Skip to content

Commit

Permalink
fix corner case in collapse_vars (#4855)
Browse files Browse the repository at this point in the history
fixes #4854
  • Loading branch information
alexlamsl committed Apr 13, 2021
1 parent f1f4a4d commit c53af3d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/compress.js
Expand Up @@ -1792,7 +1792,12 @@ merge(Compressor.prototype, {
right: candidate.value
});
}
candidate.write_only = false;
var assign = candidate;
while (assign.write_only) {
assign.write_only = false;
if (!(assign instanceof AST_Assign)) break;
assign = assign.right;
}
return candidate;
}
// These node types have child nodes that execute sequentially,
Expand Down
22 changes: 22 additions & 0 deletions test/compress/default-values.js
Expand Up @@ -1681,3 +1681,25 @@ issue_4817: {
expect_stdout: "function"
node_version: ">=6"
}

issue_4854: {
options = {
collapse_vars: true,
inline: true,
side_effects: true,
unused: true,
}
input: {
console.log(function(a) {
(function(b = a = "foo") {
[] = "foo";
})();
a;
}());
}
expect: {
console.log(void ([] = "foo"));
}
expect_stdout: "undefined"
node_version: ">=6"
}

0 comments on commit c53af3d

Please sign in to comment.