mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(minifier): remove logical nots when arg is a delete expression (#8303)
This commit is contained in:
parent
5ed439bcaf
commit
76c778b03f
1 changed files with 11 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue