ClojureScript

Investigate new Google Closure source mapping support

Details

  • Type: Task Task
  • Status: Open Open
  • Priority: Minor Minor
  • Resolution: Unresolved
  • Affects Version/s: 1.9.655
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

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.

Activity

Hide
Antonin Hildebrand added a comment - - edited

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[1]
2. mid 2016, a patch landed[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[3][5]
4. as of today, the official source-maps wiki page[4] has not been updated to reflect this latest development

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

Show
Antonin Hildebrand added a comment - - edited 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[1] 2. mid 2016, a patch landed[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[3][5] 4. as of today, the official source-maps wiki page[4] has not been updated to reflect this latest development [1] https://github.com/google/closure-compiler/issues/1360#issuecomment-170716968 [2] https://github.com/google/closure-compiler/pull/1971 [3] https://github.com/google/closure-compiler/pull/2008 [4] https://github.com/google/closure-compiler/wiki/Source-Maps [5] https://github.com/google/closure-compiler/pull/2129
Hide
Antonin Hildebrand added a comment - - edited

Closure compiler also newly understands inlined source maps using data URLs in input Javascript files[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 //# sourceMappingURL=<data URL> present [2]

[1] https://github.com/google/closure-compiler/pull/1982
[2] https://github.com/google/closure-compiler/pull/1982#issuecomment-243249065

Show
Antonin Hildebrand added a comment - - edited Closure compiler also newly understands inlined source maps using data URLs in input Javascript files[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 //# sourceMappingURL=<data URL> present [2] [1] https://github.com/google/closure-compiler/pull/1982 [2] https://github.com/google/closure-compiler/pull/1982#issuecomment-243249065
Hide
Thomas Heller added a comment -

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.

Show
Thomas Heller added a comment - 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.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated: