Skip to content

Commit b1d0186

Browse files
committed
fix(minifier): do not fold !!void b (#8533)
1 parent f5c5c3c commit b1d0186

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

crates/oxc_ecmascript/src/constant_evaluation/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,10 @@ pub trait ConstantEvaluation<'a> {
384384
}
385385
UnaryOperator::Void => (expr.argument.is_literal() || !expr.may_have_side_effects())
386386
.then_some(ConstantValue::Undefined),
387-
UnaryOperator::LogicalNot => {
388-
self.get_boolean_value(&expr.argument).map(|b| !b).map(ConstantValue::Boolean)
389-
}
387+
UnaryOperator::LogicalNot => self
388+
.get_side_free_boolean_value(&expr.argument)
389+
.map(|b| !b)
390+
.map(ConstantValue::Boolean),
390391
UnaryOperator::UnaryPlus => {
391392
self.eval_to_number(&expr.argument).map(ConstantValue::Number)
392393
}

crates/oxc_minifier/src/ast_passes/peephole_fold_constants.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,7 @@ mod test {
11131113
test("a=!10", "a=false");
11141114
test("a=!false", "a=true");
11151115
test_same("a=!foo()");
1116+
test_same("a = !!void b");
11161117

11171118
test("a=-0", "a=-0");
11181119
test("a=-(0)", "a=-0");

tasks/minsize/minsize.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Original | minified | minified | gzip | gzip | Fixture
2121

2222
3.20 MB | 1.01 MB | 1.01 MB | 332.02 kB | 331.56 kB | echarts.js
2323

24-
6.69 MB | 2.32 MB | 2.31 MB | 492.64 kB | 488.28 kB | antd.js
24+
6.69 MB | 2.32 MB | 2.31 MB | 492.65 kB | 488.28 kB | antd.js
2525

2626
10.95 MB | 3.49 MB | 3.49 MB | 907.34 kB | 915.50 kB | typescript.js
2727

0 commit comments

Comments
 (0)