Skip to content

Commit

Permalink
fix corner case in collapse_vars (#5855)
Browse files Browse the repository at this point in the history
fixes #5854
  • Loading branch information
alexlamsl committed Jun 19, 2024
1 parent 9c80456 commit 8195a66
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -2722,8 +2722,10 @@ Compressor.prototype.compress = function(node) {
if (sym instanceof AST_PropAccess) return true;
if (check_destructured(sym)) return true;
return sym.match_symbol(function(node) {
return node instanceof AST_SymbolRef
&& (lvalues.has(node.name) || read_toplevel && compressor.exposed(node.definition()));
if (node instanceof AST_PropAccess) return true;
if (node instanceof AST_SymbolRef) {
return lvalues.has(node.name) || read_toplevel && compressor.exposed(node.definition());
}
}, true);

function reject(node) {
Expand Down
48 changes: 48 additions & 0 deletions test/compress/destructured.js
Original file line number Diff line number Diff line change
Expand Up @@ -3959,3 +3959,51 @@ issue_5844: {
expect_stdout: "PASS"
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"
}

0 comments on commit 8195a66

Please sign in to comment.