fix(minifier): do not fold !!void b (#8533)

This commit is contained in:
Boshen 2025-01-16 05:52:03 +00:00
parent f5c5c3c9f1
commit b1d018622b
3 changed files with 6 additions and 4 deletions

View file

@ -384,9 +384,10 @@ pub trait ConstantEvaluation<'a> {
}
UnaryOperator::Void => (expr.argument.is_literal() || !expr.may_have_side_effects())
.then_some(ConstantValue::Undefined),
UnaryOperator::LogicalNot => {
self.get_boolean_value(&expr.argument).map(|b| !b).map(ConstantValue::Boolean)
}
UnaryOperator::LogicalNot => self
.get_side_free_boolean_value(&expr.argument)
.map(|b| !b)
.map(ConstantValue::Boolean),
UnaryOperator::UnaryPlus => {
self.eval_to_number(&expr.argument).map(ConstantValue::Number)
}

View file

@ -1113,6 +1113,7 @@ mod test {
test("a=!10", "a=false");
test("a=!false", "a=true");
test_same("a=!foo()");
test_same("a = !!void b");
test("a=-0", "a=-0");
test("a=-(0)", "a=-0");

View file

@ -21,7 +21,7 @@ Original | minified | minified | gzip | gzip | Fixture
3.20 MB | 1.01 MB | 1.01 MB | 332.02 kB | 331.56 kB | echarts.js
6.69 MB | 2.32 MB | 2.31 MB | 492.64 kB | 488.28 kB | antd.js
6.69 MB | 2.32 MB | 2.31 MB | 492.65 kB | 488.28 kB | antd.js
10.95 MB | 3.49 MB | 3.49 MB | 907.34 kB | 915.50 kB | typescript.js