make mixins behave like closures

This commit is contained in:
cloudhead 2010-07-06 16:48:05 +02:00
parent 00df4e97d0
commit 4bb4c97357
2 changed files with 4 additions and 1 deletions

View File

@ -52,6 +52,7 @@ tree.mixin.Definition = function (name, params, rules) {
else { return count }
}, 0);
this.parent = tree.Ruleset.prototype;
this.frames = [];
};
tree.mixin.Definition.prototype = {
toCSS: function () { return "" },
@ -73,7 +74,7 @@ tree.mixin.Definition.prototype = {
}
}
return new(tree.Ruleset)(null, this.rules).evalRules({
frames: [this, frame].concat(env.frames)
frames: [this, frame].concat(this.frames, env.frames)
});
},
match: function (args, env) {

View File

@ -108,6 +108,8 @@ tree.Ruleset.prototype = {
if (this.rules[i] instanceof tree.mixin.Call) {
Array.prototype.splice
.apply(this.rules, [i, 1].concat(this.rules[i].eval(env)));
} else if (this.rules[i] instanceof tree.mixin.Definition) {
this.rules[i].frames = env.frames.slice(0);
}
}