Skip to content

ironm00n/unminification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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

About

SWC plugin for JavaScript unminification

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published