esmangle
esmangle copied to clipboard
esmangle is mangler / minifier for Mozilla Parser API AST
Drop unused assignments ``` js function test() { var i; i = 20; } ``` to ``` js function test() { var i; 20; } ``` and then ``` js...
transform ``` js typeof ... === 'string' ``` to ``` js typeof ... == 'string' ```
We can provide inlining optimize pass optionally.
esmangle should not transform `9e9 + 1` into `9000000001`, as it currently does.
Just a general reminder to do constant folding. - `"a" + "b"` -> `"ab"` - `0 + 1` -> `1` - `typeof function(){}` -> `"function"` - etc.
``` js (function(something){ var a, b; sideEffect(a(b)); })(somethingElse) ``` is a common pattern that can be shortened with a step that provides the following transformation: ``` js (function(something, a, b){...
``` js (function(){ return function(){ return x ? y : void 0; }; }()) ``` can become ``` js (function(u){ return function(){ return x ? y : u; }; }())...
This might be a tough one: ``` js for(;;) { if(cond) continue; f() } ``` is currently mangled to ``` js for(;;){if(cond)continue;f()} ``` but it could be ``` js for(;;)if(!cond)f()...
For example, we can use constant folding result value to determine target branch is dead or not. ``` javascript var s = 10; if (!s) { // this is dead...