mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
fix(minifier): incorrect folding of expr in bool ctx (#8542)
esbuild code comment is wrong.
8f1faf7d4a/internal/js_ast/js_ast_helpers.go (L2127-L2128)
https://esbuild.github.io/try/#dAAwLjI0LjIALS1taW5pZnkAaWYgKGFueXRoaW5nMSA/ICgwLCBmYWxzZSkgOiBhbnl0aGluZzIpOw
This commit is contained in:
parent
c30654a793
commit
f57aac2aee
1 changed files with 3 additions and 3 deletions
|
|
@ -739,11 +739,11 @@ impl<'a> PeepholeMinimizeConditions {
|
|||
*expr =
|
||||
ctx.ast.expression_logical(e.span(), left, LogicalOperator::Or, right);
|
||||
} else {
|
||||
// "if (anything1 ? falsyNoSideEffects : anything2)" => "if (!anything1 || anything2)"
|
||||
// "if (anything1 ? falsyNoSideEffects : anything2)" => "if (!anything1 && anything2)"
|
||||
let left =
|
||||
ctx.ast.expression_unary(left.span(), UnaryOperator::LogicalNot, left);
|
||||
*expr =
|
||||
ctx.ast.expression_logical(e.span(), left, LogicalOperator::Or, right);
|
||||
ctx.ast.expression_logical(e.span(), left, LogicalOperator::And, right);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
@ -2028,7 +2028,7 @@ mod test {
|
|||
test("if (anything || (0, false));", "if (anything);");
|
||||
test("if (a ? !!b : !!c);", "if (a ? b : c);");
|
||||
test("if (anything1 ? (0, true) : anything2);", "if (anything1 || anything2);");
|
||||
test("if (anything1 ? (0, false) : anything2);", "if (!anything1 || anything2);");
|
||||
test("if (anything1 ? (0, false) : anything2);", "if (!anything1 && anything2);");
|
||||
test("if (anything1 ? anything2 : (0, true));", "if (!anything1 || anything2);");
|
||||
test("if (anything1 ? anything2 : (0, false));", "if (anything1 && anything2);");
|
||||
test("if(!![]);", "if([]);");
|
||||
|
|
|
|||
Loading…
Reference in a new issue