Skip to content

Commit 8195a66

Browse files
authored
fix corner case in collapse_vars (#5855)
fixes #5854
1 parent 9c80456 commit 8195a66

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

lib/compress.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2722,8 +2722,10 @@ Compressor.prototype.compress = function(node) {
27222722
if (sym instanceof AST_PropAccess) return true;
27232723
if (check_destructured(sym)) return true;
27242724
return sym.match_symbol(function(node) {
2725-
return node instanceof AST_SymbolRef
2726-
&& (lvalues.has(node.name) || read_toplevel && compressor.exposed(node.definition()));
2725+
if (node instanceof AST_PropAccess) return true;
2726+
if (node instanceof AST_SymbolRef) {
2727+
return lvalues.has(node.name) || read_toplevel && compressor.exposed(node.definition());
2728+
}
27272729
}, true);
27282730

27292731
function reject(node) {

test/compress/destructured.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3959,3 +3959,51 @@ issue_5844: {
39593959
expect_stdout: "PASS"
39603960
node_version: ">=6"
39613961
}
3962+
3963+
issue_5854_1: {
3964+
options = {
3965+
collapse_vars: true,
3966+
}
3967+
input: {
3968+
console.log(function(a) {
3969+
var b = a;
3970+
a++;
3971+
[ b[0] ] = [ "foo" ];
3972+
return a;
3973+
}([]) ? "PASS" : "FAIL");
3974+
}
3975+
expect: {
3976+
console.log(function(a) {
3977+
var b = a;
3978+
a++;
3979+
[ b[0] ] = [ "foo" ];
3980+
return a;
3981+
}([]) ? "PASS" : "FAIL");
3982+
}
3983+
expect_stdout: "PASS"
3984+
node_version: ">=6"
3985+
}
3986+
3987+
issue_5854_2: {
3988+
options = {
3989+
collapse_vars: true,
3990+
}
3991+
input: {
3992+
console.log(function(a) {
3993+
var b = a;
3994+
a++;
3995+
({ p: b[0] } = { p: "foo" });
3996+
return a;
3997+
}([]) ? "PASS" : "FAIL");
3998+
}
3999+
expect: {
4000+
console.log(function(a) {
4001+
var b = a;
4002+
a++;
4003+
({ p: b[0] } = { p: "foo" });
4004+
return a;
4005+
}([]) ? "PASS" : "FAIL");
4006+
}
4007+
expect_stdout: "PASS"
4008+
node_version: ">=6"
4009+
}

0 commit comments

Comments
 (0)