Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

Commit fa1e4ef

Browse files
committed
Add deprecation warning for global variable creation
1 parent 9f57ab1 commit fa1e4ef

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
std::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

@@ -341,6 +342,12 @@ namespace Sass {
341342
Env* env = environment();
342343
const std::string& var(a->variable());
343344
if (a->is_global()) {
345+
if (!env->has_global(var)) {
346+
deprecated(
347+
"!global assignments won't be able to declare new variables in future versions.",
348+
"Consider adding `" + var + ": null` at the top level.",
349+
true, a->pstate());
350+
}
344351
if (a->is_default()) {
345352
if (env->has_global(var)) {
346353
Expression_Obj e = Cast<Expression>(env->get_global(var));

0 commit comments

Comments
 (0)