From 3b79e1bc9d79fec368df5074ef1255f866d57d36 Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Mon, 30 Sep 2024 12:53:42 +0000 Subject: [PATCH] feat(minifier): evaluate bigint in fold constant (#6178) relates #6161 --- .../src/ast_passes/peephole_fold_constants.rs | 12 ++++-------- crates/oxc_minifier/src/node_util/mod.rs | 8 +++++--- 2 files changed, 9 insertions(+), 11 deletions(-) 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 0d84b82ce..b48b91fbc 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs @@ -1057,7 +1057,6 @@ mod test { } #[test] - #[ignore] fn test_string_string_comparison() { test("'a' < 'b'", "true"); test("'a' <= 'b'", "true"); @@ -1123,7 +1122,6 @@ mod test { } #[test] - #[ignore] fn test_bigint_number_comparison() { test("1n < 2", "true"); test("1n > 2", "false"); @@ -1168,7 +1166,6 @@ mod test { } #[test] - #[ignore] fn test_bigint_string_comparison() { test("1n < '2'", "true"); test("2n > '1'", "true"); @@ -1181,7 +1178,6 @@ mod test { } #[test] - #[ignore] fn test_string_bigint_comparison() { test("'1' < 2n", "true"); test("'2' > 1n", "true"); @@ -1199,10 +1195,10 @@ mod test { test("NaN <= 1", "false"); test("NaN > 1", "false"); test("NaN >= 1", "false"); - // test("NaN < 1n", "false"); - // test("NaN <= 1n", "false"); - // test("NaN > 1n", "false"); - // test("NaN >= 1n", "false"); + test("NaN < 1n", "false"); + test("NaN <= 1n", "false"); + test("NaN > 1n", "false"); + test("NaN >= 1n", "false"); test("NaN < NaN", "false"); test("NaN >= NaN", "false"); diff --git a/crates/oxc_minifier/src/node_util/mod.rs b/crates/oxc_minifier/src/node_util/mod.rs index 8c682de72..3f00c72aa 100644 --- a/crates/oxc_minifier/src/node_util/mod.rs +++ b/crates/oxc_minifier/src/node_util/mod.rs @@ -272,9 +272,11 @@ pub trait NodeUtil { None } } - Expression::BigIntLiteral(_bigint_literal) => { - // TODO: evaluate the bigint value - None + Expression::BigIntLiteral(bigint_literal) => { + let value = + self.get_string_bigint_value(bigint_literal.raw.as_str().trim_end_matches('n')); + debug_assert!(value.is_some(), "Failed to parse {}", bigint_literal.raw); + value } Expression::BooleanLiteral(bool_literal) => { if bool_literal.value {