UglifyJS — a JS parser/compressor/beautifier

... for NodeJS.

With minimal changes it should work on any JavaScript engine, but currently NodeJS is the main development platform.

It implements a JavaScript parser which produces a clean abstract syntax tree from JS code (this part is ported from parse-js, a great JS parser for Common Lisp). Then it contains a few functions that manipulate the AST to compress variable names to single characters, and provide various other compression techniques such as:

join consecutive var declarations: var a = 10; var b = 20; ==> var a = 10, b = 20;

remove block brackets {} where possible

transform foo["bar"] into foo.bar

various optimizations for IF statements:

remove "else" where possible (when the last statement in an IF block is "return", "throw", "break" or "continue")



transform simple IF-s like: if (foo) bar(); else baz(); ==> foo?bar():baz(); if (!foo) bar(); else baz(); ==> foo?baz():bar(); if (foo) bar(); ==> foo&&bar(); if (!foo) bar(); ==> foo||bar();

and some others.

It compresses better than the YUI compressor, and safer than Google Closure. And it's a lot faster than any of these.

Get the code here: http://github.com/mishoo/UglifyJS and spread the word! :-)