Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(es/codegen): Fix codegen of large numeric literals #9226

Merged
merged 13 commits into from
Jul 15, 2024
2 changes: 1 addition & 1 deletion crates/swc_ecma_codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ where
self.emit_leading_comments_of_span(num.span(), false)?;

// Handle infinity
if num.value.is_infinite() {
if num.value.is_infinite() && num.raw.is_none() {
if num.value.is_sign_negative() {
self.wr.write_str_lit(num.span, "-")?;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,12 @@ fn test_fold_arithmetic_infinity() {
fold("x = Infinity ** -2", "x = 0");
}

#[test]
fn test_fold_arithmetic_large_number() {
fold("x = -1e999", "x = -1e999");
fold("x = 1e999", "x = 1e999");
}

#[test]
fn test_fold_arithmetic_string_comp() {
fold("x = 10 - 20", "x = -10");
Expand Down
Loading