diff --git a/crates/oxc_codegen/src/gen.rs b/crates/oxc_codegen/src/gen.rs index 9031b18700916..620dbdf392165 100644 --- a/crates/oxc_codegen/src/gen.rs +++ b/crates/oxc_codegen/src/gen.rs @@ -1741,7 +1741,18 @@ impl GenExpr for UnaryExpression<'_> { p.prev_op = Some(self.operator.into()); p.prev_op_end = p.code().len(); } + // Forbid `delete Infinity`, which is syntax error in strict mode. + let is_delete_infinity = self.operator == UnaryOperator::Delete + && !p.options.minify + && matches!(&self.argument, Expression::NumericLiteral(lit) if lit.value.is_sign_positive() && lit.value.is_infinite()); + if is_delete_infinity { + p.print_str("(0,"); + p.print_soft_space(); + } self.argument.print_expr(p, Precedence::Exponentiation, ctx); + if is_delete_infinity{ + p.print_ascii_byte(b')'); + } }); } } diff --git a/crates/oxc_codegen/tests/integration/unit.rs b/crates/oxc_codegen/tests/integration/unit.rs index 594cc10ee70c8..1dc91547b92e9 100644 --- a/crates/oxc_codegen/tests/integration/unit.rs +++ b/crates/oxc_codegen/tests/integration/unit.rs @@ -26,6 +26,9 @@ fn expr() { test_minify_same("return new.target;"); test_minify_same("throw await 1;"); test_minify_same("await import(\"\");"); + + test("delete 2e308", "delete (0, Infinity);\n"); + test_minify("delete 2e308", "delete (1/0);"); } #[test]