Skip to end of metadata
Go to start of metadata


The ClojureScript compiler currently directly prints JavaScript source code strings. It is desirable to instead produce a JavaScript Abstract Syntax Tree to simplify code generation, emit source maps, and to enable higher level optimizations.


  • Compiler should be more functionally pure
    • Code generation currently emits strings as a side effect
    • Enhancing the compiler is difficult because printing forces ordering and limits higher order composition
    • It's not safe to interleave multiple passes of analysis, transformations, and code generation
  • emit complects Code Generation and Code Printing
    • requires simultaneous consideration of JavaScript's abstract structure and particulars of syntax
    • code generation is trivially functionally pure; code printing could be, but wouldn't benefit much
  • SourceMaps! Strings lack structure to associate mappings
    • If you currently are printing "foo(bar)", you might need to assign different source lines to both foo and bar
    • Adding source mappings to printing would give very low mapping resolution for the current ad-hoc strings
    • Increasing the resolution would yield something that looks very much like an AST


  • Decouple code generation from code printing
  • Simplify compiler.clj
  • Include source mappings on outputted AST
  • Preserve compiler and generated code performance


Preliminary Progress

  • Fork:
  • 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*/... ...)