Skip to content

Commit 50c40a5

Browse files
committed
[New Global] Forbid defining new variables with !global
Closes #600
1 parent d388887 commit 50c40a5

File tree

4 files changed

+9
-35
lines changed

4 files changed

+9
-35
lines changed

lib/src/deprecation.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ enum Deprecation {
1515
// DO NOT EDIT. This section was generated from the language repo.
1616
// See tool/grind/generate_deprecations.dart for details.
1717
//
18-
// Checksum: d1c9c01ca8d2b69e39b7371d774c9c86349efdef
18+
// Checksum: 0be67f32391e119205f8e98cd15fa8e7382b6dd2
1919

2020
/// Deprecation for passing a string directly to meta.call().
2121
callString('call-string',
@@ -40,6 +40,7 @@ enum Deprecation {
4040
/// Deprecation for declaring new variables with !global.
4141
newGlobal('new-global',
4242
deprecatedIn: '1.17.2',
43+
obsoleteIn: '2.0.0',
4344
description: 'Declaring new variables with !global.'),
4445

4546
/// Deprecation for using color module functions in place of plain CSS functions.

lib/src/visitor/async_evaluate.dart

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2574,21 +2574,10 @@ final class _EvaluateVisitor
25742574
}
25752575

25762576
if (node.isGlobal && !_environment.globalVariableExists(node.name)) {
2577-
_warn(
2578-
_environment.atRoot
2579-
? "As of Dart Sass 2.0.0, !global assignments won't be able to "
2580-
"declare new variables.\n"
2581-
"\n"
2582-
"Since this assignment is at the root of the stylesheet, the "
2583-
"!global flag is\n"
2584-
"unnecessary and can safely be removed."
2585-
: "As of Dart Sass 2.0.0, !global assignments won't be able to "
2586-
"declare new variables.\n"
2587-
"\n"
2588-
"Recommendation: add `${node.originalName}: null` at the "
2589-
"stylesheet root.",
2577+
throw SassRuntimeException(
2578+
'!global assignments may not declare new variables.',
25902579
node.span,
2591-
Deprecation.newGlobal,
2580+
_stackTrace(node.span),
25922581
);
25932582
}
25942583

lib/src/visitor/evaluate.dart

Lines changed: 4 additions & 15 deletions
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/grind/synchronize.dart for details.
77
//
8-
// Checksum: b6119944111590722f1b578e1d2338f7d3d9b9a2
8+
// Checksum: faf491d48ccd341abf6a301773bfce08af22b113
99
//
1010
// ignore_for_file: unused_import
1111

@@ -2579,21 +2579,10 @@ final class _EvaluateVisitor
25792579
}
25802580

25812581
if (node.isGlobal && !_environment.globalVariableExists(node.name)) {
2582-
_warn(
2583-
_environment.atRoot
2584-
? "As of Dart Sass 2.0.0, !global assignments won't be able to "
2585-
"declare new variables.\n"
2586-
"\n"
2587-
"Since this assignment is at the root of the stylesheet, the "
2588-
"!global flag is\n"
2589-
"unnecessary and can safely be removed."
2590-
: "As of Dart Sass 2.0.0, !global assignments won't be able to "
2591-
"declare new variables.\n"
2592-
"\n"
2593-
"Recommendation: add `${node.originalName}: null` at the "
2594-
"stylesheet root.",
2582+
throw SassRuntimeException(
2583+
'!global assignments may not declare new variables.',
25952584
node.span,
2596-
Deprecation.newGlobal,
2585+
_stackTrace(node.span),
25972586
);
25982587
}
25992588

test/deprecations_test.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ void main() {
1515
_expectDeprecation("a { b: call(random)}", Deprecation.callString);
1616
});
1717

18-
// Deprecated in 1.17.2
19-
test("newGlobal is violated by declaring a new variable with !global", () {
20-
_expectDeprecation(r"a {$foo: bar !global;}", Deprecation.newGlobal);
21-
});
22-
2318
// Deprecated in 1.23.0
2419
group("colorModuleCompat is violated by", () {
2520
var color = "@use 'sass:color'; a { b: color";

0 commit comments

Comments
 (0)