Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix corner case in merge_vars #5609

Merged
merged 1 commit into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -6474,16 +6474,13 @@ Compressor.prototype.compress = function(node) {
} else {
assigned = segment.block instanceof AST_ForEnumeration && segment.block.init === tw.parent();
}
node.name.mark_symbol(assigned ? function(node) {
if (!(node instanceof AST_SymbolDeclaration)) return;
walk_destructured(AST_SymbolDeclaration, assigned ? function(node) {
if (node instanceof AST_SymbolVar) {
mark(node);
} else {
references[node.definition().id] = false;
}
return true;
} : function(node) {
if (!(node instanceof AST_SymbolDeclaration)) return;
var id = node.definition().id;
if (!(node instanceof AST_SymbolVar)) {
references[id] = false;
Expand All @@ -6492,8 +6489,7 @@ Compressor.prototype.compress = function(node) {
} else if (references[id]) {
references[id].push(node);
}
return true;
}, tw);
}, node.name);
return true;
}
if (node instanceof AST_While) {
Expand Down Expand Up @@ -6613,13 +6609,16 @@ Compressor.prototype.compress = function(node) {
pop();
node.name.walk(marker);
} else if (node instanceof AST_DestructuredKeyVal) {
if (node.key instanceof AST_Node) {
if (!(node.key instanceof AST_Node)) {
node.value.walk(marker);
} else if (node.value instanceof AST_PropAccess) {
push();
segment.block = node;
node.key.walk(tw);
node.value.walk(marker);
pop();
} else {
node.key.walk(tw);
node.value.walk(marker);
}
} else if (node instanceof symbol_type) {
Expand Down
28 changes: 27 additions & 1 deletion test/compress/default-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -1718,7 +1718,7 @@ issue_4540: {
node_version: ">=6"
}

issue_4548: {
issue_4548_1: {
options = {
merge_vars: true,
toplevel: true,
Expand All @@ -1744,6 +1744,32 @@ issue_4548: {
node_version: ">=6"
}

issue_4548_2: {
options = {
merge_vars: true,
toplevel: true,
}
input: {
A = "foo";
var a = A;
var [ b = c = "bar" ] = [ console, console.log(a) ];
console.log(c);
var c;
}
expect: {
A = "foo";
var a = A;
var [ b = c = "bar" ] = [ console, console.log(a) ];
console.log(c);
var c;
}
expect_stdout: [
"foo",
"undefined",
]
node_version: ">=6"
}

issue_4588_1_unused: {
options = {
unused: true,
Expand Down
9 changes: 4 additions & 5 deletions test/compress/destructured.js
Original file line number Diff line number Diff line change
Expand Up @@ -1902,8 +1902,8 @@ issue_4288: {
console.log(typeof b);
}()]: a,
}) {
var b = a;
b++;
var a = a;
a++;
}
f(0);
}
Expand Down Expand Up @@ -2076,17 +2076,16 @@ issue_4312: {
console.log(a);
}
expect: {
var a;
b = "PASS",
c = "FAIL",
[
{
[a = b]: d,
[c = b]: d,
},
] = [ c && c ],
void 0;
var b, c, d;
console.log(a);
console.log(c);
}
expect_stdout: "PASS"
node_version: ">=6"
Expand Down