From 8ab9ce1141c511a16349f90e86cfaca4f088c891 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Thu, 21 Feb 2019 15:16:52 -0800 Subject: [PATCH] Deprecate assignment to non-existent global variables (#601) See #600 See sass/sass#2606 --- CHANGELOG.md | 6 ++++++ lib/src/visitor/async_evaluate.dart | 10 ++++++++++ lib/src/visitor/evaluate.dart | 12 +++++++++++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03a24be99..4a89bab34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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". diff --git a/lib/src/visitor/async_evaluate.dart b/lib/src/visitor/async_evaluate.dart index eb5b40233..9fdd4d20f 100644 --- a/lib/src/visitor/async_evaluate.dart +++ b/lib/src/visitor/async_evaluate.dart @@ -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(), diff --git a/lib/src/visitor/evaluate.dart b/lib/src/visitor/evaluate.dart index 38f43a50e..c6f748088 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: 08c3aaa09f3be71dd315bf36665e249983ce3d53 +// Checksum: 607d30ac9d49b341367f71b69bed09f19f93e77d // // ignore_for_file: unused_import @@ -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(),