Movatterモバイル変換


[0]ホーム

URL:


dosyncArchivePagesCategoriesTags

ClojureScript Source Maps

15 September 2013

UPDATE: This is now an outdated post. For more accurate information on enabling source maps please refer to theClojureScript Wiki entry.

ClojureScript has had experimentalsource mapsupport for some time. Unlike other transpile to JavaScript languages,ClojureScript source maps actually map all the way through GoogleClosure advanced compilation! However this support suffered frominaccuracies due to the lack of necessary information from the Clojurereader and less than ideal handling of function parameters and letbindings in the ClojureScript compiler. We switched totools.reader, a wonderfullibrary led byNicola Mometto that worksjust like the standard reader but provides the needed line and columninformation on all symbols. Then we received a patch this weekend fromSean Grove that fixed an off by one errorand changed the compiler to properly emit function parameters and letbinding. With these things in place we can finally emit accuratesource maps. There’s likely more issues but the only way to find outis to give it a try and file some bug reports!

In order to enable source maps your project.clj should look somethinglike this:

(defproject example "0.1.0-SNAPSHOT"  :dependencies [[org.clojure/clojure "1.5.1"]                 [org.clojure/clojurescript "0.0-1889"]]  :plugins [[lein-cljsbuild "0.3.2"]]  :cljsbuild  {:builds   [{:id "advanced"     :source-paths ["src/example"]     :compiler {:optimizations :advanced                :pretty-print false                :output-dir "out"                :output-to "main.js"                :source-map "main.js.map"}}]}) ;; << ADD THIS

Currently the source map generated by the ClojureScript compiler usesfull paths for the files. How to best configure this is up fordiscussion as some files live in JARs and ClojureScript doesn’t alwayswrite out these files to:output-dir. Perhaps it should but that’sthe kind of feedback we’re looking for and the kind of patches we’reinterested in.

In the meantime you can still test out the feature as we’ve hacked theClojureScript browser REPL web server to handle serving files fromJARs and elsewhere! So just make sure source maps are enabled in yourbrowser of choice, make anindex.html file that includes yourClojureScript output file, runlein trampoline cljsbuild repl-listenand point your browser athttp://localhost:9000.

If you get it working you should be able toconsole.log somethingand the browser will give you an accurate location where thatstatement was executed in the original source:

If you run into issues please let us know on theClojureScript mailing listor the Clojure IRC cannnel.

Related Posts

RSS

github.com/swannodette
twitter.com/swannodette


[8]ページ先頭

©2009-2025 Movatter.jp