feat(minifier): fold bitwise binary expressions with negative BigInts (#9081)

This commit is contained in:
sapphi-red committed 2025-02-13 13:58:53 +00:00
1 parent 24830e6c2b
commit 237ffba815
2 files changed
+3 -4

No files matched your search

@@ -331,7 +331,7 @@ pub trait ConstantEvaluation<'a>: MayHaveSideEffects {
})
}
BinaryOperator::BitwiseAnd | BinaryOperator::BitwiseOR | BinaryOperator::BitwiseXOR => {
if left.is_big_int_literal() && right.is_big_int_literal() {
if ValueType::from(left).is_bigint() && ValueType::from(right).is_bigint() {
let left_val = self.get_side_free_bigint_value(left)?;
let right_val = self.get_side_free_bigint_value(right)?;
let result_val: BigInt = match operator {
@@ -1641,7 +1641,6 @@ mod test {
fold("+(void unknown())", "+void unknown()");
}
// TODO: All big ints are rare and difficult to handle.
mod bigint {
use super::{
fold, fold_same, MAX_SAFE_FLOAT, MAX_SAFE_INT, NEG_MAX_SAFE_FLOAT, NEG_MAX_SAFE_INT,
@@ -1666,8 +1665,8 @@ mod test {
fold("x = 3n ^ 1n", "x = 2n");
fold("x = 3n ^ 3n", "x = 0n");
// test("x = -1n & 0n", "x = 0n");
// test("x = 0n & -1n", "x = 0n");
fold("x = -1n & 0n", "x = 0n");
fold("x = 0n & -1n", "x = 0n");
fold("x = 1n & 4n", "x = 0n");
fold("x = 2n & 3n", "x = 2n");