...
- Target the Google Closure AST
- Advantages
- Keeps us out of the JS AST design business
- Existing code printer
- Includes facilities for Closure Compiler type system
- Perf? Can skip roundtrip to JS source and to disk
- Disadvantages
- Closure AST nodes are stateful
- Each Node has an explicit parent reference
- Cloning policy is necessary to reuse subtrees (wasn't an issue in my port so far, see below)
- Increases our dependence on Closure
- Closure AST evolves more quickly than the JS spec
- Recent changes: http://code.google.com/p/closure-compiler/source/list?path=/trunk/src/com/google/javascript/jscomp/parsing/IRFactory.java&start=2295
- Closure AST nodes are stateful
- Alternative: Intermediate JavaScript AST as Clojure data-structures
- Requires an additional translation step
- GWT and Dart use a different AST that they translate; See: http://code.google.com/p/google-web-toolkit/source/browse/trunk/dev/core/src/com/google/gwt/dev/js/ClosureJsAstTranslator.java?r=10778
- Closure Compiler Discussion: https://groups.google.com/forum/?fromgroups=#!topic/closure-compiler-discuss/OEwLWkw4Kug
- Advantages
- Thin JS-AST DSL
- Recursively transpiles arguments
- Can be extended to automatically attach source mappings from dynamic bindings
- Does a Hiccup like seq expansion
- Eliminate js* form, replaces it with DSL invokes: (js* "foo({0})" x) becomes (js*/call 'foo x)
Preliminary Progress
- Fork: https://github.com/brandonbloom/clojurescript/tree/js-ast
- Interesting files: compiler.clj and js.clj
- As of Nov 9
- Compiles all the CLJS in the ClojureScript tree
- Bugged in advanced compilation mode
- Does not generate source mappings
- Does not bypass the extra round-trip to JS source and to disk
- Takes 3X as long as naive string printing; 10 vs 30 seconds for (compile-root "src/cljs/cljs") on my machine
- core.clj and core.cljs are fully ported from (js* "..." ...) to (js*/... ...)