Skip to content

Commit

Permalink
feat(minifier): evaluate bigint in fold constant (#6178)
Browse files Browse the repository at this point in the history
relates #6161
  • Loading branch information
Boshen committed Sep 30, 2024
1 parent f2ac584 commit 3b79e1b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
12 changes: 4 additions & 8 deletions crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,6 @@ mod test {
}

#[test]
#[ignore]
fn test_string_string_comparison() {
test("'a' < 'b'", "true");
test("'a' <= 'b'", "true");
Expand Down Expand Up @@ -1123,7 +1122,6 @@ mod test {
}

#[test]
#[ignore]
fn test_bigint_number_comparison() {
test("1n < 2", "true");
test("1n > 2", "false");
Expand Down Expand Up @@ -1168,7 +1166,6 @@ mod test {
}

#[test]
#[ignore]
fn test_bigint_string_comparison() {
test("1n < '2'", "true");
test("2n > '1'", "true");
Expand All @@ -1181,7 +1178,6 @@ mod test {
}

#[test]
#[ignore]
fn test_string_bigint_comparison() {
test("'1' < 2n", "true");
test("'2' > 1n", "true");
Expand All @@ -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");
Expand Down
8 changes: 5 additions & 3 deletions crates/oxc_minifier/src/node_util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3b79e1b

Please sign in to comment.