Skip to content

Commit

Permalink
Deprecate assignment to non-existent global variables (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
nex3 authored Feb 21, 2019
1 parent 149bf85 commit 8ab9ce1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## 1.17.2

* Deprecate `!global` variable assignments to variables that aren't yet defined.
This deprecation message can be avoided by assigning variables to `null` at
the top level before globally assigning values to them.

### Dart API

* Explicitly mark classes that were never intended to be subclassed or
implemented as "sealed".

Expand Down
10 changes: 10 additions & 0 deletions lib/src/visitor/async_evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1124,6 +1124,16 @@ class _EvaluateVisitor
if (value != null && value != sassNull) return null;
}

if (node.isGlobal && !_environment.globalVariableExists(node.name)) {
_logger.warn(
"As of Dart Sass 2.0.0, !global assignments won't be able to\n"
"declare new variables. Consider adding `\$${node.name}: null` at "
"the top level.",
span: node.span,
trace: _stackTrace(node.span),
deprecation: true);
}

_environment.setVariable(
node.name,
(await node.expression.accept(this)).withoutSlash(),
Expand Down
12 changes: 11 additions & 1 deletion lib/src/visitor/evaluate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// DO NOT EDIT. This file was generated from async_evaluate.dart.
// See tool/synchronize.dart for details.
//
// Checksum: 08c3aaa09f3be71dd315bf36665e249983ce3d53
// Checksum: 607d30ac9d49b341367f71b69bed09f19f93e77d
//
// ignore_for_file: unused_import

Expand Down Expand Up @@ -1119,6 +1119,16 @@ class _EvaluateVisitor
if (value != null && value != sassNull) return null;
}

if (node.isGlobal && !_environment.globalVariableExists(node.name)) {
_logger.warn(
"As of Dart Sass 2.0.0, !global assignments won't be able to\n"
"declare new variables. Consider adding `\$${node.name}: null` at "
"the top level.",
span: node.span,
trace: _stackTrace(node.span),
deprecation: true);
}

_environment.setVariable(
node.name,
node.expression.accept(this).withoutSlash(),
Expand Down

0 comments on commit 8ab9ce1

Please sign in to comment.