Skip to content

Commit

Permalink
Properly register pseudos' child selectors in ExtensionStore (#1374)
Browse files Browse the repository at this point in the history
Closes #1297
  • Loading branch information
nex3 committed Jun 23, 2021
1 parent 3918aef commit 713b7cc
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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
Expand Down
34 changes: 24 additions & 10 deletions lib/src/extend/extension_store.dart
Expand Up @@ -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) {
Expand All @@ -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
Expand Down

0 comments on commit 713b7cc

Please sign in to comment.