Skip to content

Commit

Permalink
fix(minifier): incorrect folding of expr in bool ctx (#8542)
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Jan 16, 2025
1 parent c30654a commit f57aac2
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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([]);");
Expand Down

0 comments on commit f57aac2

Please sign in to comment.