Skip to content

Commit

Permalink
fix corner case in dead_code
Browse files Browse the repository at this point in the history
fixes #5941
  • Loading branch information
alexlamsl committed Sep 28, 2024
1 parent d460c70 commit 1077323
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -13146,7 +13146,9 @@ Compressor.prototype.compress = function(node) {
node = parent;
parent = compressor.parent(level++);
if (parent instanceof AST_Assign) {
if (parent.left instanceof AST_SymbolRef && parent.left.definition() === def) {
if (parent.right === node
&& parent.left instanceof AST_SymbolRef
&& parent.left.definition() === def) {
if (in_try(level, parent, !local)) break;
return strip_assignment(def);
}
Expand Down
18 changes: 18 additions & 0 deletions test/compress/assignments.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,3 +862,21 @@ issue_5670: {
}
expect_stdout: "PASS"
}

issue_5941: {
options = {
assignments: true,
conditionals: true,
dead_code: true,
}
input: {
var a = 1;
a = a &&= (a = console) && console.log(typeof a);
}
expect: {
var a = 1;
a = (a = a && console) && console.log(typeof a);
}
expect_stdout: "object"
node_version: ">=15"
}

0 comments on commit 1077323

Please sign in to comment.