Commit graph

177 commits

Author SHA1 Message Date
Boshen
4d8a08d2ac feat(minifier): improve constant evaluation (#8252) 2025-01-05 12:41:57 +00:00
Boshen
2f52f333fa feat(minifier): minsize !!!foo ? bar : baz -> foo ? baz : bar (#8244) 2025-01-04 09:10:22 +00:00
Boshen
ce2b5a994b chore(minifier): disable RemoveUnusedCode (#8243)
A lot of edge cases fail in test262 and monitor-oxc.
2025-01-04 08:49:20 +00:00
Boshen
ad9a0a9c4a feat(mininifier): minimize variants of a instanceof b == true (#8241) 2025-01-04 06:04:52 +00:00
Boshen
ccdc039f54 feat(minifier): always put literals on the rhs of equal op 1==x => x==1 (#8240) 2025-01-04 04:07:54 +00:00
Boshen
bf0fbcea6e refactor(minifier): improve constant fold numbers (#8239)
Ported esbuild's implementation
2025-01-04 03:30:20 +00:00
Cameron
39353b22e9
feat(minifier): improve minimizing conditionals (#8238) 2025-01-04 08:36:54 +08:00
camc314
c90fc16bba feat(minifier): restore conditional minification and fix edge case (#8235)
This restore's the changes made in #8233, but fixing the edge cases.

If the conditional expression is not a child of an `IfStatementTest`, `WhileStatementTest`, `DoWhileStatementText` or `ExpressionStatementExpression`, we must coerce the test to a boolean.
2025-01-03 14:20:42 +00:00
Boshen
6c8ee9fdef feat(minifier): remove last redundant return statement (#8234) 2025-01-03 12:24:57 +00:00
Boshen
a698deff51 fix(minifier): fix incorrect return value for (x ? true : y) (#8233)
Need to check if the return value is used or not:

```
function foo() {
    return foo ? true : bar; // no transformed
}

foo ? true : bar; // transformed to `foo || bar;`
```
2025-01-03 11:58:28 +00:00
Boshen
51f47926ef feat(minifier): minimize foo ? foo : bar and foo ? bar : foo (#8229) 2025-01-03 10:55:59 +00:00
Boshen
6e2ec17d51 feat(minifier): statement fusion switch cases; improved minimize exit poitns (#8228) 2025-01-03 10:07:04 +00:00
Boshen
574a2428fd feat(minifier): minimize all variants of typeof x == 'undefined' (#8227) 2025-01-03 07:05:55 +00:00
Boshen
2041477f51 feat(minifier): fold if(x)return;y -> if(!x)y (#8226) 2025-01-03 05:24:53 +00:00
Boshen
9c1afa4729 feat(minifier): optional catch binding when catch param is unused (#8221) 2025-01-02 13:20:49 +00:00
Boshen
2786dea164 feat(minifier): add RemoveUnusedCode (#8210) 2025-01-02 12:50:21 +00:00
Cameron
cd274eeb02
feat(minifier): minimize logical exprs (#8209) 2025-01-02 18:32:20 +08:00
Boshen
05be1fc639 fix(minifier): remove incorrect fold Expression::AssignmentExpression (#8211) 2025-01-01 05:44:01 +00:00
camc314
4ae15df042 feat(minifier): imprve more conditional expr minification with boolean lit (#8208) 2025-01-01 02:31:18 +00:00
camc314
3202b4fed0 feat(minifier): imprve conditional expr minification with boolean lit (#8207) 2025-01-01 02:31:18 +00:00
camc314
3b4501183c feat(minifier): handle conditional expr with boolean lit (#8206) 2025-01-01 02:31:17 +00:00
camc314
4c2059af29 feat(minifier): reverse negated conditional exprs (#8205) 2025-01-01 02:31:17 +00:00
Cameron
bf266e13b0
feat(minifier): try collapse conditional to logical or expr (#8197) 2024-12-31 15:59:08 +08:00
Boshen
06e1780b8c feat(minifier): improve StatementFusion (#8194) 2024-12-31 01:13:24 +00:00
Boshen
42e211ad6b feat(minifier): only constant fold numbers when result is smaller (#8092) 2024-12-31 00:56:51 +00:00
翠 / green
cef8eb8077
feat(minifier): change foo?.['bar'] to foo?.bar (#8176)
ChainExpression's `expression` field is `ChainElement` and not
`Expression` so the previous code did not run for optional chainings.
2024-12-30 16:47:56 +08:00
Boshen
cfb51f2551 refactor(minifier): fuse ast passes (#8184) 2024-12-29 14:57:20 +00:00
Boshen
8149e34bf0 feat(minifier): optional catch binding when es target >= es2019 (#8180) 2024-12-29 12:27:33 +00:00
Boshen
ad146bbb90 feat(codegen): print real newline when \n is inside template literals (#8178) 2024-12-29 12:20:47 +00:00
sapphi-red
75d5f17dbd
fix(minifier): minify string PropertyKey (#8177)
#8169 added `if self.in_fixed_loop` in `try_compress_property_key`. Because `exit_property_key` was not called for `PeepholeOptimizations`, `try_compress_property_key` was never called.

refs #8147
2024-12-29 07:49:42 +00:00
sapphi-red
fc43ec530e
feat(minifier): fold string.length / array.length (#8172) 2024-12-29 07:14:13 +00:00
Boshen
29dc0dc070 feat(minifier): change foo['bar'] -> foo.bar (#8169) 2024-12-29 04:09:42 +00:00
翠 / green
3c5718d68b
feat(minifier): fold typeof foo == undefined into foo == undefined when possible (#8160) 2024-12-29 11:49:57 +08:00
翠 / green
9d62284202
chore(tasks): print diff for minify idempotency assertion (#8161)
Made the assertion error output more easier to understand.

Example output:

![image](https://github.com/user-attachments/assets/445910fb-b389-4884-b4c5-70a095bc523f)

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-29 00:55:45 +08:00
翠 / green
f3a36e1dbf
feat(minifier): fold typeof foo != "undefined" into typeof foo < "u" (#8159) 2024-12-29 00:50:56 +08:00
Boshen
37c9959611 feat(minifier): normalize Infinity into f64::Infinity (#8148) 2024-12-28 06:05:04 +00:00
Boshen
8fb71f518f feat(minifier): minify string PropertyKey (#8147) 2024-12-27 15:09:41 +00:00
Boshen
2b2a37347c feat(minifier): minimize a + 'b' + 'c' -> a + 'bc' (#8137) 2024-12-27 05:46:51 +00:00
Boshen
213364a400 feat(minifier): minimize if (x) if (y) z -> if (x && y) z (#8136) 2024-12-27 02:44:47 +00:00
Boshen
6b51e6dff1 feat(minifier): minimize if(foo) bar else baz -> foo ? bar : baz (#8133) 2024-12-26 16:21:34 +00:00
Boshen
f615bfa773 feat(minifier): minimize if (x) return; return 1 -> return x ? void 0 : 1 (#8130) 2024-12-26 15:36:25 +00:00
Yuichiro Yamashita
e676fdfd83
chore(tasks): use assert_eq! instead of assert! (tasks/minsize/src/lib.rs) (#8129)
related to https://github.com/oxc-project/oxc/pull/8124
2024-12-26 13:54:05 +00:00
Boshen
f0b1ee5a06 feat(minifier): minimize if(!x) foo() -> x || foo() (#8122) 2024-12-26 09:42:34 +00:00
Boshen
f8200a8882 feat(minifier): minimize if(foo) bar -> foo && bar (#8121) 2024-12-26 09:01:38 +00:00
Boshen
72d996709e feat(minifier): add Normalize ast pass (#8120) 2024-12-26 07:02:45 +00:00
Boshen
fef0b25fd3 feat(minifier): collapse var into for loop initializer (#8119)
`var a = 0; for(;a<0;a++) {}` => `for(var a = 0;a<0;a++) {}`
2024-12-26 05:22:02 +00:00
Boshen
2331ea85d9 feat(minifier): typeof foo === 'number' => typeof foo == 'number' (#8112) 2024-12-25 14:52:58 +00:00
Boshen
e594c3988d refactor(minifier): clean up peephole_substitute_alternate_syntax.rs (#8111) 2024-12-25 13:54:51 +00:00
Boshen
47276679f5 feat(codegen): minify arrow expr (x) => y -> x => y (#8078) 2024-12-24 14:25:01 +00:00
Boshen
0562830549 feat(codegen): minify string with backtick when needed (#8095) 2024-12-24 13:39:31 +00:00