Get a reference to the module:

let sourceMap = {};
Components.utils.import('resource:///modules/devtools/SourceMap.jsm', sourceMap);


A SourceMapConsumer instance represents a parsed source map which we can query for information about the original file positions by giving it a file position in the generated source.

new SourceMapConsumer(rawSourceMap)

The only parameter is the raw source map (either as a string which can be JSON.parse'd, or an object). According to the spec, source maps have the following attributes:


Returns the original source, line, and column information for the generated source's line and column positions provided. The only argument is an object with the following properties:

and an object is returned with the following properties:


An instance of the SourceMapGenerator represents a source map which is being built incrementally.

new SourceMapGenerator(startOfSourceMap)

To create a new one, you must pass an object with the following properties:


Add a single mapping from original source line and column to the generated source's line and column for this source map being created. The mapping object should have the following properties:


Renders the source map being generated to a string.


SourceNodes provide a way to abstract over interpolating and/or concatenating snippets of generated JavaScript source code, while maintaining the line and column information associated between those snippets and the original source code. This is useful as the final intermediate representation a compiler might use before outputting the generated JS and source map.

new SourceNode(line, column, source[, chunk])


Add a chunk of generated JS to this source node.


Prepend a chunk of generated JS to this source node.


Walk over the tree of JS snippets in this node and its children. The walking function is called once for each snippet of JS and is passed that snippet and its original associated source's line/column location.


Like Array.prototype.join except for SourceNodes. Inserts the separator between each of this source node's children.

SourceNode.prototype.replaceRight(pattern, replacement)

Call String.prototype.replace on the very rightmost source snippet. Useful for trimming whitespace from the end of a source node, etc.


Return the string representation of this source node. Walks over the tree and concatenates all the various snippets together to one string.


Returns the string representation of this tree of source nodes, plus a SourceMapGenerator which contains all the mappings between the generated and original sources.

The arguments are the same as those to new SourceMapGenerator.