Refactor Extender._extendOrReplace() (#965)

This combines all targets into a single extender invocation, which is
more efficient and allows it to more aggressively do redundant
selector elimination.
This commit is contained in:
Natalie Weizenbaum 2020-02-28 15:48:36 -08:00 committed by GitHub
parent f81f57dbaa
commit cb8a048e58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 16 deletions

View File

@ -1,3 +1,8 @@
## 1.26.2
* More aggressively eliminate redundant selectors in the `selector.extend()` and
`selector.replace()` functions.
## 1.26.1
### Command Line Interface

View File

@ -90,25 +90,28 @@ class Extender {
/// A helper function for [extend] and [replace].
static SelectorList _extendOrReplace(SelectorList selector,
SelectorList source, SelectorList targets, ExtendMode mode) {
var extenders = Map<ComplexSelector, Extension>.fromIterable(
source.components,
value: (complex) => Extension.oneOff(complex as ComplexSelector));
for (var complex in targets.components) {
if (complex.components.length != 1) {
throw SassScriptException("Can't extend complex selector $complex.");
}
var extenders = {
for (var complex in source.components) complex: Extension.oneOff(complex)
};
var compound = complex.components.first as CompoundSelector;
var extensions = {
var compoundTargets = [
for (var complex in targets.components)
if (complex.components.length != 1)
throw SassScriptException("Can't extend complex selector $complex.")
else
complex.components.first as CompoundSelector
];
var extensions = {
for (var compound in compoundTargets)
for (var simple in compound.components) simple: extenders
};
};
var extender = Extender._mode(mode);
if (!selector.isInvisible) {
extender._originals.addAll(selector.components);
}
selector = extender._extendList(selector, extensions, null);
var extender = Extender._mode(mode);
if (!selector.isInvisible) {
extender._originals.addAll(selector.components);
}
selector = extender._extendList(selector, extensions, null);
return selector;
}

View File

@ -1,5 +1,5 @@
name: sass
version: 1.26.1
version: 1.26.2
description: A Sass implementation in Dart.
author: Sass Team
homepage: https://github.com/sass/dart-sass