Skip to content

SourceMaps

SerkanSipahi edited this page Dec 7, 2014 · 6 revisions

How to translate output source coordinates to input source coordinates for debugging.

Traceur compiles futuristic ECMAScript into JavaScript that can run today. A Sourcemap relates the output JavaScript to the original source. Runtime error messages in the low-level code and debugging tools running on the generated source can use the source map information to convert their output to reference the original source. For more information see http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/

The runtime and development tools obtain the sourcemap by reading a comment at the end of the compiled code. The comment has the form //# sourceMapingURL=<URL>. Sourcemaps can be stored in files separate from the output (URL is file name), appended to the output (URL is data: encoding the content), or in memory (URL is filename; this mode is in development).

To generate sourcemaps when compiling into files, set the command line option --source-maps [file|inline] . With --source-maps=file, every output file ending in .js will have a sourcemap file ending in .map; with source-maps='inline', every output file ending in .js will end with a comment containing the sourcemap encoded in a data: URL.

To generate sourcemaps when compiling or loading dynamically, either via the API or via System.import(), use the sourceMaps option set to 'inline' or 'file' ('inline will normally be used).

Details

Traceur uses Mozilla's source map implementation, https://github.com/mozilla/source-map.