Skip to content

Commit 8ab9ce1

Browse files
authored
Deprecate assignment to non-existent global variables (#601)
See #600 See sass/sass#2606
1 parent 149bf85 commit 8ab9ce1

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## 1.17.2
22

3+
* Deprecate `!global` variable assignments to variables that aren't yet defined.
4+
This deprecation message can be avoided by assigning variables to `null` at
5+
the top level before globally assigning values to them.
6+
7+
### Dart API
8+
39
* Explicitly mark classes that were never intended to be subclassed or
410
implemented as "sealed".
511

lib/src/visitor/async_evaluate.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,16 @@ class _EvaluateVisitor
11241124
if (value != null && value != sassNull) return null;
11251125
}
11261126

1127+
if (node.isGlobal && !_environment.globalVariableExists(node.name)) {
1128+
_logger.warn(
1129+
"As of Dart Sass 2.0.0, !global assignments won't be able to\n"
1130+
"declare new variables. Consider adding `\$${node.name}: null` at "
1131+
"the top level.",
1132+
span: node.span,
1133+
trace: _stackTrace(node.span),
1134+
deprecation: true);
1135+
}
1136+
11271137
_environment.setVariable(
11281138
node.name,
11291139
(await node.expression.accept(this)).withoutSlash(),

lib/src/visitor/evaluate.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// DO NOT EDIT. This file was generated from async_evaluate.dart.
66
// See tool/synchronize.dart for details.
77
//
8-
// Checksum: 08c3aaa09f3be71dd315bf36665e249983ce3d53
8+
// Checksum: 607d30ac9d49b341367f71b69bed09f19f93e77d
99
//
1010
// ignore_for_file: unused_import
1111

@@ -1119,6 +1119,16 @@ class _EvaluateVisitor
11191119
if (value != null && value != sassNull) return null;
11201120
}
11211121

1122+
if (node.isGlobal && !_environment.globalVariableExists(node.name)) {
1123+
_logger.warn(
1124+
"As of Dart Sass 2.0.0, !global assignments won't be able to\n"
1125+
"declare new variables. Consider adding `\$${node.name}: null` at "
1126+
"the top level.",
1127+
span: node.span,
1128+
trace: _stackTrace(node.span),
1129+
deprecation: true);
1130+
}
1131+
11221132
_environment.setVariable(
11231133
node.name,
11241134
node.expression.accept(this).withoutSlash(),

0 commit comments

Comments
 (0)