Skip to content

Commit

Permalink
feat(minifier): remove logical nots when arg is a delete expression
Browse files Browse the repository at this point in the history
  • Loading branch information
camc314 committed Jan 6, 2025
1 parent bb5e30c commit d42d262
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/oxc_minifier/src/ast_passes/peephole_minimize_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ impl<'a> PeepholeMinimizeConditions {
expr.argument = ctx.ast.move_expression(&mut e2.argument);
return Some(ctx.ast.move_expression(&mut expr.argument));
}
// `!!delete a.b` -> `delete a.b`
if e2.operator.is_delete() {
return Some(ctx.ast.move_expression(&mut e1.argument));
}
}
// `!!a` -> `a` // ONLY in boolean contexts
if Self::is_in_boolean_context(ctx) {
Expand Down Expand Up @@ -1727,4 +1731,11 @@ mod test {
test_same("var k = () => { return !!x; }");
test_same("var k = () => !!x;");
}

#[test]
fn minimize_nots_with_deletes() {
test("!!delete x.y", "delete x.y");
test("!!!delete x.y", "!delete x.y");
test("!!!!delete x.y", "delete x.y");
}
}

0 comments on commit d42d262

Please sign in to comment.