mirror of
https://github.com/danog/dart-sass.git
synced 2024-11-27 04:34:59 +01:00
Support @while
This commit is contained in:
parent
80f0afb484
commit
e873242ac4
@ -44,6 +44,7 @@ export 'sass/statement/stylesheet.dart';
|
||||
export 'sass/statement/supports_rule.dart';
|
||||
export 'sass/statement/variable_declaration.dart';
|
||||
export 'sass/statement/warn_rule.dart';
|
||||
export 'sass/statement/while_rule.dart';
|
||||
export 'sass/supports_condition.dart';
|
||||
export 'sass/supports_condition/declaration.dart';
|
||||
export 'sass/supports_condition/interpolation.dart';
|
||||
|
25
lib/src/ast/sass/statement/while_rule.dart
Normal file
25
lib/src/ast/sass/statement/while_rule.dart
Normal file
@ -0,0 +1,25 @@
|
||||
// Copyright 2016 Google Inc. Use of this source code is governed by an
|
||||
// MIT-style license that can be found in the LICENSE file or at
|
||||
// https://opensource.org/licenses/MIT.
|
||||
|
||||
import 'package:source_span/source_span.dart';
|
||||
|
||||
import '../../../visitor/interface/statement.dart';
|
||||
import '../expression.dart';
|
||||
import '../statement.dart';
|
||||
|
||||
class WhileRule implements Statement {
|
||||
final Expression condition;
|
||||
|
||||
final List<Statement> children;
|
||||
|
||||
final FileSpan span;
|
||||
|
||||
WhileRule(this.condition, Iterable<Statement> children, this.span)
|
||||
: children = new List.unmodifiable(children);
|
||||
|
||||
/*=T*/ accept/*<T>*/(StatementVisitor/*<T>*/ visitor) =>
|
||||
visitor.visitWhileRule(this);
|
||||
|
||||
String toString() => "@while $condition {${children.join(" ")}}";
|
||||
}
|
@ -351,6 +351,8 @@ class Parser {
|
||||
return _supportsRule(start);
|
||||
case "warn":
|
||||
return _warnRule(start);
|
||||
case "while":
|
||||
return _whileRule(start, child);
|
||||
default:
|
||||
return _unknownAtRule(start, name);
|
||||
}
|
||||
@ -375,6 +377,8 @@ class Parser {
|
||||
return _includeRule(start);
|
||||
case "warn":
|
||||
return _warnRule(start);
|
||||
case "while":
|
||||
return _whileRule(start, _declarationChild);
|
||||
default:
|
||||
return _disallowedAtRule(start);
|
||||
}
|
||||
@ -395,6 +399,8 @@ class Parser {
|
||||
return _returnRule(start);
|
||||
case "warn":
|
||||
return _warnRule(start);
|
||||
case "while":
|
||||
return _whileRule(start, _functionAtRule);
|
||||
default:
|
||||
return _disallowedAtRule(start);
|
||||
}
|
||||
@ -580,6 +586,15 @@ class Parser {
|
||||
WarnRule _warnRule(LineScannerState start) =>
|
||||
new WarnRule(_expression(), _scanner.spanFrom(start));
|
||||
|
||||
WhileRule _whileRule(LineScannerState start, Statement child()) {
|
||||
var wasInControlDirective = _inControlDirective;
|
||||
_inControlDirective = true;
|
||||
var expression = _expression();
|
||||
var children = _children(child);
|
||||
_inControlDirective = wasInControlDirective;
|
||||
return new WhileRule(expression, children, _scanner.spanFrom(start));
|
||||
}
|
||||
|
||||
AtRule _unknownAtRule(LineScannerState start, String name) {
|
||||
Interpolation value;
|
||||
var next = _scanner.peekChar();
|
||||
|
@ -27,4 +27,5 @@ abstract class StatementVisitor<T> {
|
||||
T visitSupportsRule(SupportsRule node);
|
||||
T visitVariableDeclaration(VariableDeclaration node);
|
||||
T visitWarnRule(WarnRule node);
|
||||
T visitWhileRule(WhileRule node);
|
||||
}
|
||||
|
@ -532,6 +532,16 @@ class PerformVisitor implements StatementVisitor, ExpressionVisitor<Value> {
|
||||
}
|
||||
}
|
||||
|
||||
void visitWhileRule(WhileRule node) {
|
||||
_environment.scope(() {
|
||||
while (node.condition.accept(this).isTruthy) {
|
||||
for (var child in node.children) {
|
||||
child.accept(this);
|
||||
}
|
||||
}
|
||||
}, semiGlobal: true);
|
||||
}
|
||||
|
||||
// ## Expressions
|
||||
|
||||
Value visitVariableExpression(VariableExpression node) {
|
||||
|
Loading…
Reference in New Issue
Block a user