This is an SWC plugin which aims to reverse many of the effects of code minification.
- use Rust nightly:
rustup override set nightly
- run:
rustup target add wasm32-wasi
- build using:
cargo build-wasi --release
- SWC and other transpilers transform literals into equivalent values to reduce the size of code generated
- The following are reverted back into their literal forms:
!0
➞true
!1
➞false
void 0
➞undefined
1 / 0
➞Infinity
-1 / 0
➞-Infinity
0 / 0
➞NaN
- Note that:
undefined
,Infinity
, andNaN
could be potentially inaccurate since they are not reserved words. However this is unlikely to be a concern in a minified context.
- Transpilers often convert a sequence of statements into a sequence expression to save space
- foo(), bar();
+ foo();
+ bar();
- foo = (baz(), bar);
+ baz();
+ foo = bar;
- return (foo(), bar)
+ foo();
+ return bar;
- throw (foo(), bar)
+ foo();
+ throw bar;
- if ((foo = bar, baz)) {}
+ foo = bar;
+ if (baz) {}
- switch (foo(), bar) {}
+ foo();
+ switch(bar) {}
# add normal for
- for (foo in (baz(), bar)) {}
+ baz();
+ for (foo in bar) {}
- for (foo of (baz(), bar)) {}
+ baz();
+ for (foo of bar) {}