Skip to content

rewrite the constructor for ast #2318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
use
  • Loading branch information
yimi committed Sep 18, 2017
commit 7dc98666813122dc34150092d0fdde50c6abe9e1
31 changes: 16 additions & 15 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down