aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Lam S.L <alexlamsl@gmail.com>2018-05-03 00:27:45 +0800
committerGitHub <noreply@github.com>2018-05-03 00:27:45 +0800
commita0ca595c2c51809181908b9122992702aec888ab (patch)
tree4b5c0874a5935a8b29f44bc9317faa0a5171810b
parent1a314e9f60735634f85e56d7b003ee83707561f4 (diff)
downloadtracifyjs-a0ca595c2c51809181908b9122992702aec888ab.tar.gz
tracifyjs-a0ca595c2c51809181908b9122992702aec888ab.zip
fix `TreeWalker` scan order (#3114)
fixes #3113
-rw-r--r--lib/ast.js9
-rw-r--r--test/compress/reduce_vars.js36
2 files changed, 40 insertions, 5 deletions
diff --git a/lib/ast.js b/lib/ast.js
index ded3bbfb..b4b47651 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -543,12 +543,11 @@ var AST_Call = DEFNODE("Call", "expression args", {
args: "[AST_Node*] array of arguments"
},
_walk: function(visitor) {
- return visitor._visit(this, function(){
- var args = this.args;
- for (var i = 0, len = args.length; i < len; i++) {
- args[i]._walk(visitor);
- }
+ return visitor._visit(this, function() {
this.expression._walk(visitor);
+ this.args.forEach(function(node) {
+ node._walk(visitor);
+ });
});
}
});
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index afc86452..b21b760b 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -5833,3 +5833,39 @@ issue_3110_3: {
"foo",
]
}
+
+issue_3113: {
+ options = {
+ evaluate: true,
+ reduce_vars: true,
+ }
+ input: {
+ var c = 0;
+ (function() {
+ function f() {
+ while (g());
+ }
+ var a = f();
+ function g() {
+ a && a[c++];
+ }
+ g(a = 1);
+ })();
+ console.log(c);
+ }
+ expect: {
+ var c = 0;
+ (function() {
+ function f() {
+ while (g());
+ }
+ var a = f();
+ function g() {
+ a && a[c++];
+ }
+ g(a = 1);
+ })();
+ console.log(c);
+ }
+ expect_stdout: "1"
+}