-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Design Documents
Closure Compiler consists of 3 essential mechanisms:
- A "ParserRunner" that uses Rhino to parse JavaScript, and converts it into an abstract syntax tree.
- A "PassConfig" that chooses compiler passes to transform this syntax tree.
- A "CommandLineRunner" that translates user-specified options into a "PassConfig", runs the passes, and then serializes the syntax tree back to JavaScript.
Everything else that Closure Compiler does is implemented as a "CompilerPass". Compiler passes do many things. Some do type-checking. Some do optimizations. Some check the output of other compiler passes. Some create more complicated symbol tables, which are then fed into other compiler passes.
In all cases, the syntax tree is the source of truth. Every compiler pass should leave the syntax tree in a consistent state (so that if we generated JavaScript from that syntax tree, the code would still run correctly).
If you are a developer on Closure Compiler, you can install "sanity check" passes to ensure that the syntax tree is always valid between each pass. Some of these sanity checks are run all the time, even for non-developers. For example, the VarCheck pass is run at the end of every compiler job to ensure that all variables are declared in the syntax tree.
The Internal Syntax Tree (PDF)
Closure Compiler Side-effect annotations for Extern definitions
Property Renaming Part 1, Part 2, and Part 3
EcmaScript 4 Draft Spec - Our type system semantics are based on this spec.
EcmaScript 4 Draft Grammar - Our type expression grammar is based on this spec.