This commit is contained in:
yimi 2017-09-18 09:48:32 +00:00
parent caf102463a
commit 7dc9866681

View File

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