mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 04:08:41 +00:00
feat(minifier): minimize ~undefined, ~null, ~true, ~false (#8247)
This commit is contained in:
parent
f73dc9ea9b
commit
bd8d677352
2 changed files with 12 additions and 0 deletions
|
|
@ -440,6 +440,10 @@ pub trait ConstantEvaluation<'a> {
|
|||
.map(|v| !v.to_int_32())
|
||||
.map(|v| v as f64)
|
||||
.map(ConstantValue::Number),
|
||||
ValueType::Undefined | ValueType::Null => Some(ConstantValue::Number(-1.0)),
|
||||
ValueType::Boolean => self
|
||||
.get_side_free_boolean_value(&expr.argument)
|
||||
.map(|v| ConstantValue::Number(if v { -2.0 } else { -1.0 })),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1447,6 +1447,14 @@ mod test {
|
|||
test("y | 3 & 7", "y | 3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fold_bitwise_not() {
|
||||
test("~undefined", "-1");
|
||||
test("~null", "-1");
|
||||
test("~false", "-1");
|
||||
test("~true", "-2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_fold_bit_shifts() {
|
||||
test("x = 1 << 0", "x=1");
|
||||
|
|
|
|||
Loading…
Reference in a new issue