Skip to content

Commit

Permalink
fix TreeWalker scan order (#3114)
Browse files Browse the repository at this point in the history
fixes #3113
  • Loading branch information
alexlamsl authored May 2, 2018
1 parent 1a314e9 commit a0ca595
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/ast.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
}
});
Expand Down
36 changes: 36 additions & 0 deletions test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit a0ca595

Please sign in to comment.