UglifyJS Demo

This demo uses UglifyJS version 2.4.12

Input

Output

AST

Key:

  • \S in the type means the property is only available after calling ast.figure_out_scope()
  • * in the type means the property is an array of that type
  • ? in the type means the property is an optional property and may instead be null

Beautify

Minify

Documentation

Full documentation can be found at lisperator.net/uglifyjs You will probably find the following information is also useful for understanding the internals though.

Not all nodes may be instantiated, here is a list of nodes which are not "abstract"

  • Array
  • Assign
  • Binary
  • BlockStatement
  • Call
  • Case
  • Catch
  • Conditional
  • Const
  • Debugger
  • Default
  • Directive
  • Do
  • Dot
  • EmptyStatement
  • False
  • Finally
  • For
  • ForIn
  • If
  • LabeledStatement
  • New
  • Null
  • Number
  • Object
  • ObjectGetter
  • ObjectKeyVal
  • ObjectSetter
  • RegExp
  • Return
  • Seq
  • SimpleStatement
  • String
  • Sub
  • Switch
  • Throw
  • Token
  • Toplevel
  • True
  • Try
  • Undefined
  • Var
  • VarDef
  • While
  • With

You can instantiate any of the nodes by calling new UglifyJS.AST_NodeType({properties}):

function createNode(type, properties) { return new UglifyJS['AST_' + type](properties) } var str = createNode('String', {value: 'foo'})

If all you want to do is minify some code you can use:

var res = UglifyJS.minify('source code', { warnings: false, //pass `true` to display compressor warnings fromString: true, //you will probably want to pass true but this defaults to false. //Pass `true` to minify a string of source code, rather than treating //the argument as a filename. mangle: true, //pass `false` to skip magling names output: null, //customise output options compress: {} //pass `false` to skip compression or pass an object to customise compression }) //res.code contains minified source code //res.map contains a source map