Skip to content

Commit

Permalink
fix(minifier): do not fold literals in -0 != +0 (#8278)
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Jan 6, 2025
1 parent ecc789f commit f87da16
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
{
Expand Down Expand Up @@ -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)");
}

Expand Down
10 changes: 5 additions & 5 deletions tasks/minsize/minsize.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f87da16

Please sign in to comment.