Commit graph

153 commits

Author SHA1 Message Date
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
Boshen
86256ea238 feat(minifier): constant fold typeof (#5666)
closes #5628
2024-09-10 04:43:00 +00:00
Boshen
4a8aec1605 feat(span)!: change SourceType::js to SourceType::cjs and SourceType::mjs (#5606) 2024-09-08 14:11:02 +00:00
Boshen
b06052501a refactor(semantic)!: remove source_type argument from SemanticBuilder::new (#5553)
Realized we can get the source type from the AST.

The next PR will introduce `unambiguous` to `SourceType` and directly set `Program::source_type` to either `script` or `module`.
2024-09-06 16:40:10 +00:00
Boshen
ba4b68cf63 feat(minifier): remove parenthesized expression for dce (#5439)
relates #5436
2024-09-04 12:58:39 +00:00
IWANABETHATGUY
2b21be31ff feat(oxc_minifier): define plugin with postfix wildcard (#4979)
1. support `import.meta.env.*` in `ReplaceGlobalDefine`
2024-08-21 13:27:09 +00:00
Boshen
b4407c4e9a
refactor(oxc,mangler): oxc crate add mangler; mangler use options API 2024-08-20 22:58:59 +08:00
Boshen
ce4d4698b4 feat(codegen)!: remove const generic MINIFY (#5001)
This is a premature optimization, makes the code complicated, and bloats the final binary size.

The minify option is moved to `CodegenOptions`
2024-08-20 08:13:27 +00:00
Boshen
46cb1c1b7b fix(minifier): handle Object.definedPropert(exports for @babel/types/lib/index.js (#4933)
Discoverd in `monitor-oxc`

```javascript
Object.keys(_index6).forEach(function(key) {
	if (key === "default" || key === "__esModule") return;
	if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
	if (key in exports && exports[key] === _index6[key]) return;
	Object.defineProperty(exports, key, {
		enumerable: true,
		get: function() {
			return _index6[key];
		}
	});
});
```

🙃
2024-08-16 06:48:15 +00:00
Boshen
81fd6379e8 fix(minifier): do not fold 0 && (module.exports = {}) for cjs-module-lexer (#4878) 2024-08-13 12:54:59 +00:00
Boshen
879a271d47 fix(minifier): do not join require calls for cjs-module-lexer (#4875) 2024-08-13 12:21:37 +00:00
Boshen
fae8a62a62 fix(minifier): temporarily bail constant folding for tagged template (#4842)
closes #4341
2024-08-12 07:38:25 +00:00
Boshen
c51929558d feat(minifier): add InjectGlobalVariables plugin (@rollup/plugin-inject) (#4759) 2024-08-10 01:12:31 +00:00
Boshen
fbfd852cf8 refactor(minifier): add NodeUtil trait for accessing symbols on ast nodes (#4734) 2024-08-08 02:48:25 +00:00
Boshen
17602db6de
refactor(minifier): move tests and files around 2024-08-07 20:01:55 +08:00
Boshen
3289477197 refactor(minifier): clean up tests (#4724) 2024-08-07 06:29:41 +00:00