ClojureScript

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

Details

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

Description

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

Activity

Brandon Bloom made changes -
Field Original Value New Value
Attachment track-pos-2.patch [ 11051 ]
Brandon Bloom made changes -
Attachment track-pos-2.patch [ 11051 ]
Brandon Bloom made changes -
Attachment track-pos-2.patch [ 11052 ]
David Nolen made changes -
Resolution Completed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Brandon Bloom made changes -
Attachment uninit-var-print.patch [ 11059 ]
David Nolen made changes -
Status Resolved [ 5 ] Closed [ 6 ]

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: