UglifyJS — using the SpiderMonkey AST
// for example, use Acorn to parse code: acorn = require("acorn"); spidermonkey_ast = acorn.parse(source_code); uglifyjs_ast = UglifyJS.AST_Node.from_mozilla_ast(spidermonkey_ast); // further use uglifyjs_ast as if it were produced by UglifyJS.parse uglifyjs_ast.figure_out_scope(); ast = uglifyjs_ast.transform(compressor); code = ast.print_to_string();
The AST_Node.from_mozilla_ast function takes a SpiderMonkey abstract syntax tree (usually a Program node, but you can pass incomplete trees as well) and produces the equivalent UglifyJS AST.
catchclauses etc. That's because UglifyJS itself doesn't support those.
JS compressor of world fame.Open demo
- Code generator
- The AST structure
- SpiderMonkey AST
- Scope analysis
- AST walker
- AST transformer
- UglifyJS on Github
Latest blog entries tagged "uglifyjs"
- Using UglifyJS for code refactoring
- Should you switch to UglifyJS2?
- UglifyJS online demo
- UglifyJS — why not switching to SpiderMonkey AST
/** May the source-map be with you! **/