diff --git a/crates/oxc_ecmascript/src/to_int_32.rs b/crates/oxc_ecmascript/src/to_int_32.rs index d0a69a48cf16d..018715b7736dd 100644 --- a/crates/oxc_ecmascript/src/to_int_32.rs +++ b/crates/oxc_ecmascript/src/to_int_32.rs @@ -56,6 +56,10 @@ impl ToInt32 for f64 { let number = *self; + if !number.is_finite() || number == 0.0 { // NOTE: this matches with negative zero + return 0; + } + if number.is_finite() && number <= f64::from(i32::MAX) && number >= f64::from(i32::MIN) { let i = number as i32; if f64::from(i) == number { diff --git a/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs b/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs index dbff2b5eb207b..941aa7fd28598 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs @@ -1505,9 +1505,9 @@ mod test { #[test] fn test_fold_left_child_op() { - test_same("x & infinity & 2"); // FIXME: want x & 0 - test_same("x - infinity - 2"); // FIXME: want "x-infinity" - test_same("x - 1 + infinity"); + test("x & Infinity & 2", "x & 0"); + test_same("x - Infinity - 2"); // FIXME: want "x-Infinity" + test_same("x - 1 + Infinity"); test_same("x - 2 + 1"); test_same("x - 2 + 3"); test_same("1 + x - 2 + 1");