@@ -646,24 +646,28 @@ bool complexIsSuperselector(List<ComplexSelectorComponent> complex1,
646
646
var component1 = complex1[i1];
647
647
if (component1.combinators.length > 1 ) return false ;
648
648
if (remaining1 == 1 ) {
649
- var parents = complex2.sublist (i2, complex2.length - 1 );
650
- if (parents.any ((parent) => parent.combinators.length > 1 )) return false ;
651
-
652
- return compoundIsSuperselector (
653
- component1.selector, complex2.last.selector,
654
- parents: parents);
649
+ if (complex2.any ((parent) => parent.combinators.length > 1 )) {
650
+ return false ;
651
+ } else {
652
+ return compoundIsSuperselector (
653
+ component1.selector, complex2.last.selector,
654
+ parents: component1.selector.hasComplicatedSuperselectorSemantics
655
+ ? complex2.sublist (i2, complex2.length - 1 )
656
+ : null );
657
+ }
655
658
}
656
659
657
660
// Find the first index [endOfSubselector] in [complex2] such that
658
661
// `complex2.sublist(i2, endOfSubselector + 1)` is a subselector of
659
662
// [component1.selector].
660
663
var endOfSubselector = i2;
661
- List <ComplexSelectorComponent >? parents;
662
664
while (true ) {
663
665
var component2 = complex2[endOfSubselector];
664
666
if (component2.combinators.length > 1 ) return false ;
665
667
if (compoundIsSuperselector (component1.selector, component2.selector,
666
- parents: parents)) {
668
+ parents: component1.selector.hasComplicatedSuperselectorSemantics
669
+ ? complex2.sublist (i2, endOfSubselector)
670
+ : null )) {
667
671
break ;
668
672
}
669
673
@@ -675,13 +679,10 @@ bool complexIsSuperselector(List<ComplexSelectorComponent> complex1,
675
679
// to match.
676
680
return false ;
677
681
}
678
-
679
- parents ?? = [];
680
- parents.add (component2);
681
682
}
682
683
683
684
if (! _compatibleWithPreviousCombinator (
684
- previousCombinator, parents ?? const [] )) {
685
+ previousCombinator, complex2. take (endOfSubselector). skip (i2) )) {
685
686
return false ;
686
687
}
687
688
@@ -717,8 +718,8 @@ bool complexIsSuperselector(List<ComplexSelectorComponent> complex1,
717
718
/// Returns whether [parents] are valid intersitial components between one
718
719
/// complex superselector and another, given that the earlier complex
719
720
/// superselector had the combinator [previous] .
720
- bool _compatibleWithPreviousCombinator (
721
- CssValue < Combinator > ? previous, List <ComplexSelectorComponent > parents) {
721
+ bool _compatibleWithPreviousCombinator (CssValue < Combinator > ? previous,
722
+ Iterable <ComplexSelectorComponent > parents) {
722
723
if (parents.isEmpty) return true ;
723
724
if (previous == null ) return true ;
724
725
@@ -754,6 +755,13 @@ bool _isSupercombinator(
754
755
bool compoundIsSuperselector (
755
756
CompoundSelector compound1, CompoundSelector compound2,
756
757
{Iterable <ComplexSelectorComponent >? parents}) {
758
+ if (! compound1.hasComplicatedSuperselectorSemantics &&
759
+ ! compound2.hasComplicatedSuperselectorSemantics) {
760
+ if (compound1.components.length > compound2.components.length) return false ;
761
+ return compound1.components
762
+ .every ((simple1) => compound2.components.any (simple1.isSuperselector));
763
+ }
764
+
757
765
// Pseudo elements effectively change the target of a compound selector rather
758
766
// than narrowing the set of elements to which it applies like other
759
767
// selectors. As such, if either selector has a pseudo element, they both must
0 commit comments