Skip to content

Commit

Permalink
refactor: use match.
Browse files Browse the repository at this point in the history
  • Loading branch information
7086cmd committed Oct 1, 2024
1 parent e64f030 commit 833407d
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,14 @@ impl<'a> PeepholeFoldConstants {
Some(ctx.ast.move_expression(&mut expr.argument))
}
// `+1` -> `1`
UnaryOperator::UnaryPlus => {
if expr.argument.is_number() {
Some(ctx.ast.move_expression(&mut expr.argument))
} else if let Expression::UnaryExpression(un_expr) = &mut expr.argument {
// handle +-
matches!(un_expr.operator, UnaryOperator::UnaryNegation)
UnaryOperator::UnaryPlus => match &expr.argument {
Expression::UnaryExpression(unary) => {
matches!(unary.operator, UnaryOperator::UnaryNegation)
.then(|| ctx.ast.move_expression(&mut expr.argument))
} else {
None
}
}
_ if expr.argument.is_number() => Some(ctx.ast.move_expression(&mut expr.argument)),
_ => None,
},
_ => None,
}
}
Expand Down

0 comments on commit 833407d

Please sign in to comment.