mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(minifier): minify unary plus negation. (#6203)
resolves #6201. It is uncertain whether this applies to other situations, so let us eliminate it in negation first, and after I have conducted a comprehensive investigation of the Closure Compiler, we can make a definitive decision.
This commit is contained in:
parent
7a381ee8f0
commit
dac8f09232
1 changed files with 9 additions and 4 deletions
|
|
@ -157,9 +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))
|
||||
}
|
||||
UnaryOperator::UnaryPlus => match &expr.argument {
|
||||
Expression::UnaryExpression(unary) => {
|
||||
matches!(unary.operator, UnaryOperator::UnaryNegation)
|
||||
.then(|| ctx.ast.move_expression(&mut expr.argument))
|
||||
}
|
||||
_ if expr.argument.is_number() => Some(ctx.ast.move_expression(&mut expr.argument)),
|
||||
_ => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
@ -1276,7 +1281,7 @@ mod test {
|
|||
test("a=+0", "a=0");
|
||||
// test("a=+Infinity", "a=Infinity");
|
||||
// test("a=+NaN", "a=NaN");
|
||||
// test("a=+-7", "a=-7");
|
||||
test("a=+-7", "a=-7");
|
||||
// test("a=+.5", "a=.5");
|
||||
|
||||
// test("a=~0xffffffff", "a=0");
|
||||
|
|
|
|||
Loading…
Reference in a new issue