fix(codegen): use ryu-js for f64 to string

This commit is contained in:
Boshen 2024-07-14 13:23:30 +08:00
parent 06197b8be4
commit 084ab7602d
No known key found for this signature in database
GPG key ID: 67715A371E534061
2 changed files with 4 additions and 2 deletions

View file

@ -23,7 +23,7 @@ doctest = false
oxc_ast = { workspace = true }
oxc_span = { workspace = true }
oxc_allocator = { workspace = true }
oxc_syntax = { workspace = true }
oxc_syntax = { workspace = true, features = ["to_js_string"] }
oxc_sourcemap = { workspace = true }
oxc_mangler = { workspace = true }

View file

@ -1184,8 +1184,10 @@ impl<'a, const MINIFY: bool> Gen<MINIFY> for NumericLiteral<'a> {
}
// TODO: refactor this with less allocations
// <https://github.com/evanw/esbuild/blob/360d47230813e67d0312ad754cad2b6ee09b151b/internal/js_printer/js_printer.go#L3472>
fn print_non_negative_float<const MINIFY: bool>(value: f64, _p: &Codegen<{ MINIFY }>) -> String {
let mut result = value.to_string();
use oxc_syntax::number::ToJsString;
let mut result = value.to_js_string();
let chars = result.as_bytes();
let len = chars.len();
let dot = chars.iter().position(|&c| c == b'.');