This is an SWC plugin which aims to reverse many of the effects of code minification. Aims to ease reverse engineering unobfuscated, minified, bundled, JavaScript codebases.
- 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➞falsevoid 0➞undefined1 / 0➞Infinity-1 / 0➞-Infinity0 / 0➞NaN
- Note that:
undefined,Infinity, andNaNcould 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) {}
- for (foo in (baz(), bar)) {}
+ baz();
+ for (foo in bar) {}
- for (foo of (baz(), bar)) {}
+ baz();
+ for (foo of bar) {}Separates assignments from return statements and function calls:
- return (foo = bar);
+ foo = bar;
+ return foo;
- return (foo = bar)();
+ foo = bar;
+ return foo();Restores common constants and loop patterns:
- 9007199254740991
+ Number.MAX_SAFE_INTEGER
- -9007199254740991
+ Number.MIN_SAFE_INTEGER
- for (;;) { ... }
+ while (true) { ... }
- for (; cond;) { ... }
+ while (cond) { ... }Converts logical expressions back to control flow:
- foo && bar();
+ if (foo) bar();
- foo || bar();
+ if (!foo) bar();
- foo ? bar() : baz();
+ if (foo) bar();
+ else baz();
- typeof foo > "u"
+ typeof foo === "undefined"
- 0 === foo
+ foo === 0Restores modern JavaScript syntax:
- foo == null ? undefined : foo.bar
+ foo?.bar
- foo == null ? undefined : foo.bar()
+ foo?.bar()
- "".concat(a, " world")
+ `${a} world`
- ({ func: function() {} })
+ ({ func() {} })
- function f(x) {
- var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
- }
+ function f(x, y = 10) {}