From 6546aaa704ad0dfe693e1c06f98e00ef69bceb57 Mon Sep 17 00:00:00 2001 From: yimi Date: Mon, 18 Sep 2017 06:47:05 +0000 Subject: [PATCH 1/5] rewrite the constructor for `ast` --- lib/ast.js | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index 0918574d11..d253b09a17 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -47,25 +47,28 @@ function DEFNODE(type, props, methods, base) { if (arguments.length < 4) base = AST_Node; if (!props) props = []; else props = props.split(/\s+/); - var self_props = props; - if (base && base.PROPS) - props = props.concat(base.PROPS); - var code = "return function AST_" + type + "(props){ if (props) { "; - for (var i = props.length; --i >= 0;) { - code += "this." + props[i] + " = props." + props[i] + ";"; + 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 proto = base && new base; - if (proto && proto.initialize || (methods && methods.initialize)) - code += "this.initialize();"; - code += "}}"; - var ctor = new Function(code)(); if (proto) { ctor.prototype = proto; ctor.BASE = base; } if (base) base.SUBCLASSES.push(ctor); ctor.prototype.CTOR = ctor; - ctor.PROPS = props || null; ctor.SELF_PROPS = self_props; ctor.SUBCLASSES = []; if (type) { From 00c43cee458a600a9edc4a7205f96ec8720bbd1c Mon Sep 17 00:00:00 2001 From: yimi Date: Mon, 18 Sep 2017 07:18:28 +0000 Subject: [PATCH 2/5] fix --- lib/ast.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ast.js b/lib/ast.js index d253b09a17..fde574c5d4 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -69,7 +69,7 @@ function DEFNODE(type, props, methods, base) { } if (base) base.SUBCLASSES.push(ctor); ctor.prototype.CTOR = ctor; - ctor.SELF_PROPS = self_props; + ctor.SELF_PROPS = props; ctor.SUBCLASSES = []; if (type) { ctor.prototype.TYPE = ctor.TYPE = type; From b4911cb81be6a68674af1da4fdf820770811f6ba Mon Sep 17 00:00:00 2001 From: yimi Date: Mon, 18 Sep 2017 07:24:24 +0000 Subject: [PATCH 3/5] fix --- lib/ast.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ast.js b/lib/ast.js index fde574c5d4..b73d2ebe2e 100644 --- a/lib/ast.js +++ b/lib/ast.js @@ -74,7 +74,7 @@ function DEFNODE(type, props, methods, base) { if (type) { ctor.prototype.TYPE = ctor.TYPE = type; } - if (methods) for (i in methods) if (HOP(methods, i)) { + if (methods) for (var i in methods) if (HOP(methods, i)) { if (/^\$/.test(i)) { ctor[i.substr(1)] = methods[i]; } else { From caf102463a27179f8ef517d9932cdb1487899670 Mon Sep 17 00:00:00 2001 From: yimi Date: Mon, 18 Sep 2017 08:53:24 +0000 Subject: [PATCH 4/5] fix json --- bin/uglifyjs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bin/uglifyjs b/bin/uglifyjs index 8cbb3cadd8..8f1587121e 100755 --- a/bin/uglifyjs +++ b/bin/uglifyjs @@ -232,9 +232,12 @@ function run() { var result = { _class: "AST_" + value.TYPE }; - value.CTOR.PROPS.forEach(function(prop) { - result[prop] = value[prop]; - }); + var ctor = value.CTOR; + do { + ctor.SELF_PROPS.forEach(function(prop) { + result[prop] = value[prop]; + }); + } while (ctor = ctor.BASE); return result; } return value; From 7dc98666813122dc34150092d0fdde50c6abe9e1 Mon Sep 17 00:00:00 2001 From: yimi Date: Mon, 18 Sep 2017 09:48:32 +0000 Subject: [PATCH 5/5] use --- lib/ast.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lib/ast.js b/lib/ast.js index b73d2ebe2e..4d8b1431ed 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;