Commit graph

46 commits

Author SHA1 Message Date
Daniel Bulant
6aa2ddeb85
refactor(codegen): accept SymbolTable instead of Mangler (#8829)
It seems to be that the easiest way to rename variables is to use
rename_symbol from SymbolTable and to let it be applied during codegen -
this is what Mangler does.

This PR changes Codegen to accept (any) SymbolTable instead of just
Mangler itself, and for Mangler build output to be a new SymbolTable,
after consuming itself (which makes it clear at the type level if a
Mangler has been built or not).

This also moves the few symbol table helper methods from Mangler to
SymbolTable itself, and adds an example of Mangler use to it's
documentation.

Codegen dependencies now include semantic (which was transient by
mangler before). It's dependency on Mangler could be removed, though
I've left it to allow easy linking of docs (with_symbol_table points
users to Mangler, hopefully helps with migration?)
2025-02-02 17:13:09 +08:00
Boshen
2a2a2eb5ea
chore(tasks/minsize): enable test coverage 2025-01-19 12:00:40 +08: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
2041477f51 feat(minifier): fold if(x)return;y -> if(!x)y (#8226) 2025-01-03 05:24:53 +00:00
Boshen
2786dea164 feat(minifier): add RemoveUnusedCode (#8210) 2025-01-02 12:50:21 +00:00
Boshen
29dc0dc070 feat(minifier): change foo['bar'] -> foo.bar (#8169) 2024-12-29 04:09:42 +00: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
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
e594c3988d refactor(minifier): clean up peephole_substitute_alternate_syntax.rs (#8111) 2024-12-25 13:54:51 +00:00
Boshen
23b563730f
feat(tasks/minsize): save minified file 2024-12-21 18:57:36 +08: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
3de4a43761 test(minifier): reformat minsize table (#7678)
Reformat the table which `minsize` task outputs. I always found the column headings confusing previously.
2024-12-05 12:16:29 +00:00
Boshen
c7f44c439d
chore(tasks/minsize): enable idempotency test 2024-10-26 10:35:01 +08:00
Boshen
741571f645 refactor(minifier): remove extra compress options (#6893)
Closure Compiler and ESBuild does not have these kind of granularity.
2024-10-26 01:30:13 +00:00
Boshen
435a89c6e4 refactor(oxc): remove useless allocator.alloc(program) calls (#6571) 2024-10-15 02:21:20 +00:00
Boshen
020bb80b65 refactor(codegen)!: change to CodegenReturn::code and CodegenReturn::map (#6310) 2024-10-06 05:05:47 +00:00
camchenry
02d5637dbc perf(ast-tools): use FxHashMap over std::collections::HashMap (#5997) 2024-09-23 18:28:54 +00: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
33e96e23e4 feat(tasks/minsize): include esbuild minified size (#4202) 2024-07-11 13:02:32 +00:00
Boshen
bb646f2bf9 feat(tasks/minsize): show target size for easier comparison (#4201) 2024-07-11 12:38:45 +00:00
Boshen
e3e663bae4 feat(mangler): initialize crate and integrate into minifier (#4197) 2024-07-11 10:35:13 +00:00
Boshen
ca0b4fa08a refactor(tasks): clean up test files and remove libs.txt (#4172) 2024-07-10 17:38:06 +00:00
Boshen
051ceb6539
chore: improve some format by running cargo +nightly fmt 2024-06-19 00:48:30 +08:00
Boshen
5c38a0fd69 feat(codegen)!: new code gen API (#3740)
This PR introduces two type alias to avoid the confusing const generic `pub struct Codegen<'a, const MINIFY: bool>`

* CodeGenerator - Code generator without whitespace removal.
* WhitespaceRemover - Code generator with whitespace removal.

Usage is changed to a builder pattern:

```rust
CodeGenerator::new()
  .enable_comment(...)
  .enable_sourcemap(...)
  .build(&program);
```
2024-06-18 15:50:12 +00:00
Boshen
982e6f08df chore: make println and eprintln opt-in (#3712)
I noticed accidental `println` can be merged, which isn't really nice.
2024-06-17 10:40:34 +00:00
Boshen
b58d8eb88f fix!(codegen): remove the unecessary 4th argument from Codegen::new (#3640) 2024-06-12 07:58:54 +00:00
IWANABETHATGUY
0cdb45a1ff
feat(oxc_codegen): preserve annotate comment (#3465)
1. Copy tests from
efa3dd2d8e/internal/bundler_tests/bundler_dce_test.go (L3833-L3971)
2. Add option to preserve annotate comment like `/* #__NO_SIDE_EFFECTS__
*/` and `/* #__PURE__ */`
2024-05-30 15:25:23 +08:00
Boshen
f366d9bd7c
chore(minsize): remove brotlic because it takes too long to compile (#2954) 2024-04-13 13:24:25 +08:00
underfin
d9b77d853b
refactor(sourcemap): change sourcemap name to take a reference (#2779) 2024-03-23 21:40:05 +08:00
Boshen
ef932a3c27
refactor(codegen): clean up API around building sourcemaps (#2602)
closes #2564
2024-03-04 16:03:33 +08:00
Andrew McClenaghan
e6d536cb9b
feat(codegen): configurable typescript codegen (#2443)
- Adds option to `CodegenOptions` - `enable_typescript` to enable output
of TS.
- Stops skipping output that is TS when `enable_typescript` is enabled
- Adds TS support to 
    - Function
    - FormalParameter
    - BindingPattern
 - Adds basic tests for TS generation

---------

Co-authored-by: Boshen <boshenc@gmail.com>
2024-02-20 12:09:28 +08:00
Boshen
70a0076eed
refactor: remove global allocator from non-user facing apps (#2401)
The runtime performance gains does not out weight the compilation speed from
building the custom allocators, which takes about a minute to build on
slower machines.
2024-02-12 14:09:05 +08:00
Boshen
801d78a3c6
refactor(minifier): make the minifier api only accept an ast (#990) 2023-10-14 00:51:29 +08:00
Boshen
8c12dff8a3
perf: speed tasks run by using a global allocator 2023-10-11 20:30:30 +08:00
Boshen
c38a00b453
chore(minsize): disable the test as it is broken right now 2023-10-10 15:53:55 +08:00
Don Isaac
027a67d94c
feat(minifier): constant addition expression folding (#882)
Fold constant addition expressions. Handles string concatenation and
addition, both with implicit casting.

For example,
```ts
let x = 1 + 1
let y = "hello " + "world"
```
now becomes
```ts
let x = 2
let y = "hello world"
```

## Extra Goodies
- test(minifier): add `test_snapshot` helper to perform snapshot tests
with `insta`
- up(hir): implement `std::ops::Add` for `NumericValue`
- up(span): impl `TryFrom<Cow<'_, &str>>` for `Atom`
2023-09-11 10:38:35 +08:00
Boshen
ee6f18091b
chore(minsize): add newlines in between for better diff 2023-05-25 22:42:11 +08:00
Yoni Feng
c1d1846714
Add Brotli size to minsize task output (#377) 2023-05-23 17:00:49 +08:00
Boshen
f8828db68c
feat(semantic2): slot based mangler (#364) 2023-05-20 19:00:57 +08:00
Boshen
14720e7c69
refactor: move SourceType from oxc_ast to oxc_span (#351)
related #350
2023-05-12 23:16:14 +08:00
Boshen
86c01c7fb8
feat(minifier): use hir (#335) 2023-05-07 17:23:00 +08:00
Boshen
c14c82b15d
feat(printer,semantic): mangler (#285)
closes #284
2023-04-18 21:32:35 +08:00
Boshen
4c5ece9386
chore(tasks): remove minsize from unit tests as it is too slow 2023-04-15 13:41:52 +08:00
Boshen
9eec306818
chore(minifier): add SemanticBuilder to minifier example
so we can start measuring perf
2023-04-14 13:21:04 +08:00
Boshen
a7cd845fff
feat: add cargo minsize task for tracking minification size (#276)
* feat: add `cargo minsize` task for tracking minification size

* add gzip
2023-04-14 13:07:37 +08:00