Boshen
9953ac7cad
perf(minifier): add LatePeepholeOptimizations ( #8651 )
...
This PR adds a `LatePeepholeOptimizations` pass for minifications that
don't interact with the fixed point loop.
While working on this I found a couple of cases where the previous fixed
point loop is not idempotent.
2025-01-22 16:19:06 +08:00
Boshen
5b3c412e26
perf(minifier): only run optimizations on local changes ( #8644 )
...
Previously all code are ran in a fixed point loop when ast changes.
This PR changes running code when a function changes its enclosing ast only.
2025-01-21 23:55:54 +08:00
Boshen
6f95cd599a
refactor(minifier): remove all the unnecessary fake ast passes ( #8618 )
...
This also removes handling of making cjs-module-lexer to work.
2025-01-20 22:05:51 +08:00
Boshen
d9f5e7fd52
test(minifier): enable passed esbuild tests
2025-01-20 16:39:39 +08:00
Boshen
7b219a930f
fix(minifier): fix dce shadowed undefined ( #8582 )
2025-01-18 09:04:28 +00:00
camc314
4d4e805691
feat(minifier): collapse if stmt with empty consequent ( #8577 )
2025-01-18 03:51:40 +00:00
Boshen
946ad7690b
fix(minifier): (-Infinity).toString() -> '-Infinity' ( #8535 )
2025-01-16 06:47:40 +00:00
Boshen
e0f5d6c7bb
test(minifier): update esbuild test
2025-01-16 14:46:12 +08:00
Boshen
629c41713b
test(minifier): port esbuild minification tests ( #8497 )
2025-01-15 06:29:01 +00:00
Boshen
4c6675c46d
fix(minifier): do not convert while to fors in DCE ( #8484 )
2025-01-14 10:01:35 +00:00
Boshen
1d6e84dd33
fix(minifier): fix incorrect null.toString() and 1n.toString() ( #8464 )
2025-01-13 15:08:49 +00:00
Boshen
3c9354983d
fix(minifier): dce if statement should keep side effects and vars ( #8433 )
...
closes #7209
Note: Current output is sub-optimal.
2025-01-11 14:02:12 +00:00
camc314
52f88c0e9c
fix(minifier): rotate associative operators to make it more idempotent ( #8424 )
...
another **massive** pain to debug
~~https://github.com/oxc-project/monitor-oxc/actions/runs/12717213600~~
https://github.com/oxc-project/monitor-oxc/actions/runs/12717978983/job/35455601146
2025-01-11 01:12:10 +00:00
camc314
a80460c6fe
fix(minifier): correctly set self.changed when minimizing if stmts ( #8420 )
...
Before:
```
==== Input ====
require('./index.js')(function (e, os) {
if (e) return console.log(e)
return console.log(JSON.stringify(os))
})
==== First Minification
require("./index.js")(function(e, os) {
return console.log(e ? e : JSON.stringify(os));
});
==== Second Minification ====
require("./index.js")(function(e, os) {
return console.log(e || JSON.stringify(os));
});
same = false
```
After:
```
==== Input ====
require('./index.js')(function (e, os) {
if (e) return console.log(e)
return console.log(JSON.stringify(os))
})
==== First Minification ====
require("./index.js")(function(e, os) {
return console.log(e || JSON.stringify(os));
});
==== Second Minification ====
require("./index.js")(function(e, os) {
return console.log(e || JSON.stringify(os));
});
same = true
```
2025-01-11 01:12:09 +00:00
Boshen
357b61d179
fix(minifier): do not minify Object.defineProperty in sequence expressions ( #8416 )
2025-01-10 12:04:39 +00:00
Boshen
5b5b8443f4
feat(minifier): fold ambiguous if else ( #8415 )
2025-01-10 19:51:31 +08:00
Boshen
fb2acd87b3
refactor(minifier): change minimize conditionals into a loop ( #8413 )
2025-01-10 09:49:09 +00:00
翠 / green
5c63414c23
fix(mangler): keep exported symbols for top_level: true ( #7927 )
...
~~I'm not going to work on a fix for a while so feel free to fix it if
anyone wants to work on it.~~
Exported symbols are now not mangled.
2025-01-10 15:14:30 +08:00
Boshen
09f0f483f6
refactor(minifier): remove the buggy minimize_exit_points implementation ( #8349 )
2025-01-09 02:49:32 +00:00
Boshen
2041477f51
feat(minifier): fold if(x)return;y -> if(!x)y ( #8226 )
2025-01-03 05:24:53 +00:00
camc314
4c2059af29
feat(minifier): reverse negated conditional exprs ( #8205 )
2025-01-01 02:31:17 +00:00
Boshen
1314c9763b
refactor(minifier): expose dce as an API instead of an option ( #7957 )
2024-12-17 04:47:13 +00:00
翠 / green
db9e93b554
feat(mangler): mangle top level variables ( #7907 )
...
Adds `top_level` option which is similar to [terser's `toplevel`
option](https://terser.org/docs/cli-usage/#cli-mangle-options ).
---------
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
2024-12-15 21:31:41 +08:00
overlookmotel
3858221f45
refactor(global): sort imports ( #7883 )
...
Pure refactor. Re-order imports for clarity:
1. `std`
2. External crates
3. `oxc_*` crates
4. Current crate `use crate::...`
5. Super `use super::...`
6. Local modules
This order is from "furthest away" to "closest". This makes it clearer to see what is coming from where.
`cargo +nightly fmt` (#7877 ) did a lot of the work, but unfortunately `rustfmt` does not have an option to (a) put workspace crates in a separate block from external crates and (b) move `mod` statements to after `use` statements.
2024-12-14 15:07:21 +00:00
Boshen
7fb9d47460
style(rust): cargo +nightly fmt ( #7877 )
2024-12-14 06:03:31 +00:00
Song Gao
ebc80f6749
refactor(ast)!: change 'raw' from &str to Option<Atom> ( #7547 )
...
Fix #7254
Changed all "raw" properties of literal types (if they have this property) to `Option<Atom>`.
---------
Co-authored-by: overlookmotel <theoverlookmotel@gmail.com>
2024-12-05 00:34:45 +00:00
Boshen
9d6e14bb67
test(ecmascript): move tests to oxc_minifier due to cyclic dependency with oxc_parser ( #7542 )
2024-11-29 09:18:45 +00:00
Boshen
62a8c5eb59
chore(minifier): temporary remove try_fold_if_block_one and try_fold_if_one_child ( #7536 )
...
They are not idempotent.
2024-11-29 05:05:07 +00:00
Ethan Goh
ac0d25c426
feat(minifier): minify one child if statement expression ( #7230 )
2024-11-26 22:48:27 +08:00
Song Gao
cf3415b0e4
chore(doc): replace main/master to tag/commit to make the url always accessible ( #7298 )
2024-11-16 21:00:30 +08:00
Boshen
435a89c6e4
refactor(oxc): remove useless allocator.alloc(program) calls ( #6571 )
2024-10-15 02:21:20 +00:00
Boshen
3556062213
feat(ecmascript): add ConstantEvaluation ( #6549 )
2024-10-14 07:53:44 +00:00
Boshen
6f2253886d
feat(ecmascript): add ToBoolean, ToNumber, ToString ( #6502 )
2024-10-13 11:03:08 +00:00
7086cmd
702c049ebc
refactor(minifier): move compress block to dce ( #6468 )
2024-10-12 07:59:44 +00:00
7086cmd
3677ef81e9
feat(minifier): dce ExpressionStatements with no side effect ( #6457 )
...
Not sure about the performance. Just have a try.
2024-10-11 13:40:44 +00:00
Boshen
020bb80b65
refactor(codegen)!: change to CodegenReturn::code and CodegenReturn::map ( #6310 )
2024-10-06 05:05:47 +00:00
Boshen
82ab68984e
feat(transformer,minifier)!: move define and inject plugin from minifier to transformer ( #6199 )
2024-10-01 03:59:24 +00:00
Boshen
362c427b94
fix(mangler,codegen): do not mangle top level symbols ( #5965 )
2024-09-22 13:45:54 +00:00
Boshen
943bd76679
refactor(minifier): move tests to their src files ( #5912 )
2024-09-20 07:56:37 +00:00
Boshen
cbaeea6d02
refactor(minifier): clean up some tests ( #5910 )
2024-09-20 05:55:05 +00:00
Boshen
144611ef49
refactor(minifier): align ast pass names with closure compiler ( #5908 )
2024-09-20 05:20:07 +00:00
Boshen
e968e9ffd0
feat(minifier): constant fold nullish coalescing operator ( #5761 )
2024-09-13 13:25:58 +00:00
Boshen
8ff013ada1
fix(minifier): handle dce CallExpression::callee ( #5752 )
2024-09-13 10:46:14 +00:00
Boshen
2890c98d62
refactor(minifier): add tests for remove_syntax ( #5749 )
2024-09-13 08:59:45 +00:00
Boshen
6bc13f6cd4
feat(minifier): add MinimizeConditions pass ( #5747 )
...
I expect small performance regression.
But managed to improve the following case from react.developmement.js
```
oxc main ❯ diff before.js after.js
670c670
< if (!(dispatcher !== null)) throw Error("Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.");
---
> if (dispatcher === null) throw Error("Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.");
```
2024-09-13 08:31:45 +00:00
Boshen
746f7b3a02
refactor(minifier): align code with closure compiler ( #5717 )
...
also fixes #4341
2024-09-12 04:18:41 +00:00
Boshen
21e2df57a0
refactor(minifier): replace VisitMut with Traverse for inject and define plugins ( #5705 )
...
closes #5704
2024-09-11 16:13:10 +00:00
Boshen
b8f8dd6612
fix(minifier/replace_global_defines): do not replace shadowed identifiers ( #5691 )
2024-09-11 07:17:17 +00:00
Boshen
68c3cf544f
feat(minifier): fold void 1 -> void 0 ( #5670 )
2024-09-10 08:11:10 +00:00
Boshen
c6bbf94f4c
feat(minifier): constant fold unary expression ( #5669 )
2024-09-10 07:18:54 +00:00