mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-22 05:41:14 +01:00
Boolean literals.
This commit is contained in:
parent
81cff201e0
commit
97e53ce1ff
@ -5,6 +5,7 @@
|
||||
import '../../visitor/expression.dart';
|
||||
import 'node.dart';
|
||||
|
||||
export 'expression/boolean.dart';
|
||||
export 'expression/identifier.dart';
|
||||
export 'expression/interpolation.dart';
|
||||
export 'expression/list.dart';
|
||||
|
21
lib/src/ast/sass/expression/boolean.dart
Normal file
21
lib/src/ast/sass/expression/boolean.dart
Normal file
@ -0,0 +1,21 @@
|
||||
// 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/expression.dart';
|
||||
import '../expression.dart';
|
||||
|
||||
class BooleanExpression implements Expression {
|
||||
final bool value;
|
||||
|
||||
final SourceSpan span;
|
||||
|
||||
BooleanExpression(this.value, {this.span});
|
||||
|
||||
/*=T*/ visit/*<T>*/(ExpressionVisitor/*<T>*/ visitor) =>
|
||||
visitor.visitBooleanExpression(this);
|
||||
|
||||
String toString() => value.toString();
|
||||
}
|
@ -394,12 +394,17 @@ class Parser {
|
||||
Expression _identifierLike() {
|
||||
// TODO: url(), functions
|
||||
var identifier = _interpolatedIdentifier();
|
||||
if (identifier.asPlain == "not") {
|
||||
_ignoreComments();
|
||||
return new UnaryOperatorExpression(
|
||||
UnaryOperator.not, _singleExpression());
|
||||
} else {
|
||||
return new IdentifierExpression(identifier);
|
||||
switch (identifier.asPlain) {
|
||||
case "not":
|
||||
_ignoreComments();
|
||||
return new UnaryOperatorExpression(
|
||||
UnaryOperator.not, _singleExpression(), span: identifier.span);
|
||||
|
||||
case "true": return new BooleanExpression(true, span: identifier.span);
|
||||
case "false": return new BooleanExpression(false, span: identifier.span);
|
||||
|
||||
default:
|
||||
return new IdentifierExpression(identifier);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ class ExpressionVisitor<T> {
|
||||
T visit(Expression expression) => expression.visit(this);
|
||||
|
||||
T visitVariableExpression(VariableExpression node) => null;
|
||||
T visitBooleanExpression(BooleanExpression node) => null;
|
||||
|
||||
T visitUnaryOperatorExpression(UnaryOperatorExpression node) {
|
||||
node.operand.visit(this);
|
||||
@ -19,13 +20,6 @@ class ExpressionVisitor<T> {
|
||||
return null;
|
||||
}
|
||||
|
||||
T visitInterpolationExpression(InterpolationExpression node) {
|
||||
for (var value in node.contents) {
|
||||
if (value is Expression) value.visit(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
T visitListExpression(ListExpression node) {
|
||||
for (var expression in node.contents) {
|
||||
expression.visit(this);
|
||||
@ -37,4 +31,11 @@ class ExpressionVisitor<T> {
|
||||
visitInterpolationExpression(node.text);
|
||||
return null;
|
||||
}
|
||||
|
||||
T visitInterpolationExpression(InterpolationExpression node) {
|
||||
for (var value in node.contents) {
|
||||
if (value is Expression) value.visit(this);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -36,6 +36,9 @@ class PerformExpressionVisitor extends ExpressionVisitor<Value> {
|
||||
Identifier visitIdentifierExpression(IdentifierExpression node) =>
|
||||
new Identifier(visitInterpolationExpression(node.text).text);
|
||||
|
||||
Boolean visitBooleanExpression(BooleanExpression node) =>
|
||||
new Boolean(node.value);
|
||||
|
||||
SassString visitInterpolationExpression(InterpolationExpression node) {
|
||||
return new SassString(node.contents.map((value) {
|
||||
if (value is String) return value;
|
||||
|
Loading…
x
Reference in New Issue
Block a user