fix corner case in collapse_vars (#5855)

fixes #5854
This commit is contained in:
Alex Lam S.L
2024-06-19 05:15:03 +03:00
committed by GitHub
parent 9c80456634
commit 8195a664fd
2 changed files with 52 additions and 2 deletions

View File

@@ -2722,8 +2722,10 @@ Compressor.prototype.compress = function(node) {
if (sym instanceof AST_PropAccess) return true; if (sym instanceof AST_PropAccess) return true;
if (check_destructured(sym)) return true; if (check_destructured(sym)) return true;
return sym.match_symbol(function(node) { return sym.match_symbol(function(node) {
return node instanceof AST_SymbolRef if (node instanceof AST_PropAccess) return true;
&& (lvalues.has(node.name) || read_toplevel && compressor.exposed(node.definition())); if (node instanceof AST_SymbolRef) {
return lvalues.has(node.name) || read_toplevel && compressor.exposed(node.definition());
}
}, true); }, true);
function reject(node) { function reject(node) {

View File

@@ -3959,3 +3959,51 @@ issue_5844: {
expect_stdout: "PASS" expect_stdout: "PASS"
node_version: ">=6" node_version: ">=6"
} }
issue_5854_1: {
options = {
collapse_vars: true,
}
input: {
console.log(function(a) {
var b = a;
a++;
[ b[0] ] = [ "foo" ];
return a;
}([]) ? "PASS" : "FAIL");
}
expect: {
console.log(function(a) {
var b = a;
a++;
[ b[0] ] = [ "foo" ];
return a;
}([]) ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
node_version: ">=6"
}
issue_5854_2: {
options = {
collapse_vars: true,
}
input: {
console.log(function(a) {
var b = a;
a++;
({ p: b[0] } = { p: "foo" });
return a;
}([]) ? "PASS" : "FAIL");
}
expect: {
console.log(function(a) {
var b = a;
a++;
({ p: b[0] } = { p: "foo" });
return a;
}([]) ? "PASS" : "FAIL");
}
expect_stdout: "PASS"
node_version: ">=6"
}