@@ -57,9 +57,10 @@ final class SelectorList extends Selector {
5757
5858 /// Parses a selector list from [contents] .
5959 ///
60- /// If passed, [url] is the name of the file from which [contents] comes.
61- /// [allowParent] and [allowPlaceholder] control whether [ParentSelector] s or
62- /// [PlaceholderSelector] s are allowed in this selector, respectively.
60+ /// If passed, [url] is the name of the file from which [contents] comes. If
61+ /// [allowParent] is false, this doesn't allow [ParentSelector] s. If
62+ /// [plainCss] is true, this parses the selector as plain CSS rather than
63+ /// unresolved Sass.
6364 ///
6465 /// If passed, [interpolationMap] maps the text of [contents] back to the
6566 /// original location of the selector in the source file.
@@ -70,13 +71,13 @@ final class SelectorList extends Selector {
7071 Logger ? logger,
7172 InterpolationMap ? interpolationMap,
7273 bool allowParent = true ,
73- bool allowPlaceholder = true }) =>
74+ bool plainCss = false }) =>
7475 SelectorParser (contents,
7576 url: url,
7677 logger: logger,
7778 interpolationMap: interpolationMap,
7879 allowParent: allowParent,
79- allowPlaceholder : allowPlaceholder )
80+ plainCss : plainCss )
8081 .parse ();
8182
8283 T accept <T >(SelectorVisitor <T > visitor) => visitor.visitSelectorList (this );
@@ -95,17 +96,24 @@ final class SelectorList extends Selector {
9596 return contents.isEmpty ? null : SelectorList (contents, span);
9697 }
9798
98- /// Returns a new list with all [ParentSelector] s replaced with [parent] .
99+ /// Returns a new selector list that represents [this] nested within [parent] .
99100 ///
100- /// If [implicitParent] is true, this treats [ComplexSelector] s that don't
101- /// contain an explicit [ParentSelector] as though they began with one.
101+ /// By default, this replaces [ParentSelector] s in [this] with [parent] . If
102+ /// [preserveParentSelectors] is true, this instead preserves those selectors
103+ /// as parent selectors.
104+ ///
105+ /// If [implicitParent] is true, this prepends [parent] to any
106+ /// [ComplexSelector] s in this that don't contain explicit [ParentSelector] s,
107+ /// or to _all_ [ComplexSelector] s if [preserveParentSelectors] is true.
102108 ///
103109 /// The given [parent] may be `null` , indicating that this has no parents. If
104110 /// so, this list is returned as-is if it doesn't contain any explicit
105- /// [ParentSelector] s. If it does, this throws a [SassScriptException] .
106- SelectorList resolveParentSelectors (SelectorList ? parent,
107- {bool implicitParent = true }) {
111+ /// [ParentSelector] s or if [preserveParentSelectors] is true. Otherwise, this
112+ /// throws a [SassScriptException] .
113+ SelectorList nestWithin (SelectorList ? parent,
114+ {bool implicitParent = true , bool preserveParentSelectors = false }) {
108115 if (parent == null ) {
116+ if (preserveParentSelectors) return this ;
109117 var parentSelector = accept (const _ParentSelectorVisitor ());
110118 if (parentSelector == null ) return this ;
111119 throw SassException (
@@ -114,15 +122,15 @@ final class SelectorList extends Selector {
114122 }
115123
116124 return SelectorList (flattenVertically (components.map ((complex) {
117- if (! _containsParentSelector (complex)) {
125+ if (preserveParentSelectors || ! _containsParentSelector (complex)) {
118126 if (! implicitParent) return [complex];
119127 return parent.components.map ((parentComplex) =>
120128 parentComplex.concatenate (complex, complex.span));
121129 }
122130
123131 var newComplexes = < ComplexSelector > [];
124132 for (var component in complex.components) {
125- var resolved = _resolveParentSelectorsCompound (component, parent);
133+ var resolved = _nestWithinCompound (component, parent);
126134 if (resolved == null ) {
127135 if (newComplexes.isEmpty) {
128136 newComplexes.add (ComplexSelector (
@@ -165,7 +173,7 @@ final class SelectorList extends Selector {
165173 /// [ParentSelector] s replaced with [parent] .
166174 ///
167175 /// Returns `null` if [component] doesn't contain any [ParentSelector] s.
168- Iterable <ComplexSelector >? _resolveParentSelectorsCompound (
176+ Iterable <ComplexSelector >? _nestWithinCompound (
169177 ComplexSelectorComponent component, SelectorList parent) {
170178 var simples = component.selector.components;
171179 var containsSelectorPseudo = simples.any ((simple) {
@@ -181,8 +189,8 @@ final class SelectorList extends Selector {
181189 ? simples.map ((simple) => switch (simple) {
182190 PseudoSelector (: var selector? )
183191 when _containsParentSelector (selector) =>
184- simple.withSelector (selector. resolveParentSelectors (parent,
185- implicitParent: false )),
192+ simple.withSelector (
193+ selector. nestWithin (parent, implicitParent: false )),
186194 _ => simple
187195 })
188196 : simples;
@@ -261,6 +269,8 @@ final class SelectorList extends Selector {
261269
262270 /// Returns a copy of `this` with [combinators] added to the end of each
263271 /// complex selector in [components] .
272+ ///
273+ /// @nodoc
264274 @internal
265275 SelectorList withAdditionalCombinators (
266276 List <CssValue <Combinator >> combinators) =>
0 commit comments