From 027392ac3069d821dd8c2119482fa4499a95f24e Mon Sep 17 00:00:00 2001 From: Jen Thakar Date: Sat, 26 May 2018 22:30:34 -0700 Subject: [PATCH] Add variables argument to _EvaluateVisitor --- lib/src/visitor/async_evaluate.dart | 34 ++++++++++++++++----------- lib/src/visitor/evaluate.dart | 36 ++++++++++++++++++----------- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/lib/src/visitor/async_evaluate.dart b/lib/src/visitor/async_evaluate.dart index 1d4533fe..1ee32ab4 100644 --- a/lib/src/visitor/async_evaluate.dart +++ b/lib/src/visitor/async_evaluate.dart @@ -44,6 +44,9 @@ typedef Future _ScopeCallback(Future callback()); /// The [functions] are available as global functions when evaluating /// [stylesheet]. /// +/// The [variables] are available as global variables when evaluating +/// [stylesheet]. +/// /// Warnings are emitted using [logger], or printed to standard error by /// default. /// @@ -56,6 +59,7 @@ Future evaluateAsync(Stylesheet stylesheet, NodeImporter nodeImporter, AsyncImporter importer, Iterable functions, + Map variables, Logger logger, bool sourceMap: false}) => new _EvaluateVisitor( @@ -63,33 +67,32 @@ Future evaluateAsync(Stylesheet stylesheet, nodeImporter: nodeImporter, importer: importer, functions: functions, + variables: variables, logger: logger, sourceMap: sourceMap) .run(stylesheet); /// Evaluates a single [expression] /// -/// The [variables] are available when evaluating [expression] -/// /// The [functions] are available as global functions when evaluating /// [expression]. /// +/// The [variables] are available as global variables when evaluating +/// [expression]. +/// /// Warnings are emitted using [logger], or printed to standard error by /// default. /// /// Throws a [SassRuntimeException] if evaluation fails. Future evaluateExpressionAsync(Expression expression, - {Map variables, - Iterable functions, - Logger logger}) { - var evaluator = new _EvaluateVisitor( - functions: functions, logger: logger, sourceMap: false); - for (var name in variables.keys) { - evaluator._environment - .setVariable(name, variables[name], null, global: true); - } - return expression.accept(evaluator); -} + {Iterable functions, + Map variables, + Logger logger}) => + expression.accept(new _EvaluateVisitor( + functions: functions, + variables: variables, + logger: logger, + sourceMap: false)); /// A visitor that executes Sass code to produce a CSS tree. class _EvaluateVisitor @@ -194,6 +197,7 @@ class _EvaluateVisitor NodeImporter nodeImporter, AsyncImporter importer, Iterable functions, + Map variables, Logger logger, bool sourceMap}) : _importCache = importCache ?? AsyncImportCache.none, @@ -289,6 +293,10 @@ class _EvaluateVisitor for (var function in functions ?? const []) { _environment.setFunction(function); } + + for (var name in variables?.keys ?? const []) { + _environment.setVariable(name, variables[name], null, global: true); + } } Future run(Stylesheet node) async { diff --git a/lib/src/visitor/evaluate.dart b/lib/src/visitor/evaluate.dart index 533ccfd2..adb1b78e 100644 --- a/lib/src/visitor/evaluate.dart +++ b/lib/src/visitor/evaluate.dart @@ -5,7 +5,7 @@ // DO NOT EDIT. This file was generated from async_evaluate.dart. // See tool/synchronize.dart for details. // -// Checksum: c24a81d7e627d58976112aa89f95377a30b20afa +// Checksum: ff6c50c58c86529e7fed4247a7381649cec1900c import 'async_evaluate.dart' show EvaluateResult; export 'async_evaluate.dart' show EvaluateResult; @@ -51,6 +51,9 @@ typedef void _ScopeCallback(void callback()); /// The [functions] are available as global functions when evaluating /// [stylesheet]. /// +/// The [variables] are available as global variables when evaluating +/// [stylesheet]. +/// /// Warnings are emitted using [logger], or printed to standard error by /// default. /// @@ -63,6 +66,7 @@ EvaluateResult evaluate(Stylesheet stylesheet, NodeImporter nodeImporter, Importer importer, Iterable functions, + Map variables, Logger logger, bool sourceMap: false}) => new _EvaluateVisitor( @@ -70,33 +74,32 @@ EvaluateResult evaluate(Stylesheet stylesheet, nodeImporter: nodeImporter, importer: importer, functions: functions, + variables: variables, logger: logger, sourceMap: sourceMap) .run(stylesheet); /// Evaluates a single [expression] /// -/// The [variables] are available when evaluating [expression] -/// /// The [functions] are available as global functions when evaluating /// [expression]. /// +/// The [variables] are available as global variables when evaluating +/// [expression]. +/// /// Warnings are emitted using [logger], or printed to standard error by /// default. /// /// Throws a [SassRuntimeException] if evaluation fails. Value evaluateExpression(Expression expression, - {Map variables, - Iterable functions, - Logger logger}) { - var evaluator = new _EvaluateVisitor( - functions: functions, logger: logger, sourceMap: false); - for (var name in variables.keys) { - evaluator._environment - .setVariable(name, variables[name], null, global: true); - } - return expression.accept(evaluator); -} + {Iterable functions, + Map variables, + Logger logger}) => + expression.accept(new _EvaluateVisitor( + functions: functions, + variables: variables, + logger: logger, + sourceMap: false)); /// A visitor that executes Sass code to produce a CSS tree. class _EvaluateVisitor @@ -199,6 +202,7 @@ class _EvaluateVisitor NodeImporter nodeImporter, Importer importer, Iterable functions, + Map variables, Logger logger, bool sourceMap}) : _importCache = importCache ?? ImportCache.none, @@ -294,6 +298,10 @@ class _EvaluateVisitor for (var function in functions ?? const []) { _environment.setFunction(function); } + + for (var name in variables?.keys ?? const []) { + _environment.setVariable(name, variables[name], null, global: true); + } } EvaluateResult run(Stylesheet node) {