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

Closes #777
This commit is contained in:
Natalie Weizenbaum 2023-04-11 15:44:19 -07:00 committed by GitHub
parent e68818a86e
commit c55235d166
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 49 additions and 7 deletions

View File

@ -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.

View File

@ -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);

View File

@ -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';
@ -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);
}

View File

@ -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';
@ -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);
}

View File

@ -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,

View File

@ -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);

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}
}
}

View File

@ -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: 17862153344c8577d780b3e039a1ce5ebb774c17
//
// ignore_for_file: unused_import
@ -3314,8 +3314,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);
}
}
}

View File

@ -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

View File

@ -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