mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-27 12:44:42 +01:00
Clean up style rule tracking.
This commit is contained in:
parent
d69839080e
commit
6022128372
@ -19,9 +19,8 @@ class PerformVisitor extends StatementVisitor {
|
|||||||
final Environment _environment;
|
final Environment _environment;
|
||||||
final PerformExpressionVisitor _expressionVisitor;
|
final PerformExpressionVisitor _expressionVisitor;
|
||||||
|
|
||||||
/// Style rules containing the currently visited node, from outermost to
|
/// The innermost containing style rule, if one exists.
|
||||||
/// innermost.
|
CssStyleRule _styleRule;
|
||||||
var _styleRules = <CssStyleRule>[];
|
|
||||||
|
|
||||||
/// The children of the root stylesheet node.
|
/// The children of the root stylesheet node.
|
||||||
///
|
///
|
||||||
@ -120,10 +119,10 @@ class PerformVisitor extends StatementVisitor {
|
|||||||
|
|
||||||
void visitStyleRule(StyleRule node) {
|
void visitStyleRule(StyleRule node) {
|
||||||
var selectorText = _performInterpolation(node.selector, trim: true);
|
var selectorText = _performInterpolation(node.selector, trim: true);
|
||||||
if (_styleRules.isNotEmpty) {
|
if (_styleRule != null) {
|
||||||
// TODO: semantically resolve parent references.
|
// TODO: semantically resolve parent references.
|
||||||
selectorText = new CssValue(
|
selectorText = new CssValue(
|
||||||
"${_styleRules.last.selector.value} ${selectorText.value}",
|
"${_styleRule.selector.value} ${selectorText.value}",
|
||||||
span: node.selector.span);
|
span: node.selector.span);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,9 +136,9 @@ class PerformVisitor extends StatementVisitor {
|
|||||||
// rule before any of its children.
|
// rule before any of its children.
|
||||||
var insertionPoint = _outerChildren.isEmpty ? null : _outerChildren.last;
|
var insertionPoint = _outerChildren.isEmpty ? null : _outerChildren.last;
|
||||||
|
|
||||||
_styleRules.add(new CssStyleRule(selector, [], span: node.span));
|
var children = _withStyleRule(
|
||||||
var children = _collectChildren(() => super.visitStyleRule(node));
|
new CssStyleRule(selector, [], span: node.span),
|
||||||
_styleRules.removeLast();
|
() => _collectChildren(() => super.visitStyleRule(node)));
|
||||||
if (children.isEmpty) return;
|
if (children.isEmpty) return;
|
||||||
|
|
||||||
var rule = new CssStyleRule(selector, children, span: node.span);
|
var rule = new CssStyleRule(selector, children, span: node.span);
|
||||||
@ -171,17 +170,17 @@ class PerformVisitor extends StatementVisitor {
|
|||||||
list.add(new LinkedListValue(node));
|
list.add(new LinkedListValue(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*=T*/ _resetStyleRules/*<T>*/(/*=T*/ callback()) {
|
/*=T*/ _withStyleRule/*<T>*/(CssStyleRule rule, /*=T*/ callback()) {
|
||||||
var oldStyleRules = _styleRules;
|
var oldStyleRule = _styleRule;
|
||||||
_styleRules = [];
|
_styleRule = rule;
|
||||||
var result = callback();
|
var result = callback();
|
||||||
_styleRules = oldStyleRules;
|
_styleRule = oldStyleRule;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Like [_collectChildren], but handles bubbling.
|
/// Like [_collectChildren], but handles bubbling.
|
||||||
Iterable<CssNode> _atRuleChildren(void callback()) {
|
Iterable<CssNode> _atRuleChildren(void callback()) {
|
||||||
if (_styleRules.isEmpty) return _collectChildren(callback);
|
if (_styleRule == null) return _collectChildren(callback);
|
||||||
|
|
||||||
return _scope(() {
|
return _scope(() {
|
||||||
_outerChildren = new LinkedList();
|
_outerChildren = new LinkedList();
|
||||||
@ -191,9 +190,9 @@ class PerformVisitor extends StatementVisitor {
|
|||||||
|
|
||||||
if (_innerChildren.isNotEmpty) {
|
if (_innerChildren.isNotEmpty) {
|
||||||
_outerChildren.addFirst(new LinkedListValue(new CssStyleRule(
|
_outerChildren.addFirst(new LinkedListValue(new CssStyleRule(
|
||||||
_styleRules.last.selector,
|
_styleRule.selector,
|
||||||
_innerChildren.map((node) => node.value),
|
_innerChildren.map((node) => node.value),
|
||||||
span: _styleRules.last.span)));
|
span: _styleRule.span)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return _outerChildren.map((node) => node.value);
|
return _outerChildren.map((node) => node.value);
|
||||||
|
Loading…
Reference in New Issue
Block a user