Skip to content

Commit

Permalink
feat(minifier): NaN.toString(radix) is always NaN (#8727)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jan 26, 2025
1 parent cbe0e82 commit 2e9a560
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/oxc_minifier/src/peephole/replace_known_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ impl<'a> PeepholeOptimizations {
}
// Only convert integers for other radix values.
let value = lit.value;
if value.is_nan() {
return Some(ctx.ast.expression_string_literal(ce.span, "NaN", None));
}
if value >= 0.0 && value.fract() != 0.0 {
return None;
}
Expand Down Expand Up @@ -1422,6 +1425,7 @@ mod test {
test("x = 0 .toString()", "x = '0';");
test("x = 123 .toString()", "x = '123';");
test("x = NaN.toString()", "x = 'NaN';");
test("x = NaN.toString(2)", "x = 'NaN';");
test("x = Infinity.toString()", "x = 'Infinity';");
test("x = 1n.toString()", "x = '1'");
test_same("254n.toString(16);"); // unimplemented
Expand Down

0 comments on commit 2e9a560

Please sign in to comment.