Skip to content

Commit

Permalink
fix corner case in evaluate (#5942)
Browse files Browse the repository at this point in the history
fixes #5940
  • Loading branch information
alexlamsl authored Sep 28, 2024
1 parent d460c70 commit 5c3927c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -12270,7 +12270,7 @@ Compressor.prototype.compress = function(node) {
return maintain_this_binding(parent, compressor.self(), self.left).optimize(compressor);
} else if (!(ll instanceof AST_Node)) {
AST_Node.warn("Condition left of && always true [{start}]", self);
return make_sequence(self, [ self.left, self.right ]).optimize(compressor);
return make_sequence(self, [ self.left.clone(), self.right ]).optimize(compressor);
}
if (!self.right.evaluate(compressor, true)) {
if (in_bool && !(self.right.evaluate(compressor) instanceof AST_Node)) {
Expand Down
23 changes: 23 additions & 0 deletions test/compress/evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3416,3 +3416,26 @@ issue_5558: {
}
expect_stdout: "100"
}

issue_5940: {
options = {
conditionals: true,
evaluate: true,
sequences: true,
side_effects: true,
unused: true,
}
input: {
(function f(a) {
f && (console, 42) && (f && (a = [])) && console.log("PASS");
f = 42;
})();
}
expect: {
(function f(a) {
f && (console, 42) && (f && []) && console.log("PASS"),
f = 42;
})();
}
expect_stdout: "PASS"
}

0 comments on commit 5c3927c

Please sign in to comment.