self referencing variable gives a proper error (no stack overflow). Fixes #972

This commit is contained in:
Luke Page
2012-10-29 20:22:05 +00:00
parent 0601933239
commit 6ec856097c
3 changed files with 16 additions and 1 deletions

View File

@@ -8,12 +8,24 @@ tree.Variable.prototype = {
if (name.indexOf('@@') == 0) {
name = '@' + new(tree.Variable)(name.slice(1)).eval(env).value;
}
if (this.evaluating) {
throw { type: 'Name',
message: "Recursive variable definition for " + name,
filename: this.file,
index: this.index };
}
this.evaluating = true;
if (variable = tree.find(env.frames, function (frame) {
if (v = frame.variable(name)) {
return v.value.eval(env);
}
})) { return variable }
})) {
this.evaluating = false;
return variable;
}
else {
throw { type: 'Name',
message: "variable " + name + " is undefined",

View File

@@ -0,0 +1 @@
@bodyColor: darken(@bodyColor, 30%);

View File

@@ -0,0 +1,2 @@
NameError: Recursive variable definition for @bodyColor in {path}recursive-variable.less:1:19
1 @bodyColor: darken(@bodyColor, 30%);