fix `TreeWalker` scan order (#3114)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 2 May 2018 16:27:45 +0000 (00:27 +0800)
committerGitHub <noreply@github.com>
Wed, 2 May 2018 16:27:45 +0000 (00:27 +0800)
fixes #3113

lib/ast.js
test/compress/reduce_vars.js

index ded3bbf..b4b4765 100644 (file)
@@ -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);
+            });
         });
     }
 });
index afc8645..b21b760 100644 (file)
@@ -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"
+}