No description
  • Rust 99.8%
  • JavaScript 0.2%
Find a file
2024-08-26 11:37:57 -04:00
.cargo bring to top-level 2024-08-26 11:37:57 -04:00
.vscode bring to top-level 2024-08-26 11:37:57 -04:00
javascript bring to top-level 2024-08-26 11:37:57 -04:00
src bring to top-level 2024-08-26 11:37:57 -04:00
.gitignore bring to top-level 2024-08-26 11:37:57 -04:00
.rustfmt.toml bring to top-level 2024-08-26 11:37:57 -04:00
Cargo.lock bring to top-level 2024-08-26 11:37:57 -04:00
Cargo.toml bring to top-level 2024-08-26 11:37:57 -04:00
package.json bring to top-level 2024-08-26 11:37:57 -04:00
README.md bring to top-level 2024-08-26 11:37:57 -04:00

Unminification

This is an SWC plugin which aims to reverse many of the effects of code minification.

Setup

  • use Rust nightly: rustup override set nightly
  • run: rustup target add wasm32-wasi
  • build using: cargo build-wasi --release

Changes

Restore Literals

  • 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:
    • !0true
    • !1false
    • void 0undefined
    • 1 / 0Infinity
    • -1 / 0-Infinity
    • 0 / 0NaN
  • Note that: undefined, Infinity, and NaN could be potentially inaccurate since they are not reserved words. However this is unlikely to be a concern in a minified context.

Desequencing

  • 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) {}