diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-02-06 18:46:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-06 18:46:25 +0000 |
commit | 551420132c357467a747cae12be39c2662ce56f1 (patch) | |
tree | c3eac8ac64078004a2d2cbfba29fc33c648339ba /lib | |
parent | b0040ba6540232687204d125eff021adf11c4efa (diff) | |
download | tracifyjs-551420132c357467a747cae12be39c2662ce56f1.tar.gz tracifyjs-551420132c357467a747cae12be39c2662ce56f1.zip |
export missing API for AST manipulation (#3707)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ast.js | 4 | ||||
-rw-r--r-- | lib/compress.js | 18 | ||||
-rw-r--r-- | lib/transform.js | 2 | ||||
-rw-r--r-- | lib/utils.js | 20 |
4 files changed, 22 insertions, 22 deletions
@@ -351,7 +351,7 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", { filename: "wrap=" + JSON.stringify(name) }).transform(new TreeTransformer(function(node) { if (node instanceof AST_Directive && node.value == "$ORIG") { - return MAP.splice(body); + return List.splice(body); } })); }, @@ -370,7 +370,7 @@ var AST_Toplevel = DEFNODE("Toplevel", "globals", { filename: "enclose=" + JSON.stringify(args_values) }).transform(new TreeTransformer(function(node) { if (node instanceof AST_Directive && node.value == "$ORIG") { - return MAP.splice(body); + return List.splice(body); } })); } diff --git a/lib/compress.js b/lib/compress.js index b190ef9c..0fcd199e 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1230,7 +1230,7 @@ merge(Compressor.prototype, { var parent = multi_replacer.parent(); if (parent instanceof AST_Sequence && parent.tail_node() !== node) { value_def.replaced++; - return MAP.skip; + return List.skip; } return get_rvalue(candidate); case 1: @@ -1863,7 +1863,7 @@ merge(Compressor.prototype, { node.value = null; return node; } - return in_list ? MAP.skip : null; + return in_list ? List.skip : null; }, patch_sequence)); } @@ -4017,7 +4017,7 @@ merge(Compressor.prototype, { if (value) props.push(value); switch (props.length) { case 0: - return MAP.skip; + return List.skip; case 1: return maintain_this_binding(compressor, parent, node, props[0].transform(tt)); default: @@ -4159,11 +4159,11 @@ merge(Compressor.prototype, { } switch (body.length) { case 0: - return in_list ? MAP.skip : make_node(AST_EmptyStatement, node); + return in_list ? List.skip : make_node(AST_EmptyStatement, node); case 1: return body[0]; default: - return in_list ? MAP.splice(body) : make_node(AST_BlockStatement, node, { + return in_list ? List.splice(body) : make_node(AST_BlockStatement, node, { body: body }); } @@ -4177,7 +4177,7 @@ merge(Compressor.prototype, { var block = node.body; node.body = block.body.pop(); block.body.push(node); - return in_list ? MAP.splice(block.body) : block; + return in_list ? List.splice(block.body) : block; } return node; } @@ -4214,7 +4214,7 @@ merge(Compressor.prototype, { } else if (is_empty(node.init)) { node.init = null; } - return !block ? node : in_list ? MAP.splice(block.body) : block; + return !block ? node : in_list ? List.splice(block.body) : block; } else if (node instanceof AST_ForIn) { if (!drop_vars || !compressor.option("loops")) return; if (!(node.init instanceof AST_Definitions)) return; @@ -4229,7 +4229,7 @@ merge(Compressor.prototype, { body: value }); } - return in_list ? MAP.skip : make_node(AST_EmptyStatement, node); + return in_list ? List.skip : make_node(AST_EmptyStatement, node); } else if (node instanceof AST_Sequence) { if (node.expressions.length == 1) return node.expressions[0]; } @@ -4610,7 +4610,7 @@ merge(Compressor.prototype, { })); }); defs_by_id[node.name.definition().id] = defs; - return MAP.splice(var_defs); + return List.splice(var_defs); } function make_sym(sym, key) { diff --git a/lib/transform.js b/lib/transform.js index 5897aa77..e97cb741 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -52,7 +52,7 @@ TreeTransformer.prototype = new TreeWalker; (function(DEF) { function do_list(list, tw) { - return MAP(list, function(node) { + return List(list, function(node) { return node.transform(tw, true); }); } diff --git a/lib/utils.js b/lib/utils.js index 6ac68bbd..da82a140 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -113,8 +113,8 @@ function return_true() { return true; } function return_this() { return this; } function return_null() { return null; } -var MAP = (function() { - function MAP(a, f, backwards) { +var List = (function() { + function List(a, f, backwards) { var ret = [], top = [], i; function doit() { var val = f(a[i], i); @@ -149,14 +149,14 @@ var MAP = (function() { } return top.concat(ret); } - MAP.at_top = function(val) { return new AtTop(val) }; - MAP.splice = function(val) { return new Splice(val) }; - MAP.last = function(val) { return new Last(val) }; - var skip = MAP.skip = {}; - function AtTop(val) { this.v = val } - function Splice(val) { this.v = val } - function Last(val) { this.v = val } - return MAP; + List.at_top = function(val) { return new AtTop(val); }; + List.splice = function(val) { return new Splice(val); }; + List.last = function(val) { return new Last(val); }; + var skip = List.skip = {}; + function AtTop(val) { this.v = val; } + function Splice(val) { this.v = val; } + function Last(val) { this.v = val; } + return List; })(); function push_uniq(array, el) { |