Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by

Google Closure now contains comprehensive support for (at least from the command line) for source map merging and inline source map generation. We should investigate how reusable this functionality actually is.

4 Answers

0 votes
by

Comment made by: darwin

Investigated it a bit, just sharing what I learned so far:

  1. historically there used to be a hidden flag --source_map_input which could be used to produce source-map-aware error reporting, not source map composition as name would suggest(link: 1)
  2. mid 2016, a patch landed(link: 2), which enhanced this for full source map composition
  3. by the end of 2016, the feature seems to be public and enabled in command-line tool by default(link: 3)(link: 5)
  4. as of today, the official source-maps wiki page(link: 4) has not been updated to reflect this latest development

(link: 1) https://github.com/google/closure-compiler/issues/1360#issuecomment-170716968
(link: 2) https://github.com/google/closure-compiler/pull/1971
(link: 3) https://github.com/google/closure-compiler/pull/2008
(link: 4) https://github.com/google/closure-compiler/wiki/Source-Maps
(link: 5) https://github.com/google/closure-compiler/pull/2129

0 votes
by

Comment made by: darwin

Closure compiler also newly understands inlined source maps using data URLs in input Javascript files(link: 1).

  1. parsing of inline source maps is enabled by default unless \-\-parse_inline_source_maps=false is passed, it is independent on \-\-source_map_input flag
  2. information from \-\-source_map_input and inlined source-maps is merged, inlined maps override \-\-source_map_input, the last inlined map wins in case of multiple //1. sourceMappingURL= present (link: 2)

(link: 1) https://github.com/google/closure-compiler/pull/1982
(link: 2) https://github.com/google/closure-compiler/pull/1982#issuecomment-243249065

0 votes
by

Comment made by: thheller

FWIW I added support for this in shadow-build a while ago. It does not need inline source maps to work.

The code can be found here: https://github.com/thheller/shadow-build/blob/master/src/main/shadow/cljs/closure.clj

The relevant bits are {{.addInputSourceMap}} on {{Compiler}} and {{.setApplyInputSourceMaps}} on {{CompilerOptions}}.

If everything is properly configured the warnings displayed by Closure will contain an "Originally at:" location which points to the CLJS file.

Closure will also use the input source maps when generating source maps for {{:advanced}} builds, so the manual merge done by CLJS at the moment becomes unnecessary. The source maps also appear to be more accurate. Before input source maps I had a few issues where source maps were off by a few lines, but that may have been due to my incorrect source map handling in shadow-build.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJS-1901 (reported by dnolen)
...