fix corner case in booleans (#5470)

fixes #5469
This commit is contained in:
Alex Lam S.L 2022-05-25 22:33:50 +01:00 committed by GitHub
parent 5979b195fe
commit 59b23b8c13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 10 deletions

View File

@ -9174,11 +9174,12 @@ Compressor.prototype.compress = function(node) {
child = parent; child = parent;
parent = compressor.parent(level++); parent = compressor.parent(level++);
if (parent instanceof AST_Binary) { if (parent instanceof AST_Binary) {
var op = parent.operator; switch (child) {
if (!lazy_op[op]) return; case parent.left:
var left = parent.left; if (lazy_op[parent.operator]) continue;
if (left === child) continue; break;
if (match(left)) switch (op) { case parent.right:
if (match(parent.left)) switch (parent.operator) {
case "&&": case "&&":
node[negated ? "falsy" : "truthy"] = true; node[negated ? "falsy" : "truthy"] = true;
break; break;
@ -9187,6 +9188,8 @@ Compressor.prototype.compress = function(node) {
node[negated ? "truthy" : "falsy"] = true; node[negated ? "truthy" : "falsy"] = true;
break; break;
} }
break;
}
} else if (parent instanceof AST_Conditional) { } else if (parent instanceof AST_Conditional) {
var cond = parent.condition; var cond = parent.condition;
if (cond === child) continue; if (cond === child) continue;

View File

@ -762,3 +762,27 @@ issue_5228: {
} }
expect_stdout: "true" expect_stdout: "true"
} }
issue_5469: {
options = {
assignments: true,
booleans: true,
conditionals: true,
dead_code: true,
evaluate: true,
pure_getters: "strict",
side_effects: true,
}
input: {
console.log(function f(a) {
a && 42[a = A && null];
}());
}
expect: {
console.log(function f(a) {
a && A,
0;
}());
}
expect_stdout: "undefined"
}