These pages are old. They apply to UglifyJS v2. Version 3 has evolved a lot in the mean time to support most of ES6. Please check the documentation in the official repository for up-to-date information. Big thanks to all contributors, especially to Alex Lam S.L., who has maintained this project for years!

UglifyJS — the syntax tree (AST)

You can get a cruel description of the AST with uglifyjs --ast-help. Each definition starts with the node name (i.e. AST_Node), followed by a list of own properties in parens (if it has any), followed by a string description and followed by any subclasses (if there are any). Nodes inherit properties from the base classes; for example since the start and end properties are defined in the base class AST_Node, then every node contains those properties.

The parser will instantiate the most specific subclass; for example you will never find an object of type AST_Node in the AST; that's just the base class. You won't find an AST_Statement either, since every kind of statement has its own dedicated subclass.

The AST nodes

The following hierarchy is generated by your browser using introspection from the UglifyJS objects. Click a node to get a brief description of it. See below for some information on AST_Token, also take a look at the scope analyzer for more information about properties in red and SymbolDef.





The tokenizer

For a higher-level operation, the parser works concomitantly with a tokenizer. The tokenizer is initialized to the stream of the source code text and reads one token at a time, producing an AST_Token object which has the following properties:

The start and end properties of AST nodes are AST_Token objects and tell you where that node begins and ends. The AST_Toplevel is the single node that might start in one file and end in another (when parsing multiple files); the parser will properly update its end property.

Read more about the scope analyzer.

Welcome! (login)

UglifyJS

JS compressor of world fame.

Open demo

Latest blog entries tagged "uglifyjs"

/** May the source-map be with you! **/

Fork me on Github