Fix *-exists(). (#86)

These were always using the global scope rather than the lexical scope.
They've been moved into the perform visitor so that they have access to
the lexical environment instead.
This commit is contained in:
Natalie Weizenbaum 2017-01-06 14:43:34 -08:00 committed by GitHub
parent bf464f0539
commit 63b39479e1
3 changed files with 18 additions and 15 deletions

View File

@ -1,5 +1,8 @@
## 1.0.0-alpha.7
* Fix `function-exists()`, `variable-exists()`, and `mixin-exists()` to use the
lexical scope rather than always using the global scope.
* `str-index()` now correctly inserts at negative indices.
* Properly parse `url()`s that contain comment-like text.

View File

@ -870,26 +870,11 @@ void defineCoreFunctions(Environment environment) {
return new SassBoolean(_features.contains(feature.text));
});
environment.defineFunction("variable-exists", r"$name", (arguments) {
var variable = arguments[0].assertString("name");
return new SassBoolean(environment.variableExists(variable.text));
});
environment.defineFunction("global-variable-exists", r"$name", (arguments) {
var variable = arguments[0].assertString("name");
return new SassBoolean(environment.globalVariableExists(variable.text));
});
environment.defineFunction("function-exists", r"$name", (arguments) {
var variable = arguments[0].assertString("name");
return new SassBoolean(environment.functionExists(variable.text));
});
environment.defineFunction("mixin-exists", r"$name", (arguments) {
var variable = arguments[0].assertString("name");
return new SassBoolean(environment.mixinExists(variable.text));
});
environment.defineFunction("inspect", r"$value",
(arguments) => new SassString(arguments.first.toString()));

View File

@ -128,6 +128,21 @@ class _PerformVisitor
: _loadPaths = loadPaths == null ? const [] : new List.from(loadPaths),
_environment = environment ?? new Environment(),
_color = color {
_environment.defineFunction("variable-exists", r"$name", (arguments) {
var variable = arguments[0].assertString("name");
return new SassBoolean(_environment.variableExists(variable.text));
});
_environment.defineFunction("function-exists", r"$name", (arguments) {
var variable = arguments[0].assertString("name");
return new SassBoolean(_environment.functionExists(variable.text));
});
_environment.defineFunction("mixin-exists", r"$name", (arguments) {
var variable = arguments[0].assertString("name");
return new SassBoolean(_environment.mixinExists(variable.text));
});
_environment.defineFunction("call", r"$function, $args...", (arguments) {
var function = arguments[0];
var args = arguments[1] as SassArgumentList;