Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: 翠 / green <[email protected]>
  • Loading branch information
Boshen and sapphi-red committed Feb 2, 2025
1 parent f590004 commit 6bac151
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions crates/oxc_minifier/src/peephole/minimize_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,14 @@ impl<'a> PeepholeOptimizations {
} else if let Some(stmt) = &mut if_stmt.alternate {
// "yes" is missing and "no" is not missing (and is not an expression)
match &mut if_stmt.test {
// "if (!a) {} else return b;" => "if (a) return b;"
Expression::UnaryExpression(unary_expr) if unary_expr.operator.is_not() => {
if_stmt.test = ctx.ast.move_expression(&mut unary_expr.argument);
if_stmt.consequent = ctx.ast.move_statement(stmt);
if_stmt.alternate = None;
self.mark_current_function_as_changed();
}
// "if (a) {} else return b;" => "if (!a) return b;"
_ => {
if_stmt.test = Self::minimize_not(
if_stmt.test.span(),
Expand All @@ -219,6 +221,7 @@ impl<'a> PeepholeOptimizations {
self.mark_current_function_as_changed();
}
}
// "if (a) return b; else {}" => "if (a) return b;" is handled by remove_dead_code
} else {
// "no" is missing
if let Statement::IfStatement(if2_stmt) = &mut if_stmt.consequent {
Expand Down

0 comments on commit 6bac151

Please sign in to comment.