Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't separate out media queries after one has bubbled #1933

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
native CSS `filter` functions. This is in addition to number values which were
already allowed.

* Fix a cosmetic bug where an outer rule could be duplicated after nesting was
resolved, instead of re-using a shared rule.

## 1.61.0

* **Potentially breaking change:** Drop support for End-of-Life Node.js 12.
Expand Down
6 changes: 6 additions & 0 deletions lib/src/ast/css/modifiable/at_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ class ModifiableCssAtRule extends ModifiableCssParentNode implements CssAtRule {

T accept<T>(ModifiableCssVisitor<T> visitor) => visitor.visitCssAtRule(this);

bool equalsIgnoringChildren(ModifiableCssNode other) =>
other is ModifiableCssAtRule &&
name == other.name &&
value == other.value &&
isChildless == other.isChildless;

ModifiableCssAtRule copyWithoutChildren() =>
ModifiableCssAtRule(name, span, childless: isChildless, value: value);

Expand Down
5 changes: 5 additions & 0 deletions lib/src/ast/css/modifiable/keyframe_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:source_span/source_span.dart';

import '../../../utils.dart';
import '../../../visitor/interface/modifiable_css.dart';
import '../keyframe_block.dart';
import '../value.dart';
Expand All @@ -20,6 +21,10 @@ class ModifiableCssKeyframeBlock extends ModifiableCssParentNode
T accept<T>(ModifiableCssVisitor<T> visitor) =>
visitor.visitCssKeyframeBlock(this);

bool equalsIgnoringChildren(ModifiableCssNode other) =>
other is ModifiableCssKeyframeBlock &&
listEquals(selector.value, other.selector.value);

ModifiableCssKeyframeBlock copyWithoutChildren() =>
ModifiableCssKeyframeBlock(selector, span);
}
4 changes: 4 additions & 0 deletions lib/src/ast/css/modifiable/media_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:source_span/source_span.dart';

import '../../../utils.dart';
import '../../../visitor/interface/modifiable_css.dart';
import '../media_query.dart';
import '../media_rule.dart';
Expand All @@ -25,6 +26,9 @@ class ModifiableCssMediaRule extends ModifiableCssParentNode
T accept<T>(ModifiableCssVisitor<T> visitor) =>
visitor.visitCssMediaRule(this);

bool equalsIgnoringChildren(ModifiableCssNode other) =>
other is ModifiableCssMediaRule && listEquals(queries, other.queries);

ModifiableCssMediaRule copyWithoutChildren() =>
ModifiableCssMediaRule(queries, span);
}
3 changes: 3 additions & 0 deletions lib/src/ast/css/modifiable/node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ abstract class ModifiableCssParentNode extends ModifiableCssNode
: _children = children,
children = UnmodifiableListView(children);

/// Returns whether [this] is equal to [other], ignoring their child nodes.
bool equalsIgnoringChildren(ModifiableCssNode other);

/// Returns a copy of [this] with an empty [children] list.
///
/// This is *not* a deep copy. If other parts of this node are modifiable,
Expand Down
3 changes: 3 additions & 0 deletions lib/src/ast/css/modifiable/style_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class ModifiableCssStyleRule extends ModifiableCssParentNode
T accept<T>(ModifiableCssVisitor<T> visitor) =>
visitor.visitCssStyleRule(this);

bool equalsIgnoringChildren(ModifiableCssNode other) =>
other is ModifiableCssStyleRule && other.selector == selector;

ModifiableCssStyleRule copyWithoutChildren() =>
ModifiableCssStyleRule(_selector, span,
originalSelector: originalSelector);
Expand Down
3 changes: 3 additions & 0 deletions lib/src/ast/css/modifiable/stylesheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class ModifiableCssStylesheet extends ModifiableCssParentNode
T accept<T>(ModifiableCssVisitor<T> visitor) =>
visitor.visitCssStylesheet(this);

bool equalsIgnoringChildren(ModifiableCssNode other) =>
other is ModifiableCssStylesheet;

ModifiableCssStylesheet copyWithoutChildren() =>
ModifiableCssStylesheet(span);
}
3 changes: 3 additions & 0 deletions lib/src/ast/css/modifiable/supports_rule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ class ModifiableCssSupportsRule extends ModifiableCssParentNode
T accept<T>(ModifiableCssVisitor<T> visitor) =>
visitor.visitCssSupportsRule(this);

bool equalsIgnoringChildren(ModifiableCssNode other) =>
other is ModifiableCssSupportsRule && condition == other.condition;

ModifiableCssSupportsRule copyWithoutChildren() =>
ModifiableCssSupportsRule(condition, span);
}
10 changes: 8 additions & 2 deletions lib/src/visitor/async_evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3343,8 +3343,14 @@ class _EvaluateVisitor
if (parent.hasFollowingSibling) {
// A node with siblings must have a parent
var grandparent = parent.parent!;
parent = parent.copyWithoutChildren();
grandparent.addChild(parent);
if (parent.equalsIgnoringChildren(grandparent.children.last)) {
// If we've already made a copy of [parent] and nothing else has been
// added after it, re-use it.
parent = grandparent.children.last as ModifiableCssParentNode;
} else {
parent = parent.copyWithoutChildren();
grandparent.addChild(parent);
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions lib/src/visitor/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/grind/synchronize.dart for details.
//
// Checksum: 06d1dd221c149650242b3e09b3f507125606bf0f
// Checksum: c5414c9b883d650c2ff52336ce8063860da9f81b
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -3314,8 +3314,12 @@ class _EvaluateVisitor
if (parent.hasFollowingSibling) {
// A node with siblings must have a parent
var grandparent = parent.parent!;
parent = parent.copyWithoutChildren();
grandparent.addChild(parent);
if (parent.equalsIgnoringChildren(grandparent.children.last)) {
parent = grandparent.children.last as ModifiableCssParentNode;
} else {
parent = parent.copyWithoutChildren();
grandparent.addChild(parent);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sass_api/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: sass_api
# Note: Every time we add a new Sass AST node, we need to bump the *major*
# version because it's a breaking change for anyone who's implementing the
# visitor interface(s).
version: 6.3.0-dev
version: 6.3.0
description: Additional APIs for Dart Sass.
homepage: https://github.com/sass/dart-sass

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: sass
version: 1.62.0-dev
version: 1.62.0
description: A Sass implementation in Dart.
homepage: https://github.com/sass/dart-sass

Expand Down