@@ -646,24 +646,28 @@ bool complexIsSuperselector(List<ComplexSelectorComponent> complex1,
646646 var component1 = complex1[i1];
647647 if (component1.combinators.length > 1 ) return false ;
648648 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+ }
655658 }
656659
657660 // Find the first index [endOfSubselector] in [complex2] such that
658661 // `complex2.sublist(i2, endOfSubselector + 1)` is a subselector of
659662 // [component1.selector].
660663 var endOfSubselector = i2;
661- List <ComplexSelectorComponent >? parents;
662664 while (true ) {
663665 var component2 = complex2[endOfSubselector];
664666 if (component2.combinators.length > 1 ) return false ;
665667 if (compoundIsSuperselector (component1.selector, component2.selector,
666- parents: parents)) {
668+ parents: component1.selector.hasComplicatedSuperselectorSemantics
669+ ? complex2.sublist (i2, endOfSubselector)
670+ : null )) {
667671 break ;
668672 }
669673
@@ -675,13 +679,10 @@ bool complexIsSuperselector(List<ComplexSelectorComponent> complex1,
675679 // to match.
676680 return false ;
677681 }
678-
679- parents ?? = [];
680- parents.add (component2);
681682 }
682683
683684 if (! _compatibleWithPreviousCombinator (
684- previousCombinator, parents ?? const [] )) {
685+ previousCombinator, complex2. take (endOfSubselector). skip (i2) )) {
685686 return false ;
686687 }
687688
@@ -717,8 +718,8 @@ bool complexIsSuperselector(List<ComplexSelectorComponent> complex1,
717718/// Returns whether [parents] are valid intersitial components between one
718719/// complex superselector and another, given that the earlier complex
719720/// 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) {
722723 if (parents.isEmpty) return true ;
723724 if (previous == null ) return true ;
724725
@@ -754,6 +755,13 @@ bool _isSupercombinator(
754755bool compoundIsSuperselector (
755756 CompoundSelector compound1, CompoundSelector compound2,
756757 {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+
757765 // Pseudo elements effectively change the target of a compound selector rather
758766 // than narrowing the set of elements to which it applies like other
759767 // selectors. As such, if either selector has a pseudo element, they both must
0 commit comments