mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
fix(minifier): (-Infinity).toString() -> '-Infinity' (#8535)
This commit is contained in:
parent
e0f5d6c7bb
commit
946ad7690b
2 changed files with 11 additions and 18 deletions
|
|
@ -294,19 +294,10 @@ impl<'a> PeepholeReplaceKnownMethods {
|
|||
if radix == 0 {
|
||||
return None;
|
||||
}
|
||||
if lit.value.is_nan() {
|
||||
return Some(ctx.ast.expression_string_literal(ce.span, "NaN", None));
|
||||
}
|
||||
if lit.value.is_infinite() {
|
||||
return Some(ctx.ast.expression_string_literal(ce.span, "Infinity", None));
|
||||
}
|
||||
if radix == 10 {
|
||||
use oxc_syntax::number::ToJsString;
|
||||
return Some(ctx.ast.expression_string_literal(
|
||||
ce.span,
|
||||
lit.value.to_js_string(),
|
||||
None,
|
||||
));
|
||||
let s = lit.value.to_js_string();
|
||||
return Some(ctx.ast.expression_string_literal(ce.span, s, None));
|
||||
}
|
||||
// Only convert integers for other radix values.
|
||||
let value = lit.value;
|
||||
|
|
@ -1244,12 +1235,5 @@ mod test {
|
|||
test("123 .toString(b)", "123 .toString(b)");
|
||||
test("1e99.toString(b)", "1e99.toString(b)");
|
||||
test("/./.toString(b)", "/./.toString(b)");
|
||||
|
||||
// Will get constant folded into positive values
|
||||
test_same("(-0).toString()");
|
||||
test_same("(-123).toString()");
|
||||
test_same("(-Infinity).toString()");
|
||||
test_same("(-1000000).toString(36)");
|
||||
test_same("(-0).toString(36)");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,6 +77,15 @@ fn integration() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fold() {
|
||||
test("var x = (-0).toString()", "var x = '0'");
|
||||
test("var x = (-0).toString(36)", "var x = '0'");
|
||||
test("var x = (-123).toString()", "var x = '-123'");
|
||||
test("var x = (-Infinity).toString()", "var x = '-Infinity'");
|
||||
test("var x = (-1000000).toString(36)", "var x = (-1e6).toString(36)");
|
||||
}
|
||||
|
||||
#[test] // https://github.com/oxc-project/oxc/issues/4341
|
||||
fn tagged_template() {
|
||||
test_same("(1, o.f)()");
|
||||
|
|
|
|||
Loading…
Reference in a new issue