From f87da160dff7147d722a5dea1759153fdc1a764c Mon Sep 17 00:00:00 2001 From: Boshen <1430279+Boshen@users.noreply.github.com> Date: Mon, 6 Jan 2025 10:08:57 +0000 Subject: [PATCH] fix(minifier): do not fold literals in `-0 != +0` (#8278) --- .../src/ast_passes/peephole_minimize_conditions.rs | 2 ++ tasks/minsize/minsize.snap | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/crates/oxc_minifier/src/ast_passes/peephole_minimize_conditions.rs b/crates/oxc_minifier/src/ast_passes/peephole_minimize_conditions.rs index 18efdebb394db..28b8f977e4003 100644 --- a/crates/oxc_minifier/src/ast_passes/peephole_minimize_conditions.rs +++ b/crates/oxc_minifier/src/ast_passes/peephole_minimize_conditions.rs @@ -542,6 +542,7 @@ impl<'a> PeepholeMinimizeConditions { } Expression::NumericLiteral(lit) if lit.value == 0.0 + && !e.left.is_literal() // let constant folding do the work && ValueType::from(&e.left).is_number() && Self::is_in_boolean_context(ctx) => { @@ -1709,6 +1710,7 @@ mod test { test("if(x >> y === 0){}", "if(!(x >> y)){}"); test("if(x >> y != 0){}", "if(x >> y){}"); test("if(x >> y !== 0){}", "if(x >> y){}"); + test("if((-0 != +0) !== false){}", "if (-0 != +0) {}"); test_same("foo(x >> y == 0)"); } diff --git a/tasks/minsize/minsize.snap b/tasks/minsize/minsize.snap index 96a38dffb5b35..e3f7ed6f9d0e5 100644 --- a/tasks/minsize/minsize.snap +++ b/tasks/minsize/minsize.snap @@ -11,17 +11,17 @@ Original | minified | minified | gzip | gzip | Fixture 544.10 kB | 71.80 kB | 72.48 kB | 26.18 kB | 26.20 kB | lodash.js -555.77 kB | 273.17 kB | 270.13 kB | 90.96 kB | 90.80 kB | d3.js +555.77 kB | 273.15 kB | 270.13 kB | 90.95 kB | 90.80 kB | d3.js -1.01 MB | 460.34 kB | 458.89 kB | 126.85 kB | 126.71 kB | bundle.min.js +1.01 MB | 460.33 kB | 458.89 kB | 126.85 kB | 126.71 kB | bundle.min.js -1.25 MB | 652.70 kB | 646.76 kB | 163.54 kB | 163.73 kB | three.js +1.25 MB | 652.69 kB | 646.76 kB | 163.54 kB | 163.73 kB | three.js -2.14 MB | 726.18 kB | 724.14 kB | 180.17 kB | 181.07 kB | victory.js +2.14 MB | 726.17 kB | 724.14 kB | 180.17 kB | 181.07 kB | victory.js 3.20 MB | 1.01 MB | 1.01 MB | 331.88 kB | 331.56 kB | echarts.js 6.69 MB | 2.32 MB | 2.31 MB | 492.84 kB | 488.28 kB | antd.js -10.95 MB | 3.50 MB | 3.49 MB | 909.21 kB | 915.50 kB | typescript.js +10.95 MB | 3.50 MB | 3.49 MB | 909.14 kB | 915.50 kB | typescript.js