fix corner case in reduce_vars (#4384)

fixes #4383
This commit is contained in:
Alex Lam S.L
2020-12-16 20:47:48 +00:00
committed by GitHub
parent 8b10b93ee1
commit f68e267830
2 changed files with 33 additions and 4 deletions

View File

@@ -644,7 +644,14 @@ merge(Compressor.prototype, {
fixed = save;
return true;
}
visit(node, fixed);
visit(node, fixed, function() {
var save_len = tw.stack.length;
for (var i = 0, len = scanner.stack.length - 1; i < len; i++) {
tw.stack.push(scanner.stack[i]);
}
node.walk(tw);
tw.stack.length = save_len;
});
return true;
});
lhs.walk(scanner);
@@ -678,10 +685,10 @@ merge(Compressor.prototype, {
node.right.walk(tw);
scan_declaration(tw, left, function() {
return node.right;
}, function(sym, fixed) {
}, function(sym, fixed, walk) {
if (!(sym instanceof AST_SymbolRef)) {
mark_assignment_to_arguments(sym);
sym.walk(tw);
walk();
return;
}
var d = sym.definition();
@@ -696,7 +703,7 @@ merge(Compressor.prototype, {
sym.fixed = d.fixed = fixed;
sym.fixed.assigns = [ node ];
} else {
sym.walk(tw);
walk();
d.fixed = false;
}
});

View File

@@ -1844,3 +1844,25 @@ issue_4372_2: {
expect_stdout: "PASS"
node_version: ">=6"
}
issue_4383: {
options = {
evaluate: true,
reduce_vars: true,
unsafe: true,
}
input: {
console.log(function(a) {
[ a[0] ] = [];
return a.length;
}([]));
}
expect: {
console.log(function(a) {
[ a[0] ] = [];
return a.length;
}([]));
}
expect_stdout: "1"
node_version: ">=6"
}