Properly register pseudos' child selectors in ExtensionStore (#1374)

Closes #1297
This commit is contained in:
Natalie Weizenbaum 2021-06-23 16:43:08 -07:00 committed by GitHub
parent 3918aefdfd
commit 713b7cc31e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 10 deletions

View File

@ -13,6 +13,9 @@
URLs (those that begin with `/`) in `@import` rules would be passed to
both Dart and JS importers as `file:` URLs.
* Fix an edge case where `@extend` wouldn't affect a selector within a
pseudo-selector such as `:is()` that itself extended other selectors.
## 1.35.1
* Fix a bug where the quiet dependency flag didn't silence warnings in some

View File

@ -258,16 +258,12 @@ class ExtensionStore {
sources[complex] = extension;
for (var component in complex.components) {
if (component is CompoundSelector) {
for (var simple in component.components) {
_extensionsByExtender.putIfAbsent(simple, () => []).add(extension);
// Only source specificity for the original selector is relevant.
// Selectors generated by `@extend` don't get new specificity.
_sourceSpecificity.putIfAbsent(
simple, () => complex.maxSpecificity);
}
}
for (var simple in _simpleSelectors(complex)) {
_extensionsByExtender.putIfAbsent(simple, () => []).add(extension);
// Only source specificity for the original selector is relevant.
// Selectors generated by `@extend` don't get new specificity.
_sourceSpecificity.putIfAbsent(
simple, () => complex.maxSpecificity);
}
if (selectors != null || existingExtensions != null) {
@ -292,6 +288,24 @@ class ExtensionStore {
}
}
/// Returns an iterable of all simple selectors in [complex]
Iterable<SimpleSelector> _simpleSelectors(ComplexSelector complex) sync* {
for (var component in complex.components) {
if (component is CompoundSelector) {
for (var simple in component.components) {
yield simple;
if (simple is! PseudoSelector) continue;
var selector = simple.selector;
if (selector == null) continue;
for (var complex in selector.components) {
yield* _simpleSelectors(complex);
}
}
}
}
}
/// Extend [extensions] using [newExtensions].
///
/// Note that this does duplicate some work done by