mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-22 13:51:31 +01:00
Fix parent selector resolution. (#33)
If a child selector list contained one complex selector with & and one without, the latter's parent wouldn't be added automatically. Closes #28
This commit is contained in:
parent
d4f77cc674
commit
c5508cac89
@ -21,17 +21,8 @@ class SelectorList extends Selector {
|
||||
final List<ComplexSelector> components;
|
||||
|
||||
/// Whether this contains a [ParentSelector].
|
||||
bool get _containsParentSelector {
|
||||
return components.any((complex) {
|
||||
return complex.components.any((component) =>
|
||||
component is CompoundSelector &&
|
||||
component.components.any((simple) =>
|
||||
simple is ParentSelector ||
|
||||
(simple is PseudoSelector &&
|
||||
simple.selector != null &&
|
||||
simple.selector._containsParentSelector)));
|
||||
});
|
||||
}
|
||||
bool get _containsParentSelector =>
|
||||
components.any(_complexContainsParentSelector);
|
||||
|
||||
/// Returns a SassScript list that represents this selector.
|
||||
///
|
||||
@ -97,15 +88,13 @@ class SelectorList extends Selector {
|
||||
'Top-level selectors may not contain the parent selector "&".');
|
||||
}
|
||||
|
||||
if (!_containsParentSelector) {
|
||||
return new SelectorList(parent.components.expand((parentComplex) {
|
||||
return components.map((childComplex) => new ComplexSelector(
|
||||
parentComplex.components.toList()..addAll(childComplex.components),
|
||||
lineBreak: childComplex.lineBreak || parentComplex.lineBreak));
|
||||
}));
|
||||
}
|
||||
|
||||
return new SelectorList(flattenVertically(components.map((complex) {
|
||||
if (!_complexContainsParentSelector(complex)) {
|
||||
return parent.components.map((parentComplex) => new ComplexSelector(
|
||||
parentComplex.components.toList()..addAll(complex.components),
|
||||
lineBreak: complex.lineBreak || parentComplex.lineBreak));
|
||||
}
|
||||
|
||||
var newComplexes = [<ComplexSelectorComponent>[]];
|
||||
var lineBreaks = <bool>[false];
|
||||
for (var component in complex.components) {
|
||||
@ -144,6 +133,16 @@ class SelectorList extends Selector {
|
||||
})));
|
||||
}
|
||||
|
||||
/// Returns whether [complex] contains a [ParentSelector].
|
||||
bool _complexContainsParentSelector(ComplexSelector complex) =>
|
||||
complex.components.any((component) =>
|
||||
component is CompoundSelector &&
|
||||
component.components.any((simple) =>
|
||||
simple is ParentSelector ||
|
||||
(simple is PseudoSelector &&
|
||||
simple.selector != null &&
|
||||
simple.selector._containsParentSelector)));
|
||||
|
||||
/// Returns a new [CompoundSelector] based on [compound] with all
|
||||
/// [ParentSelector]s replaced with [parent].
|
||||
///
|
||||
|
Loading…
x
Reference in New Issue
Block a user