B2G/gecko/toolkit/devtools/sourcemap/SourceMap.jsm
/**
   * 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.
   *
   * The only parameter is the raw source map (either as a JSON string, or
   * already parsed to an object). According to the spec, source maps have the
   * following attributes:
   *
   *   - version: Which version of the source map spec this map is following.
   *   - sources: An array of URLs to the original source files.
   *   - names: An array of identifiers which can be referrenced by individual mappings.
   *   - sourceRoot: Optional. The URL root from which all sources are relative.
   *   - mappings: A string of base64 VLQs which contain the actual mappings.
   *   - file: The generated file this source map is associated with.
   *
   * Here is an example source map, taken from the source map spec[0]:
   *
   *     {
   *       version : 3,
   *       file: "out.js",
   *       sourceRoot : "",
   *       sources: ["foo.js", "bar.js"],
   *       names: ["src", "maps", "are", "fun"],
   *       mappings: "AA,AB;;ABCDE;"
   *     }
   *
   * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
   */
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.

The only parameter is the raw source map (either as a JSON string, or
already parsed to an object). According to the spec, source maps have the
following attributes.

- version: Which version of the source map spec this map is following.
- sources: An array of URLs to the original source files.
- names: An array of identifiers which can be referrenced by individual mappings.
- sourceRoot: Optional. The URL root from which all sources are relative.
- mappings: A string of base64 VLQs which contain the actual mappings.
- file: The generated file this source map is associated with.

Here is an example source map, taken from the source map spec[0].




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 . The only parameter is the raw source map ( either as a JSON string or already parsed to an object ) . According to the spec source maps have the following attributes . - version : Which version of the source map spec this map is following . - sources : An array of URLs to the original source files . - names : An array of identifiers which can be referrenced by individual mappings . - sourceRoot : Optional . The URL root from which all sources are relative . - mappings : A string of base64 VLQs which contain the actual mappings . - file : The generated file this source map is associated with . Here is an example source map taken from the source map spec [ 0 ] .
function SourceMapConsumer(aSourceMap) {
    var sourceMap = aSourceMap;
    if (typeof aSourceMap === 'string') {
      sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
    }
    var version = util.getArg(sourceMap, 'version');
    var sources = util.getArg(sourceMap, 'sources');
    var names = util.getArg(sourceMap, 'names');
    var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
    var mappings = util.getArg(sourceMap, 'mappings');
    var file = util.getArg(sourceMap, 'file');
    if (version !== this._version) {
      throw new Error('Unsupported version: ' + version);
    }
    this._names = ArraySet.fromArray(names);
    this._sources = ArraySet.fromArray(sources);
         {
           generatedLine: The line number in the generated code,
           generatedColumn: The column number in the generated code,
           source: The path to the original source file that generated this
                   chunk of code,
           originalLine: The line number in the original source that
                         corresponds to this chunk of generated code,
           originalColumn: The column number in the original source that
                           corresponds to this chunk of generated code,
           name: The name of the original symbol which generated this chunk of
                 code.
         }
     All properties except for `generatedLine` and `generatedColumn` can be
     `null`.
     `this._generatedMappings` is ordered by the generated positions.
     `this._originalMappings` is ordered by the original positions.
    this._generatedMappings = [];
    this._originalMappings = [];
    this._parseMappings(mappings, sourceRoot);
  }
function SourceMapConsumer ( aSourceMap ) { var sourceMap = aSourceMap ; if ( typeof aSourceMap === 'string' ) { sourceMap = JSON . parse ( aSourceMap . replace ( / ^\)\]\}' / , '' ) ) ; } var version = util . getArg ( sourceMap , 'version' ) ; var sources = util . getArg ( sourceMap , 'sources' ) ; var names = util . getArg ( sourceMap , 'names' ) ; var sourceRoot = util . getArg ( sourceMap , 'sourceRoot' , null ) ; var mappings = util . getArg ( sourceMap , 'mappings' ) ; var file = util . getArg ( sourceMap , 'file' ) ; if ( version !== this . _version ) { throw new Error ( 'Unsupported version: ' + version ) ; } this . _names = ArraySet . fromArray ( names ) ; this . _sources = ArraySet . fromArray ( sources ) ; this . _generatedMappings = [ ] ; this . _originalMappings = [ ] ; this . _parseMappings ( mappings , sourceRoot ) ; }
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.
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 .
// `this._generatedMappings` and `this._originalMappings` hold the parsed // mapping coordinates from the source map's "mappings" attribute. Each // object in the array is of the form // //     { //       generatedLine: The line number in the generated code, //       generatedColumn: The column number in the generated code, //       source: The path to the original source file that generated this //               chunk of code, //       originalLine: The line number in the original source that //                     corresponds to this chunk of generated code, //       originalColumn: The column number in the original source that //                       corresponds to this chunk of generated code, //       name: The name of the original symbol which generated this chunk of //             code. //     } // // All properties except for `generatedLine` and `generatedColumn` can be // `null`. // // `this._generatedMappings` is ordered by the generated positions. // // `this._originalMappings` is ordered by the original positions.