Skip to content

Commit

Permalink
Add deprecation warning for global variable creation (#2913)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter authored Feb 19, 2020
1 parent b50404a commit 031b2b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "expand.hpp"
#include "color_maps.hpp"
#include "sass_functions.hpp"
#include "error_handling.hpp"
#include "util_string.hpp"

namespace Sass {
Expand Down Expand Up @@ -92,6 +93,12 @@ namespace Sass {
Env* env = environment();
sass::string var(a->variable());
if (a->is_global()) {
if (!env->has_global(var)) {
deprecated(
"!global assignments won't be able to declare new variables in future versions.",
"Consider adding `" + var + ": null` at the top level.",
true, a->pstate());
}
if (a->is_default()) {
if (env->has_global(var)) {
Expression* e = Cast<Expression>(env->get_global(var));
Expand Down
7 changes: 7 additions & 0 deletions src/expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "context.hpp"
#include "parser.hpp"
#include "sass_functions.hpp"
#include "error_handling.hpp"

namespace Sass {

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

0 comments on commit 031b2b5

Please sign in to comment.