Skip to content

Commit

Permalink
fix corner case in booleans & conditionals (#5696)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl authored Oct 4, 2022
1 parent dabcc39 commit 58d997a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -11592,7 +11592,7 @@ Compressor.prototype.compress = function(node) {

function extract_lhs(node, compressor) {
if (node instanceof AST_Assign) return is_lhs_read_only(node.left, compressor) ? node : node.left;
if (node instanceof AST_Sequence) return extract_lhs(node.tail_node());
if (node instanceof AST_Sequence) return extract_lhs(node.tail_node(), compressor);
if (node instanceof AST_UnaryPrefix && UNARY_POSTFIX[node.operator]) {
return is_lhs_read_only(node.expression, compressor) ? node : node.expression;
}
Expand Down
25 changes: 21 additions & 4 deletions test/compress/booleans.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,19 +831,36 @@ issue_5469: {
expect_stdout: "undefined"
}

issue_5694: {
issue_5694_1: {
options = {
booleans: true,
conditionals: true,
}
input: {
var undefined;
var Infinity;
// Node.js v0.12~6 (vm): 42
console.log((undefined = 42) && undefined);
console.log((Infinity = 42) && Infinity);
}
expect: {
var Infinity;
console.log((Infinity = 42) && Infinity);
}
expect_stdout: true
}

issue_5694_2: {
options = {
booleans: true,
conditionals: true,
}
input: {
var undefined;
// Node.js v0.12~6 (vm): NaN
console.log(("foo", ++undefined) || undefined);
}
expect: {
var undefined;
console.log((undefined = 42) && undefined);
console.log(("foo", ++undefined) || undefined);
}
expect_stdout: true
}

0 comments on commit 58d997a

Please sign in to comment.