mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 04:42:10 +00:00
fix(codegen): print delete 2e308 as delete (0, Infinity) (#7761)
closes #7736
This commit is contained in:
parent
4bd3d103d3
commit
a222f2b055
2 changed files with 14 additions and 0 deletions
|
|
@ -1741,7 +1741,18 @@ impl GenExpr for UnaryExpression<'_> {
|
||||||
p.prev_op = Some(self.operator.into());
|
p.prev_op = Some(self.operator.into());
|
||||||
p.prev_op_end = p.code().len();
|
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);
|
self.argument.print_expr(p, Precedence::Exponentiation, ctx);
|
||||||
|
if is_delete_infinity{
|
||||||
|
p.print_ascii_byte(b')');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@ fn expr() {
|
||||||
test_minify_same("return new.target;");
|
test_minify_same("return new.target;");
|
||||||
test_minify_same("throw await 1;");
|
test_minify_same("throw await 1;");
|
||||||
test_minify_same("await import(\"\");");
|
test_minify_same("await import(\"\");");
|
||||||
|
|
||||||
|
test("delete 2e308", "delete (0, Infinity);\n");
|
||||||
|
test_minify("delete 2e308", "delete (1/0);");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue