do not pollute the parent scope after mixin call if variable is defined

This commit is contained in:
Luke Page
2013-02-16 15:15:38 +00:00
parent 156911aa11
commit d01d2e9bfb
3 changed files with 11 additions and 3 deletions

View File

@@ -47,7 +47,15 @@ tree.Ruleset.prototype = {
// Evaluate mixin calls.
for (var i = 0; i < ruleset.rules.length; i++) {
if (ruleset.rules[i] instanceof tree.mixin.Call) {
rules = ruleset.rules[i].eval(env);
rules = ruleset.rules[i].eval(env).filter(function(r) {
if ((r instanceof tree.Rule) && r.variable) {
// do not pollute the scope if the variable is
// already there. consider returning false here
// but we need a way to "return" variable from mixins
return !(ruleset.variable(r.name));
}
return true;
});
ruleset.rules.splice.apply(ruleset.rules, [i, 1].concat(rules));
i += rules.length-1;
ruleset.resetCache();