Skip to content

Commit 031b2b5

Browse files
authored
Add deprecation warning for global variable creation (#2913)
1 parent b50404a commit 031b2b5

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/eval.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "expand.hpp"
3131
#include "color_maps.hpp"
3232
#include "sass_functions.hpp"
33+
#include "error_handling.hpp"
3334
#include "util_string.hpp"
3435

3536
namespace Sass {
@@ -92,6 +93,12 @@ namespace Sass {
9293
Env* env = environment();
9394
sass::string var(a->variable());
9495
if (a->is_global()) {
96+
if (!env->has_global(var)) {
97+
deprecated(
98+
"!global assignments won't be able to declare new variables in future versions.",
99+
"Consider adding `" + var + ": null` at the top level.",
100+
true, a->pstate());
101+
}
95102
if (a->is_default()) {
96103
if (env->has_global(var)) {
97104
Expression* e = Cast<Expression>(env->get_global(var));

src/expand.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "context.hpp"
1414
#include "parser.hpp"
1515
#include "sass_functions.hpp"
16+
#include "error_handling.hpp"
1617

1718
namespace Sass {
1819

@@ -358,6 +359,12 @@ namespace Sass {
358359
Env* env = environment();
359360
const sass::string& var(a->variable());
360361
if (a->is_global()) {
362+
if (!env->has_global(var)) {
363+
deprecated(
364+
"!global assignments won't be able to declare new variables in future versions.",
365+
"Consider adding `" + var + ": null` at the top level.",
366+
true, a->pstate());
367+
}
361368
if (a->is_default()) {
362369
if (env->has_global(var)) {
363370
ExpressionObj e = Cast<Expression>(env->get_global(var));

0 commit comments

Comments
 (0)