Skip to content

Commit

Permalink
fix(codegen): print delete 2e308 as delete (0, Infinity) (#7761)
Browse files Browse the repository at this point in the history
closes #7736
  • Loading branch information
Boshen committed Dec 10, 2024
1 parent 4bd3d10 commit a222f2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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')');
}
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions crates/oxc_codegen/tests/integration/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit a222f2b

Please sign in to comment.