diff --git a/lib/ast.js b/lib/ast.js index b73d2ebe..4d8b1431 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -47,21 +47,22 @@ function DEFNODE(type, props, methods, base) { if (arguments.length < 4) base = AST_Node; if (!props) props = []; else props = props.split(/\s+/); - var ctor = function (props) { - if (props) { - var ctor = this.CTOR; - do { - var self_props = ctor.SELF_PROPS; - for (var i = self_props.length; i;) { - var k = self_props[--i]; - this[k] = props[k]; - } - } while (ctor = ctor.BASE) - if (this.initialize) { - this.initialize(); - } - } - } + var code = "return function AST_" + type + "(props) {\ + if (props) {\ + var ctor = this.CTOR;\ + do {\ + var self_props = ctor.SELF_PROPS;\ + for (var i = self_props.length; i;) {\ + var k = self_props[--i];\ + this[k] = props[k];\ + }\ + } while (ctor = ctor.BASE);\ + if (this.initialize) {\ + this.initialize();\ + }\ + }\ + }"; + var ctor = new Function(code)(); var proto = base && new base; if (proto) { ctor.prototype = proto;