Track line & column in generated JS (needed for SourceMaps)


  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:


The attached patch modifies the ClojureScript compiler by replacing all calls to print, println, emits, etc, such that all code generation funnels through the new emitx and emitln. The emitx and emitln functions track position as a 2-tuple vector of [line, column], zero-based. The line and column information is a prerequisite for generating correct source maps. NOTE: This is the position in the generated JavaScript source, not the :line and :column metadata from the Clojure reader.

In the emitln function, there are a few commented out lines which constitute a "test". Basically, it causes the compiler to append a line number // comment on each line of the generated source. The comments are horizontally aligned at 120 characters, so you can quickly visually inspect for alignment bugs. Unfortunately, I'm not really sure how better to test this, or to ensure that this keeps working until the rest of SourceMaps gets implemented In theory, as long as no one prints anything directly, always using emitx and emitln, nothing should break.

  1. track-pos-1.diff
    09/Apr/12 2:16 AM
    29 kB
    Brandon Bloom
  2. track-pos-2.patch
    14/Apr/12 7:49 PM
    30 kB
    Brandon Bloom
  3. uninit-var-print.patch
    16/Apr/12 11:49 PM
    0.7 kB
    Brandon Bloom



Vote (0)
Watch (1)


  • Created: