fix corner case in booleans & conditionals (#5696)

This commit is contained in:
Alex Lam S.L
2022-10-04 05:58:55 +01:00
committed by GitHub
parent dabcc39b51
commit 58d997a3d6
2 changed files with 22 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -831,19 +831,36 @@ issue_5469: {
expect_stdout: "undefined"
}
issue_5694: {
issue_5694_1: {
options = {
booleans: true,
conditionals: true,
}
input: {
var Infinity;
// Node.js v0.12~6 (vm): 42
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): 42
console.log((undefined = 42) && 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
}