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