From df5e67e7f398ac8222cc1adc6e3fe197ef430fd1 Mon Sep 17 00:00:00 2001 From: Jann Horn Date: Fri, 9 Sep 2011 19:25:31 +0200 Subject: [PATCH 1/4] walkers: walk subnodes in the same order they get evaluated in --- lib/process.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/process.js b/lib/process.js index 9c82bcee..75120464 100644 --- a/lib/process.js +++ b/lib/process.js @@ -128,13 +128,17 @@ function ast_walker() { return [ this[0], walk(cond), walk(t), walk(e) ]; }, "assign": function(op, lvalue, rvalue) { - return [ this[0], op, walk(lvalue), walk(rvalue) ]; + rvalue = walk(rvalue) + lvalue = walk(lvalue) + return [ this[0], op, lvalue, rvalue ]; }, "dot": function(expr) { return [ this[0], walk(expr) ].concat(slice(arguments, 1)); }, "call": function(expr, args) { - return [ this[0], walk(expr), MAP(args, walk) ]; + args = MAP(args, walk) + expr = walk(expr) + return [ this[0], expr, args ]; }, "function": function(name, args, body) { return [ this[0], name, args.slice(), MAP(body, walk) ]; From 7f0dcc6640ffd66c9ce844b441b7fbfddd21f24b Mon Sep 17 00:00:00 2001 From: Jann Horn Date: Fri, 9 Sep 2011 19:25:58 +0200 Subject: [PATCH 2/4] make default walkers accessible --- lib/process.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/process.js b/lib/process.js index 75120464..2f7d34aa 100644 --- a/lib/process.js +++ b/lib/process.js @@ -253,6 +253,7 @@ function ast_walker() { }; return { + default_walkers: walkers, walk: walk, dive: dive, with_walkers: with_walkers, From b6b1a1ff3d9ad626b5bae622f015fd1f334442b2 Mon Sep 17 00:00:00 2001 From: Jann Horn Date: Fri, 9 Sep 2011 19:28:57 +0200 Subject: [PATCH 3/4] #223: Join literal value assignments into usage --- lib/process.js | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/lib/process.js b/lib/process.js index 2f7d34aa..d73b5931 100644 --- a/lib/process.js +++ b/lib/process.js @@ -988,6 +988,81 @@ function ast_lift_variables(ast) { }); }; +function mergeAssignSimple(ast, options) { + var w = ast_walker() + , walk = w.walk + , mergeable = null + , obsolete = []; + + function arrayCopy(arr) { + var result = []; + for (var i=0; i Date: Sun, 11 Sep 2011 10:49:22 +0200 Subject: [PATCH 4/4] [bugfix] only "="-assignments can be joined --- lib/process.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/process.js b/lib/process.js index d73b5931..0af9b4ec 100644 --- a/lib/process.js +++ b/lib/process.js @@ -1031,7 +1031,7 @@ function mergeAssignSimple(ast, options) { function handleStatement(expr) { var result = [this[0], walk(expr)] mergeable = null - if (expr[0] === "assign" && expr[3][0] in {string:1,num:1,atom:1}) { + if (expr[0] === "assign" && expr[1] === true && expr[3][0] in {string:1,num:1,atom:1}) { // this is a simple-value assigning statement mergeable = {statement: result, type: expr[3][0], value: expr[3][1], assign: expr} }