mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
fix(minifier): !!x is not idempotent in RemoveDeadCode (#8419)
This commit is contained in:
parent
0550e81da6
commit
d4ca8d4f5c
2 changed files with 11 additions and 8 deletions
|
|
@ -1951,6 +1951,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn minimize_duplicate_nots() {
|
fn minimize_duplicate_nots() {
|
||||||
|
// test("!x", "x"); // TODO: in ExpressionStatement
|
||||||
test("!!x", "x");
|
test("!!x", "x");
|
||||||
test("!!!x", "!x");
|
test("!!!x", "!x");
|
||||||
test("!!!!x", "x");
|
test("!!!!x", "x");
|
||||||
|
|
|
||||||
|
|
@ -341,12 +341,12 @@ impl<'a, 'b> PeepholeRemoveDeadCode {
|
||||||
{
|
{
|
||||||
Some(ctx.ast.statement_empty(SPAN))
|
Some(ctx.ast.statement_empty(SPAN))
|
||||||
}
|
}
|
||||||
// `typeof x.y` -> `x`, `!x` -> `x`, `void x` -> `x`...
|
// `typeof x.y` -> `x.y`, `void x` -> `x`
|
||||||
// `+0n` -> `Uncaught TypeError: Cannot convert a BigInt value to a number`
|
// `+0n` -> `Uncaught TypeError: Cannot convert a BigInt value to a number`
|
||||||
Expression::UnaryExpression(unary_expr)
|
Expression::UnaryExpression(unary_expr)
|
||||||
if !matches!(
|
if matches!(
|
||||||
unary_expr.operator,
|
unary_expr.operator,
|
||||||
UnaryOperator::Delete | UnaryOperator::UnaryPlus
|
UnaryOperator::Typeof | UnaryOperator::Void
|
||||||
) =>
|
) =>
|
||||||
{
|
{
|
||||||
Some(ctx.ast.statement_expression(
|
Some(ctx.ast.statement_expression(
|
||||||
|
|
@ -700,11 +700,13 @@ mod test {
|
||||||
fold("void x?.y", "x?.y");
|
fold("void x?.y", "x?.y");
|
||||||
fold("void x.y", "x.y");
|
fold("void x.y", "x.y");
|
||||||
fold("void x.y.z()", "x.y.z()");
|
fold("void x.y.z()", "x.y.z()");
|
||||||
fold("!x", "x");
|
|
||||||
fold("!x?.y", "x?.y");
|
// Removed in `MinimizeConditions`, to keep this pass idempotent for DCE.
|
||||||
fold("!x.y", "x.y");
|
fold_same("!x");
|
||||||
fold("!x.y.z()", "x.y.z()");
|
fold_same("!x?.y");
|
||||||
fold("-x.y.z()", "x.y.z()");
|
fold_same("!x.y");
|
||||||
|
fold_same("!x.y.z()");
|
||||||
|
fold_same("-x.y.z()");
|
||||||
|
|
||||||
fold_same("delete x");
|
fold_same("delete x");
|
||||||
fold_same("delete x.y");
|
fold_same("delete x.y");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue