Properly handle selectors and @at-root.

This commit is contained in:
Natalie Weizenbaum 2016-10-28 14:16:50 -07:00
parent 43917fe25a
commit 5c53579b4c

View File

@ -60,6 +60,13 @@ class _PerformVisitor
/// The current selector, if any. /// The current selector, if any.
CssValue<SelectorList> _selector; CssValue<SelectorList> _selector;
/// The value of [_selector] outside an `@at-root` statement that excludes
/// style rules.
///
/// This is separate from [_selector] because `&` can see it but parent
/// resolution cannot.
CssValue<SelectorList> _selectorOutsideAtRoot;
/// The current media queries, if any. /// The current media queries, if any.
List<CssMediaQuery> _mediaQueries; List<CssMediaQuery> _mediaQueries;
@ -228,6 +235,16 @@ class _PerformVisitor
_parent = oldParent; _parent = oldParent;
}; };
if (query.excludesStyleRules) {
var innerScope = scope;
scope = (callback) {
var oldSelectorOutsideAtRoot = _selectorOutsideAtRoot;
_selectorOutsideAtRoot = _selector ?? _selectorOutsideAtRoot;
_withSelector(null, () => innerScope(callback));
_selectorOutsideAtRoot = oldSelectorOutsideAtRoot;
};
}
if (query.excludesMedia) { if (query.excludesMedia) {
var innerScope = scope; var innerScope = scope;
scope = (callback) => _withMediaQueries(null, () => innerScope(callback)); scope = (callback) => _withMediaQueries(null, () => innerScope(callback));
@ -1203,8 +1220,9 @@ class _PerformVisitor
} }
Value visitSelectorExpression(SelectorExpression node) { Value visitSelectorExpression(SelectorExpression node) {
if (_selector == null) return sassNull; var selector = _selector ?? _selectorOutsideAtRoot;
return _selector.value.asSassList; if (selector == null) return sassNull;
return selector.value.asSassList;
} }
SassString visitStringExpression(StringExpression node) => SassString visitStringExpression(StringExpression node) =>