toolkit/devtools/sourcemap/SourceMap.jsm

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/devtools/sourcemap/SourceMap.jsm	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1799 @@
     1.4 +/* -*- Mode: js; js-indent-level: 2; -*- */
     1.5 +/*
     1.6 + * Copyright 2011 Mozilla Foundation and contributors
     1.7 + * Licensed under the New BSD license. See LICENSE or:
     1.8 + * http://opensource.org/licenses/BSD-3-Clause
     1.9 + */
    1.10 +
    1.11 +/*
    1.12 + * WARNING!
    1.13 + *
    1.14 + * Do not edit this file directly, it is built from the sources at
    1.15 + * https://github.com/mozilla/source-map/
    1.16 + */
    1.17 +
    1.18 +///////////////////////////////////////////////////////////////////////////////
    1.19 +
    1.20 +
    1.21 +this.EXPORTED_SYMBOLS = [ "SourceMapConsumer", "SourceMapGenerator", "SourceNode" ];
    1.22 +
    1.23 +Components.utils.import('resource://gre/modules/devtools/Require.jsm');
    1.24 +/* -*- Mode: js; js-indent-level: 2; -*- */
    1.25 +/*
    1.26 + * Copyright 2011 Mozilla Foundation and contributors
    1.27 + * Licensed under the New BSD license. See LICENSE or:
    1.28 + * http://opensource.org/licenses/BSD-3-Clause
    1.29 + */
    1.30 +define('source-map/source-map-consumer', ['require', 'exports', 'module' ,  'source-map/util', 'source-map/binary-search', 'source-map/array-set', 'source-map/base64-vlq'], function(require, exports, module) {
    1.31 +
    1.32 +  var util = require('source-map/util');
    1.33 +  var binarySearch = require('source-map/binary-search');
    1.34 +  var ArraySet = require('source-map/array-set').ArraySet;
    1.35 +  var base64VLQ = require('source-map/base64-vlq');
    1.36 +
    1.37 +  /**
    1.38 +   * A SourceMapConsumer instance represents a parsed source map which we can
    1.39 +   * query for information about the original file positions by giving it a file
    1.40 +   * position in the generated source.
    1.41 +   *
    1.42 +   * The only parameter is the raw source map (either as a JSON string, or
    1.43 +   * already parsed to an object). According to the spec, source maps have the
    1.44 +   * following attributes:
    1.45 +   *
    1.46 +   *   - version: Which version of the source map spec this map is following.
    1.47 +   *   - sources: An array of URLs to the original source files.
    1.48 +   *   - names: An array of identifiers which can be referrenced by individual mappings.
    1.49 +   *   - sourceRoot: Optional. The URL root from which all sources are relative.
    1.50 +   *   - sourcesContent: Optional. An array of contents of the original source files.
    1.51 +   *   - mappings: A string of base64 VLQs which contain the actual mappings.
    1.52 +   *   - file: The generated file this source map is associated with.
    1.53 +   *
    1.54 +   * Here is an example source map, taken from the source map spec[0]:
    1.55 +   *
    1.56 +   *     {
    1.57 +   *       version : 3,
    1.58 +   *       file: "out.js",
    1.59 +   *       sourceRoot : "",
    1.60 +   *       sources: ["foo.js", "bar.js"],
    1.61 +   *       names: ["src", "maps", "are", "fun"],
    1.62 +   *       mappings: "AA,AB;;ABCDE;"
    1.63 +   *     }
    1.64 +   *
    1.65 +   * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
    1.66 +   */
    1.67 +  function SourceMapConsumer(aSourceMap) {
    1.68 +    var sourceMap = aSourceMap;
    1.69 +    if (typeof aSourceMap === 'string') {
    1.70 +      sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
    1.71 +    }
    1.72 +
    1.73 +    var version = util.getArg(sourceMap, 'version');
    1.74 +    var sources = util.getArg(sourceMap, 'sources');
    1.75 +    // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
    1.76 +    // requires the array) to play nice here.
    1.77 +    var names = util.getArg(sourceMap, 'names', []);
    1.78 +    var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
    1.79 +    var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
    1.80 +    var mappings = util.getArg(sourceMap, 'mappings');
    1.81 +    var file = util.getArg(sourceMap, 'file', null);
    1.82 +
    1.83 +    // Once again, Sass deviates from the spec and supplies the version as a
    1.84 +    // string rather than a number, so we use loose equality checking here.
    1.85 +    if (version != this._version) {
    1.86 +      throw new Error('Unsupported version: ' + version);
    1.87 +    }
    1.88 +
    1.89 +    // Pass `true` below to allow duplicate names and sources. While source maps
    1.90 +    // are intended to be compressed and deduplicated, the TypeScript compiler
    1.91 +    // sometimes generates source maps with duplicates in them. See Github issue
    1.92 +    // #72 and bugzil.la/889492.
    1.93 +    this._names = ArraySet.fromArray(names, true);
    1.94 +    this._sources = ArraySet.fromArray(sources, true);
    1.95 +
    1.96 +    this.sourceRoot = sourceRoot;
    1.97 +    this.sourcesContent = sourcesContent;
    1.98 +    this._mappings = mappings;
    1.99 +    this.file = file;
   1.100 +  }
   1.101 +
   1.102 +  /**
   1.103 +   * Create a SourceMapConsumer from a SourceMapGenerator.
   1.104 +   *
   1.105 +   * @param SourceMapGenerator aSourceMap
   1.106 +   *        The source map that will be consumed.
   1.107 +   * @returns SourceMapConsumer
   1.108 +   */
   1.109 +  SourceMapConsumer.fromSourceMap =
   1.110 +    function SourceMapConsumer_fromSourceMap(aSourceMap) {
   1.111 +      var smc = Object.create(SourceMapConsumer.prototype);
   1.112 +
   1.113 +      smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
   1.114 +      smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
   1.115 +      smc.sourceRoot = aSourceMap._sourceRoot;
   1.116 +      smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
   1.117 +                                                              smc.sourceRoot);
   1.118 +      smc.file = aSourceMap._file;
   1.119 +
   1.120 +      smc.__generatedMappings = aSourceMap._mappings.slice()
   1.121 +        .sort(util.compareByGeneratedPositions);
   1.122 +      smc.__originalMappings = aSourceMap._mappings.slice()
   1.123 +        .sort(util.compareByOriginalPositions);
   1.124 +
   1.125 +      return smc;
   1.126 +    };
   1.127 +
   1.128 +  /**
   1.129 +   * The version of the source mapping spec that we are consuming.
   1.130 +   */
   1.131 +  SourceMapConsumer.prototype._version = 3;
   1.132 +
   1.133 +  /**
   1.134 +   * The list of original sources.
   1.135 +   */
   1.136 +  Object.defineProperty(SourceMapConsumer.prototype, 'sources', {
   1.137 +    get: function () {
   1.138 +      return this._sources.toArray().map(function (s) {
   1.139 +        return this.sourceRoot ? util.join(this.sourceRoot, s) : s;
   1.140 +      }, this);
   1.141 +    }
   1.142 +  });
   1.143 +
   1.144 +  // `__generatedMappings` and `__originalMappings` are arrays that hold the
   1.145 +  // parsed mapping coordinates from the source map's "mappings" attribute. They
   1.146 +  // are lazily instantiated, accessed via the `_generatedMappings` and
   1.147 +  // `_originalMappings` getters respectively, and we only parse the mappings
   1.148 +  // and create these arrays once queried for a source location. We jump through
   1.149 +  // these hoops because there can be many thousands of mappings, and parsing
   1.150 +  // them is expensive, so we only want to do it if we must.
   1.151 +  //
   1.152 +  // Each object in the arrays is of the form:
   1.153 +  //
   1.154 +  //     {
   1.155 +  //       generatedLine: The line number in the generated code,
   1.156 +  //       generatedColumn: The column number in the generated code,
   1.157 +  //       source: The path to the original source file that generated this
   1.158 +  //               chunk of code,
   1.159 +  //       originalLine: The line number in the original source that
   1.160 +  //                     corresponds to this chunk of generated code,
   1.161 +  //       originalColumn: The column number in the original source that
   1.162 +  //                       corresponds to this chunk of generated code,
   1.163 +  //       name: The name of the original symbol which generated this chunk of
   1.164 +  //             code.
   1.165 +  //     }
   1.166 +  //
   1.167 +  // All properties except for `generatedLine` and `generatedColumn` can be
   1.168 +  // `null`.
   1.169 +  //
   1.170 +  // `_generatedMappings` is ordered by the generated positions.
   1.171 +  //
   1.172 +  // `_originalMappings` is ordered by the original positions.
   1.173 +
   1.174 +  SourceMapConsumer.prototype.__generatedMappings = null;
   1.175 +  Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
   1.176 +    get: function () {
   1.177 +      if (!this.__generatedMappings) {
   1.178 +        this.__generatedMappings = [];
   1.179 +        this.__originalMappings = [];
   1.180 +        this._parseMappings(this._mappings, this.sourceRoot);
   1.181 +      }
   1.182 +
   1.183 +      return this.__generatedMappings;
   1.184 +    }
   1.185 +  });
   1.186 +
   1.187 +  SourceMapConsumer.prototype.__originalMappings = null;
   1.188 +  Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
   1.189 +    get: function () {
   1.190 +      if (!this.__originalMappings) {
   1.191 +        this.__generatedMappings = [];
   1.192 +        this.__originalMappings = [];
   1.193 +        this._parseMappings(this._mappings, this.sourceRoot);
   1.194 +      }
   1.195 +
   1.196 +      return this.__originalMappings;
   1.197 +    }
   1.198 +  });
   1.199 +
   1.200 +  /**
   1.201 +   * Parse the mappings in a string in to a data structure which we can easily
   1.202 +   * query (the ordered arrays in the `this.__generatedMappings` and
   1.203 +   * `this.__originalMappings` properties).
   1.204 +   */
   1.205 +  SourceMapConsumer.prototype._parseMappings =
   1.206 +    function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
   1.207 +      var generatedLine = 1;
   1.208 +      var previousGeneratedColumn = 0;
   1.209 +      var previousOriginalLine = 0;
   1.210 +      var previousOriginalColumn = 0;
   1.211 +      var previousSource = 0;
   1.212 +      var previousName = 0;
   1.213 +      var mappingSeparator = /^[,;]/;
   1.214 +      var str = aStr;
   1.215 +      var mapping;
   1.216 +      var temp;
   1.217 +
   1.218 +      while (str.length > 0) {
   1.219 +        if (str.charAt(0) === ';') {
   1.220 +          generatedLine++;
   1.221 +          str = str.slice(1);
   1.222 +          previousGeneratedColumn = 0;
   1.223 +        }
   1.224 +        else if (str.charAt(0) === ',') {
   1.225 +          str = str.slice(1);
   1.226 +        }
   1.227 +        else {
   1.228 +          mapping = {};
   1.229 +          mapping.generatedLine = generatedLine;
   1.230 +
   1.231 +          // Generated column.
   1.232 +          temp = base64VLQ.decode(str);
   1.233 +          mapping.generatedColumn = previousGeneratedColumn + temp.value;
   1.234 +          previousGeneratedColumn = mapping.generatedColumn;
   1.235 +          str = temp.rest;
   1.236 +
   1.237 +          if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
   1.238 +            // Original source.
   1.239 +            temp = base64VLQ.decode(str);
   1.240 +            mapping.source = this._sources.at(previousSource + temp.value);
   1.241 +            previousSource += temp.value;
   1.242 +            str = temp.rest;
   1.243 +            if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
   1.244 +              throw new Error('Found a source, but no line and column');
   1.245 +            }
   1.246 +
   1.247 +            // Original line.
   1.248 +            temp = base64VLQ.decode(str);
   1.249 +            mapping.originalLine = previousOriginalLine + temp.value;
   1.250 +            previousOriginalLine = mapping.originalLine;
   1.251 +            // Lines are stored 0-based
   1.252 +            mapping.originalLine += 1;
   1.253 +            str = temp.rest;
   1.254 +            if (str.length === 0 || mappingSeparator.test(str.charAt(0))) {
   1.255 +              throw new Error('Found a source and line, but no column');
   1.256 +            }
   1.257 +
   1.258 +            // Original column.
   1.259 +            temp = base64VLQ.decode(str);
   1.260 +            mapping.originalColumn = previousOriginalColumn + temp.value;
   1.261 +            previousOriginalColumn = mapping.originalColumn;
   1.262 +            str = temp.rest;
   1.263 +
   1.264 +            if (str.length > 0 && !mappingSeparator.test(str.charAt(0))) {
   1.265 +              // Original name.
   1.266 +              temp = base64VLQ.decode(str);
   1.267 +              mapping.name = this._names.at(previousName + temp.value);
   1.268 +              previousName += temp.value;
   1.269 +              str = temp.rest;
   1.270 +            }
   1.271 +          }
   1.272 +
   1.273 +          this.__generatedMappings.push(mapping);
   1.274 +          if (typeof mapping.originalLine === 'number') {
   1.275 +            this.__originalMappings.push(mapping);
   1.276 +          }
   1.277 +        }
   1.278 +      }
   1.279 +
   1.280 +      this.__originalMappings.sort(util.compareByOriginalPositions);
   1.281 +    };
   1.282 +
   1.283 +  /**
   1.284 +   * Find the mapping that best matches the hypothetical "needle" mapping that
   1.285 +   * we are searching for in the given "haystack" of mappings.
   1.286 +   */
   1.287 +  SourceMapConsumer.prototype._findMapping =
   1.288 +    function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
   1.289 +                                           aColumnName, aComparator) {
   1.290 +      // To return the position we are searching for, we must first find the
   1.291 +      // mapping for the given position and then return the opposite position it
   1.292 +      // points to. Because the mappings are sorted, we can use binary search to
   1.293 +      // find the best mapping.
   1.294 +
   1.295 +      if (aNeedle[aLineName] <= 0) {
   1.296 +        throw new TypeError('Line must be greater than or equal to 1, got '
   1.297 +                            + aNeedle[aLineName]);
   1.298 +      }
   1.299 +      if (aNeedle[aColumnName] < 0) {
   1.300 +        throw new TypeError('Column must be greater than or equal to 0, got '
   1.301 +                            + aNeedle[aColumnName]);
   1.302 +      }
   1.303 +
   1.304 +      return binarySearch.search(aNeedle, aMappings, aComparator);
   1.305 +    };
   1.306 +
   1.307 +  /**
   1.308 +   * Returns the original source, line, and column information for the generated
   1.309 +   * source's line and column positions provided. The only argument is an object
   1.310 +   * with the following properties:
   1.311 +   *
   1.312 +   *   - line: The line number in the generated source.
   1.313 +   *   - column: The column number in the generated source.
   1.314 +   *
   1.315 +   * and an object is returned with the following properties:
   1.316 +   *
   1.317 +   *   - source: The original source file, or null.
   1.318 +   *   - line: The line number in the original source, or null.
   1.319 +   *   - column: The column number in the original source, or null.
   1.320 +   *   - name: The original identifier, or null.
   1.321 +   */
   1.322 +  SourceMapConsumer.prototype.originalPositionFor =
   1.323 +    function SourceMapConsumer_originalPositionFor(aArgs) {
   1.324 +      var needle = {
   1.325 +        generatedLine: util.getArg(aArgs, 'line'),
   1.326 +        generatedColumn: util.getArg(aArgs, 'column')
   1.327 +      };
   1.328 +
   1.329 +      var mapping = this._findMapping(needle,
   1.330 +                                      this._generatedMappings,
   1.331 +                                      "generatedLine",
   1.332 +                                      "generatedColumn",
   1.333 +                                      util.compareByGeneratedPositions);
   1.334 +
   1.335 +      if (mapping) {
   1.336 +        var source = util.getArg(mapping, 'source', null);
   1.337 +        if (source && this.sourceRoot) {
   1.338 +          source = util.join(this.sourceRoot, source);
   1.339 +        }
   1.340 +        return {
   1.341 +          source: source,
   1.342 +          line: util.getArg(mapping, 'originalLine', null),
   1.343 +          column: util.getArg(mapping, 'originalColumn', null),
   1.344 +          name: util.getArg(mapping, 'name', null)
   1.345 +        };
   1.346 +      }
   1.347 +
   1.348 +      return {
   1.349 +        source: null,
   1.350 +        line: null,
   1.351 +        column: null,
   1.352 +        name: null
   1.353 +      };
   1.354 +    };
   1.355 +
   1.356 +  /**
   1.357 +   * Returns the original source content. The only argument is the url of the
   1.358 +   * original source file. Returns null if no original source content is
   1.359 +   * availible.
   1.360 +   */
   1.361 +  SourceMapConsumer.prototype.sourceContentFor =
   1.362 +    function SourceMapConsumer_sourceContentFor(aSource) {
   1.363 +      if (!this.sourcesContent) {
   1.364 +        return null;
   1.365 +      }
   1.366 +
   1.367 +      if (this.sourceRoot) {
   1.368 +        aSource = util.relative(this.sourceRoot, aSource);
   1.369 +      }
   1.370 +
   1.371 +      if (this._sources.has(aSource)) {
   1.372 +        return this.sourcesContent[this._sources.indexOf(aSource)];
   1.373 +      }
   1.374 +
   1.375 +      var url;
   1.376 +      if (this.sourceRoot
   1.377 +          && (url = util.urlParse(this.sourceRoot))) {
   1.378 +        // XXX: file:// URIs and absolute paths lead to unexpected behavior for
   1.379 +        // many users. We can help them out when they expect file:// URIs to
   1.380 +        // behave like it would if they were running a local HTTP server. See
   1.381 +        // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
   1.382 +        var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
   1.383 +        if (url.scheme == "file"
   1.384 +            && this._sources.has(fileUriAbsPath)) {
   1.385 +          return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
   1.386 +        }
   1.387 +
   1.388 +        if ((!url.path || url.path == "/")
   1.389 +            && this._sources.has("/" + aSource)) {
   1.390 +          return this.sourcesContent[this._sources.indexOf("/" + aSource)];
   1.391 +        }
   1.392 +      }
   1.393 +
   1.394 +      throw new Error('"' + aSource + '" is not in the SourceMap.');
   1.395 +    };
   1.396 +
   1.397 +  /**
   1.398 +   * Returns the generated line and column information for the original source,
   1.399 +   * line, and column positions provided. The only argument is an object with
   1.400 +   * the following properties:
   1.401 +   *
   1.402 +   *   - source: The filename of the original source.
   1.403 +   *   - line: The line number in the original source.
   1.404 +   *   - column: The column number in the original source.
   1.405 +   *
   1.406 +   * and an object is returned with the following properties:
   1.407 +   *
   1.408 +   *   - line: The line number in the generated source, or null.
   1.409 +   *   - column: The column number in the generated source, or null.
   1.410 +   */
   1.411 +  SourceMapConsumer.prototype.generatedPositionFor =
   1.412 +    function SourceMapConsumer_generatedPositionFor(aArgs) {
   1.413 +      var needle = {
   1.414 +        source: util.getArg(aArgs, 'source'),
   1.415 +        originalLine: util.getArg(aArgs, 'line'),
   1.416 +        originalColumn: util.getArg(aArgs, 'column')
   1.417 +      };
   1.418 +
   1.419 +      if (this.sourceRoot) {
   1.420 +        needle.source = util.relative(this.sourceRoot, needle.source);
   1.421 +      }
   1.422 +
   1.423 +      var mapping = this._findMapping(needle,
   1.424 +                                      this._originalMappings,
   1.425 +                                      "originalLine",
   1.426 +                                      "originalColumn",
   1.427 +                                      util.compareByOriginalPositions);
   1.428 +
   1.429 +      if (mapping) {
   1.430 +        return {
   1.431 +          line: util.getArg(mapping, 'generatedLine', null),
   1.432 +          column: util.getArg(mapping, 'generatedColumn', null)
   1.433 +        };
   1.434 +      }
   1.435 +
   1.436 +      return {
   1.437 +        line: null,
   1.438 +        column: null
   1.439 +      };
   1.440 +    };
   1.441 +
   1.442 +  SourceMapConsumer.GENERATED_ORDER = 1;
   1.443 +  SourceMapConsumer.ORIGINAL_ORDER = 2;
   1.444 +
   1.445 +  /**
   1.446 +   * Iterate over each mapping between an original source/line/column and a
   1.447 +   * generated line/column in this source map.
   1.448 +   *
   1.449 +   * @param Function aCallback
   1.450 +   *        The function that is called with each mapping.
   1.451 +   * @param Object aContext
   1.452 +   *        Optional. If specified, this object will be the value of `this` every
   1.453 +   *        time that `aCallback` is called.
   1.454 +   * @param aOrder
   1.455 +   *        Either `SourceMapConsumer.GENERATED_ORDER` or
   1.456 +   *        `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
   1.457 +   *        iterate over the mappings sorted by the generated file's line/column
   1.458 +   *        order or the original's source/line/column order, respectively. Defaults to
   1.459 +   *        `SourceMapConsumer.GENERATED_ORDER`.
   1.460 +   */
   1.461 +  SourceMapConsumer.prototype.eachMapping =
   1.462 +    function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
   1.463 +      var context = aContext || null;
   1.464 +      var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
   1.465 +
   1.466 +      var mappings;
   1.467 +      switch (order) {
   1.468 +      case SourceMapConsumer.GENERATED_ORDER:
   1.469 +        mappings = this._generatedMappings;
   1.470 +        break;
   1.471 +      case SourceMapConsumer.ORIGINAL_ORDER:
   1.472 +        mappings = this._originalMappings;
   1.473 +        break;
   1.474 +      default:
   1.475 +        throw new Error("Unknown order of iteration.");
   1.476 +      }
   1.477 +
   1.478 +      var sourceRoot = this.sourceRoot;
   1.479 +      mappings.map(function (mapping) {
   1.480 +        var source = mapping.source;
   1.481 +        if (source && sourceRoot) {
   1.482 +          source = util.join(sourceRoot, source);
   1.483 +        }
   1.484 +        return {
   1.485 +          source: source,
   1.486 +          generatedLine: mapping.generatedLine,
   1.487 +          generatedColumn: mapping.generatedColumn,
   1.488 +          originalLine: mapping.originalLine,
   1.489 +          originalColumn: mapping.originalColumn,
   1.490 +          name: mapping.name
   1.491 +        };
   1.492 +      }).forEach(aCallback, context);
   1.493 +    };
   1.494 +
   1.495 +  exports.SourceMapConsumer = SourceMapConsumer;
   1.496 +
   1.497 +});
   1.498 +/* -*- Mode: js; js-indent-level: 2; -*- */
   1.499 +/*
   1.500 + * Copyright 2011 Mozilla Foundation and contributors
   1.501 + * Licensed under the New BSD license. See LICENSE or:
   1.502 + * http://opensource.org/licenses/BSD-3-Clause
   1.503 + */
   1.504 +define('source-map/util', ['require', 'exports', 'module' , ], function(require, exports, module) {
   1.505 +
   1.506 +  /**
   1.507 +   * This is a helper function for getting values from parameter/options
   1.508 +   * objects.
   1.509 +   *
   1.510 +   * @param args The object we are extracting values from
   1.511 +   * @param name The name of the property we are getting.
   1.512 +   * @param defaultValue An optional value to return if the property is missing
   1.513 +   * from the object. If this is not specified and the property is missing, an
   1.514 +   * error will be thrown.
   1.515 +   */
   1.516 +  function getArg(aArgs, aName, aDefaultValue) {
   1.517 +    if (aName in aArgs) {
   1.518 +      return aArgs[aName];
   1.519 +    } else if (arguments.length === 3) {
   1.520 +      return aDefaultValue;
   1.521 +    } else {
   1.522 +      throw new Error('"' + aName + '" is a required argument.');
   1.523 +    }
   1.524 +  }
   1.525 +  exports.getArg = getArg;
   1.526 +
   1.527 +  var urlRegexp = /([\w+\-.]+):\/\/((\w+:\w+)@)?([\w.]+)?(:(\d+))?(\S+)?/;
   1.528 +  var dataUrlRegexp = /^data:.+\,.+/;
   1.529 +
   1.530 +  function urlParse(aUrl) {
   1.531 +    var match = aUrl.match(urlRegexp);
   1.532 +    if (!match) {
   1.533 +      return null;
   1.534 +    }
   1.535 +    return {
   1.536 +      scheme: match[1],
   1.537 +      auth: match[3],
   1.538 +      host: match[4],
   1.539 +      port: match[6],
   1.540 +      path: match[7]
   1.541 +    };
   1.542 +  }
   1.543 +  exports.urlParse = urlParse;
   1.544 +
   1.545 +  function urlGenerate(aParsedUrl) {
   1.546 +    var url = aParsedUrl.scheme + "://";
   1.547 +    if (aParsedUrl.auth) {
   1.548 +      url += aParsedUrl.auth + "@"
   1.549 +    }
   1.550 +    if (aParsedUrl.host) {
   1.551 +      url += aParsedUrl.host;
   1.552 +    }
   1.553 +    if (aParsedUrl.port) {
   1.554 +      url += ":" + aParsedUrl.port
   1.555 +    }
   1.556 +    if (aParsedUrl.path) {
   1.557 +      url += aParsedUrl.path;
   1.558 +    }
   1.559 +    return url;
   1.560 +  }
   1.561 +  exports.urlGenerate = urlGenerate;
   1.562 +
   1.563 +  function join(aRoot, aPath) {
   1.564 +    var url;
   1.565 +
   1.566 +    if (aPath.match(urlRegexp) || aPath.match(dataUrlRegexp)) {
   1.567 +      return aPath;
   1.568 +    }
   1.569 +
   1.570 +    if (aPath.charAt(0) === '/' && (url = urlParse(aRoot))) {
   1.571 +      url.path = aPath;
   1.572 +      return urlGenerate(url);
   1.573 +    }
   1.574 +
   1.575 +    return aRoot.replace(/\/$/, '') + '/' + aPath;
   1.576 +  }
   1.577 +  exports.join = join;
   1.578 +
   1.579 +  /**
   1.580 +   * Because behavior goes wacky when you set `__proto__` on objects, we
   1.581 +   * have to prefix all the strings in our set with an arbitrary character.
   1.582 +   *
   1.583 +   * See https://github.com/mozilla/source-map/pull/31 and
   1.584 +   * https://github.com/mozilla/source-map/issues/30
   1.585 +   *
   1.586 +   * @param String aStr
   1.587 +   */
   1.588 +  function toSetString(aStr) {
   1.589 +    return '$' + aStr;
   1.590 +  }
   1.591 +  exports.toSetString = toSetString;
   1.592 +
   1.593 +  function fromSetString(aStr) {
   1.594 +    return aStr.substr(1);
   1.595 +  }
   1.596 +  exports.fromSetString = fromSetString;
   1.597 +
   1.598 +  function relative(aRoot, aPath) {
   1.599 +    aRoot = aRoot.replace(/\/$/, '');
   1.600 +
   1.601 +    var url = urlParse(aRoot);
   1.602 +    if (aPath.charAt(0) == "/" && url && url.path == "/") {
   1.603 +      return aPath.slice(1);
   1.604 +    }
   1.605 +
   1.606 +    return aPath.indexOf(aRoot + '/') === 0
   1.607 +      ? aPath.substr(aRoot.length + 1)
   1.608 +      : aPath;
   1.609 +  }
   1.610 +  exports.relative = relative;
   1.611 +
   1.612 +  function strcmp(aStr1, aStr2) {
   1.613 +    var s1 = aStr1 || "";
   1.614 +    var s2 = aStr2 || "";
   1.615 +    return (s1 > s2) - (s1 < s2);
   1.616 +  }
   1.617 +
   1.618 +  /**
   1.619 +   * Comparator between two mappings where the original positions are compared.
   1.620 +   *
   1.621 +   * Optionally pass in `true` as `onlyCompareGenerated` to consider two
   1.622 +   * mappings with the same original source/line/column, but different generated
   1.623 +   * line and column the same. Useful when searching for a mapping with a
   1.624 +   * stubbed out mapping.
   1.625 +   */
   1.626 +  function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
   1.627 +    var cmp;
   1.628 +
   1.629 +    cmp = strcmp(mappingA.source, mappingB.source);
   1.630 +    if (cmp) {
   1.631 +      return cmp;
   1.632 +    }
   1.633 +
   1.634 +    cmp = mappingA.originalLine - mappingB.originalLine;
   1.635 +    if (cmp) {
   1.636 +      return cmp;
   1.637 +    }
   1.638 +
   1.639 +    cmp = mappingA.originalColumn - mappingB.originalColumn;
   1.640 +    if (cmp || onlyCompareOriginal) {
   1.641 +      return cmp;
   1.642 +    }
   1.643 +
   1.644 +    cmp = strcmp(mappingA.name, mappingB.name);
   1.645 +    if (cmp) {
   1.646 +      return cmp;
   1.647 +    }
   1.648 +
   1.649 +    cmp = mappingA.generatedLine - mappingB.generatedLine;
   1.650 +    if (cmp) {
   1.651 +      return cmp;
   1.652 +    }
   1.653 +
   1.654 +    return mappingA.generatedColumn - mappingB.generatedColumn;
   1.655 +  };
   1.656 +  exports.compareByOriginalPositions = compareByOriginalPositions;
   1.657 +
   1.658 +  /**
   1.659 +   * Comparator between two mappings where the generated positions are
   1.660 +   * compared.
   1.661 +   *
   1.662 +   * Optionally pass in `true` as `onlyCompareGenerated` to consider two
   1.663 +   * mappings with the same generated line and column, but different
   1.664 +   * source/name/original line and column the same. Useful when searching for a
   1.665 +   * mapping with a stubbed out mapping.
   1.666 +   */
   1.667 +  function compareByGeneratedPositions(mappingA, mappingB, onlyCompareGenerated) {
   1.668 +    var cmp;
   1.669 +
   1.670 +    cmp = mappingA.generatedLine - mappingB.generatedLine;
   1.671 +    if (cmp) {
   1.672 +      return cmp;
   1.673 +    }
   1.674 +
   1.675 +    cmp = mappingA.generatedColumn - mappingB.generatedColumn;
   1.676 +    if (cmp || onlyCompareGenerated) {
   1.677 +      return cmp;
   1.678 +    }
   1.679 +
   1.680 +    cmp = strcmp(mappingA.source, mappingB.source);
   1.681 +    if (cmp) {
   1.682 +      return cmp;
   1.683 +    }
   1.684 +
   1.685 +    cmp = mappingA.originalLine - mappingB.originalLine;
   1.686 +    if (cmp) {
   1.687 +      return cmp;
   1.688 +    }
   1.689 +
   1.690 +    cmp = mappingA.originalColumn - mappingB.originalColumn;
   1.691 +    if (cmp) {
   1.692 +      return cmp;
   1.693 +    }
   1.694 +
   1.695 +    return strcmp(mappingA.name, mappingB.name);
   1.696 +  };
   1.697 +  exports.compareByGeneratedPositions = compareByGeneratedPositions;
   1.698 +
   1.699 +});
   1.700 +/* -*- Mode: js; js-indent-level: 2; -*- */
   1.701 +/*
   1.702 + * Copyright 2011 Mozilla Foundation and contributors
   1.703 + * Licensed under the New BSD license. See LICENSE or:
   1.704 + * http://opensource.org/licenses/BSD-3-Clause
   1.705 + */
   1.706 +define('source-map/binary-search', ['require', 'exports', 'module' , ], function(require, exports, module) {
   1.707 +
   1.708 +  /**
   1.709 +   * Recursive implementation of binary search.
   1.710 +   *
   1.711 +   * @param aLow Indices here and lower do not contain the needle.
   1.712 +   * @param aHigh Indices here and higher do not contain the needle.
   1.713 +   * @param aNeedle The element being searched for.
   1.714 +   * @param aHaystack The non-empty array being searched.
   1.715 +   * @param aCompare Function which takes two elements and returns -1, 0, or 1.
   1.716 +   */
   1.717 +  function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare) {
   1.718 +    // This function terminates when one of the following is true:
   1.719 +    //
   1.720 +    //   1. We find the exact element we are looking for.
   1.721 +    //
   1.722 +    //   2. We did not find the exact element, but we can return the next
   1.723 +    //      closest element that is less than that element.
   1.724 +    //
   1.725 +    //   3. We did not find the exact element, and there is no next-closest
   1.726 +    //      element which is less than the one we are searching for, so we
   1.727 +    //      return null.
   1.728 +    var mid = Math.floor((aHigh - aLow) / 2) + aLow;
   1.729 +    var cmp = aCompare(aNeedle, aHaystack[mid], true);
   1.730 +    if (cmp === 0) {
   1.731 +      // Found the element we are looking for.
   1.732 +      return aHaystack[mid];
   1.733 +    }
   1.734 +    else if (cmp > 0) {
   1.735 +      // aHaystack[mid] is greater than our needle.
   1.736 +      if (aHigh - mid > 1) {
   1.737 +        // The element is in the upper half.
   1.738 +        return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare);
   1.739 +      }
   1.740 +      // We did not find an exact match, return the next closest one
   1.741 +      // (termination case 2).
   1.742 +      return aHaystack[mid];
   1.743 +    }
   1.744 +    else {
   1.745 +      // aHaystack[mid] is less than our needle.
   1.746 +      if (mid - aLow > 1) {
   1.747 +        // The element is in the lower half.
   1.748 +        return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare);
   1.749 +      }
   1.750 +      // The exact needle element was not found in this haystack. Determine if
   1.751 +      // we are in termination case (2) or (3) and return the appropriate thing.
   1.752 +      return aLow < 0
   1.753 +        ? null
   1.754 +        : aHaystack[aLow];
   1.755 +    }
   1.756 +  }
   1.757 +
   1.758 +  /**
   1.759 +   * This is an implementation of binary search which will always try and return
   1.760 +   * the next lowest value checked if there is no exact hit. This is because
   1.761 +   * mappings between original and generated line/col pairs are single points,
   1.762 +   * and there is an implicit region between each of them, so a miss just means
   1.763 +   * that you aren't on the very start of a region.
   1.764 +   *
   1.765 +   * @param aNeedle The element you are looking for.
   1.766 +   * @param aHaystack The array that is being searched.
   1.767 +   * @param aCompare A function which takes the needle and an element in the
   1.768 +   *     array and returns -1, 0, or 1 depending on whether the needle is less
   1.769 +   *     than, equal to, or greater than the element, respectively.
   1.770 +   */
   1.771 +  exports.search = function search(aNeedle, aHaystack, aCompare) {
   1.772 +    return aHaystack.length > 0
   1.773 +      ? recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, aCompare)
   1.774 +      : null;
   1.775 +  };
   1.776 +
   1.777 +});
   1.778 +/* -*- Mode: js; js-indent-level: 2; -*- */
   1.779 +/*
   1.780 + * Copyright 2011 Mozilla Foundation and contributors
   1.781 + * Licensed under the New BSD license. See LICENSE or:
   1.782 + * http://opensource.org/licenses/BSD-3-Clause
   1.783 + */
   1.784 +define('source-map/array-set', ['require', 'exports', 'module' ,  'source-map/util'], function(require, exports, module) {
   1.785 +
   1.786 +  var util = require('source-map/util');
   1.787 +
   1.788 +  /**
   1.789 +   * A data structure which is a combination of an array and a set. Adding a new
   1.790 +   * member is O(1), testing for membership is O(1), and finding the index of an
   1.791 +   * element is O(1). Removing elements from the set is not supported. Only
   1.792 +   * strings are supported for membership.
   1.793 +   */
   1.794 +  function ArraySet() {
   1.795 +    this._array = [];
   1.796 +    this._set = {};
   1.797 +  }
   1.798 +
   1.799 +  /**
   1.800 +   * Static method for creating ArraySet instances from an existing array.
   1.801 +   */
   1.802 +  ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
   1.803 +    var set = new ArraySet();
   1.804 +    for (var i = 0, len = aArray.length; i < len; i++) {
   1.805 +      set.add(aArray[i], aAllowDuplicates);
   1.806 +    }
   1.807 +    return set;
   1.808 +  };
   1.809 +
   1.810 +  /**
   1.811 +   * Add the given string to this set.
   1.812 +   *
   1.813 +   * @param String aStr
   1.814 +   */
   1.815 +  ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
   1.816 +    var isDuplicate = this.has(aStr);
   1.817 +    var idx = this._array.length;
   1.818 +    if (!isDuplicate || aAllowDuplicates) {
   1.819 +      this._array.push(aStr);
   1.820 +    }
   1.821 +    if (!isDuplicate) {
   1.822 +      this._set[util.toSetString(aStr)] = idx;
   1.823 +    }
   1.824 +  };
   1.825 +
   1.826 +  /**
   1.827 +   * Is the given string a member of this set?
   1.828 +   *
   1.829 +   * @param String aStr
   1.830 +   */
   1.831 +  ArraySet.prototype.has = function ArraySet_has(aStr) {
   1.832 +    return Object.prototype.hasOwnProperty.call(this._set,
   1.833 +                                                util.toSetString(aStr));
   1.834 +  };
   1.835 +
   1.836 +  /**
   1.837 +   * What is the index of the given string in the array?
   1.838 +   *
   1.839 +   * @param String aStr
   1.840 +   */
   1.841 +  ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
   1.842 +    if (this.has(aStr)) {
   1.843 +      return this._set[util.toSetString(aStr)];
   1.844 +    }
   1.845 +    throw new Error('"' + aStr + '" is not in the set.');
   1.846 +  };
   1.847 +
   1.848 +  /**
   1.849 +   * What is the element at the given index?
   1.850 +   *
   1.851 +   * @param Number aIdx
   1.852 +   */
   1.853 +  ArraySet.prototype.at = function ArraySet_at(aIdx) {
   1.854 +    if (aIdx >= 0 && aIdx < this._array.length) {
   1.855 +      return this._array[aIdx];
   1.856 +    }
   1.857 +    throw new Error('No element indexed by ' + aIdx);
   1.858 +  };
   1.859 +
   1.860 +  /**
   1.861 +   * Returns the array representation of this set (which has the proper indices
   1.862 +   * indicated by indexOf). Note that this is a copy of the internal array used
   1.863 +   * for storing the members so that no one can mess with internal state.
   1.864 +   */
   1.865 +  ArraySet.prototype.toArray = function ArraySet_toArray() {
   1.866 +    return this._array.slice();
   1.867 +  };
   1.868 +
   1.869 +  exports.ArraySet = ArraySet;
   1.870 +
   1.871 +});
   1.872 +/* -*- Mode: js; js-indent-level: 2; -*- */
   1.873 +/*
   1.874 + * Copyright 2011 Mozilla Foundation and contributors
   1.875 + * Licensed under the New BSD license. See LICENSE or:
   1.876 + * http://opensource.org/licenses/BSD-3-Clause
   1.877 + *
   1.878 + * Based on the Base 64 VLQ implementation in Closure Compiler:
   1.879 + * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
   1.880 + *
   1.881 + * Copyright 2011 The Closure Compiler Authors. All rights reserved.
   1.882 + * Redistribution and use in source and binary forms, with or without
   1.883 + * modification, are permitted provided that the following conditions are
   1.884 + * met:
   1.885 + *
   1.886 + *  * Redistributions of source code must retain the above copyright
   1.887 + *    notice, this list of conditions and the following disclaimer.
   1.888 + *  * Redistributions in binary form must reproduce the above
   1.889 + *    copyright notice, this list of conditions and the following
   1.890 + *    disclaimer in the documentation and/or other materials provided
   1.891 + *    with the distribution.
   1.892 + *  * Neither the name of Google Inc. nor the names of its
   1.893 + *    contributors may be used to endorse or promote products derived
   1.894 + *    from this software without specific prior written permission.
   1.895 + *
   1.896 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   1.897 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   1.898 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   1.899 + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   1.900 + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   1.901 + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   1.902 + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
   1.903 + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
   1.904 + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   1.905 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   1.906 + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   1.907 + */
   1.908 +define('source-map/base64-vlq', ['require', 'exports', 'module' ,  'source-map/base64'], function(require, exports, module) {
   1.909 +
   1.910 +  var base64 = require('source-map/base64');
   1.911 +
   1.912 +  // A single base 64 digit can contain 6 bits of data. For the base 64 variable
   1.913 +  // length quantities we use in the source map spec, the first bit is the sign,
   1.914 +  // the next four bits are the actual value, and the 6th bit is the
   1.915 +  // continuation bit. The continuation bit tells us whether there are more
   1.916 +  // digits in this value following this digit.
   1.917 +  //
   1.918 +  //   Continuation
   1.919 +  //   |    Sign
   1.920 +  //   |    |
   1.921 +  //   V    V
   1.922 +  //   101011
   1.923 +
   1.924 +  var VLQ_BASE_SHIFT = 5;
   1.925 +
   1.926 +  // binary: 100000
   1.927 +  var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
   1.928 +
   1.929 +  // binary: 011111
   1.930 +  var VLQ_BASE_MASK = VLQ_BASE - 1;
   1.931 +
   1.932 +  // binary: 100000
   1.933 +  var VLQ_CONTINUATION_BIT = VLQ_BASE;
   1.934 +
   1.935 +  /**
   1.936 +   * Converts from a two-complement value to a value where the sign bit is
   1.937 +   * is placed in the least significant bit.  For example, as decimals:
   1.938 +   *   1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
   1.939 +   *   2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
   1.940 +   */
   1.941 +  function toVLQSigned(aValue) {
   1.942 +    return aValue < 0
   1.943 +      ? ((-aValue) << 1) + 1
   1.944 +      : (aValue << 1) + 0;
   1.945 +  }
   1.946 +
   1.947 +  /**
   1.948 +   * Converts to a two-complement value from a value where the sign bit is
   1.949 +   * is placed in the least significant bit.  For example, as decimals:
   1.950 +   *   2 (10 binary) becomes 1, 3 (11 binary) becomes -1
   1.951 +   *   4 (100 binary) becomes 2, 5 (101 binary) becomes -2
   1.952 +   */
   1.953 +  function fromVLQSigned(aValue) {
   1.954 +    var isNegative = (aValue & 1) === 1;
   1.955 +    var shifted = aValue >> 1;
   1.956 +    return isNegative
   1.957 +      ? -shifted
   1.958 +      : shifted;
   1.959 +  }
   1.960 +
   1.961 +  /**
   1.962 +   * Returns the base 64 VLQ encoded value.
   1.963 +   */
   1.964 +  exports.encode = function base64VLQ_encode(aValue) {
   1.965 +    var encoded = "";
   1.966 +    var digit;
   1.967 +
   1.968 +    var vlq = toVLQSigned(aValue);
   1.969 +
   1.970 +    do {
   1.971 +      digit = vlq & VLQ_BASE_MASK;
   1.972 +      vlq >>>= VLQ_BASE_SHIFT;
   1.973 +      if (vlq > 0) {
   1.974 +        // There are still more digits in this value, so we must make sure the
   1.975 +        // continuation bit is marked.
   1.976 +        digit |= VLQ_CONTINUATION_BIT;
   1.977 +      }
   1.978 +      encoded += base64.encode(digit);
   1.979 +    } while (vlq > 0);
   1.980 +
   1.981 +    return encoded;
   1.982 +  };
   1.983 +
   1.984 +  /**
   1.985 +   * Decodes the next base 64 VLQ value from the given string and returns the
   1.986 +   * value and the rest of the string.
   1.987 +   */
   1.988 +  exports.decode = function base64VLQ_decode(aStr) {
   1.989 +    var i = 0;
   1.990 +    var strLen = aStr.length;
   1.991 +    var result = 0;
   1.992 +    var shift = 0;
   1.993 +    var continuation, digit;
   1.994 +
   1.995 +    do {
   1.996 +      if (i >= strLen) {
   1.997 +        throw new Error("Expected more digits in base 64 VLQ value.");
   1.998 +      }
   1.999 +      digit = base64.decode(aStr.charAt(i++));
  1.1000 +      continuation = !!(digit & VLQ_CONTINUATION_BIT);
  1.1001 +      digit &= VLQ_BASE_MASK;
  1.1002 +      result = result + (digit << shift);
  1.1003 +      shift += VLQ_BASE_SHIFT;
  1.1004 +    } while (continuation);
  1.1005 +
  1.1006 +    return {
  1.1007 +      value: fromVLQSigned(result),
  1.1008 +      rest: aStr.slice(i)
  1.1009 +    };
  1.1010 +  };
  1.1011 +
  1.1012 +});
  1.1013 +/* -*- Mode: js; js-indent-level: 2; -*- */
  1.1014 +/*
  1.1015 + * Copyright 2011 Mozilla Foundation and contributors
  1.1016 + * Licensed under the New BSD license. See LICENSE or:
  1.1017 + * http://opensource.org/licenses/BSD-3-Clause
  1.1018 + */
  1.1019 +define('source-map/base64', ['require', 'exports', 'module' , ], function(require, exports, module) {
  1.1020 +
  1.1021 +  var charToIntMap = {};
  1.1022 +  var intToCharMap = {};
  1.1023 +
  1.1024 +  'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
  1.1025 +    .split('')
  1.1026 +    .forEach(function (ch, index) {
  1.1027 +      charToIntMap[ch] = index;
  1.1028 +      intToCharMap[index] = ch;
  1.1029 +    });
  1.1030 +
  1.1031 +  /**
  1.1032 +   * Encode an integer in the range of 0 to 63 to a single base 64 digit.
  1.1033 +   */
  1.1034 +  exports.encode = function base64_encode(aNumber) {
  1.1035 +    if (aNumber in intToCharMap) {
  1.1036 +      return intToCharMap[aNumber];
  1.1037 +    }
  1.1038 +    throw new TypeError("Must be between 0 and 63: " + aNumber);
  1.1039 +  };
  1.1040 +
  1.1041 +  /**
  1.1042 +   * Decode a single base 64 digit to an integer.
  1.1043 +   */
  1.1044 +  exports.decode = function base64_decode(aChar) {
  1.1045 +    if (aChar in charToIntMap) {
  1.1046 +      return charToIntMap[aChar];
  1.1047 +    }
  1.1048 +    throw new TypeError("Not a valid base 64 digit: " + aChar);
  1.1049 +  };
  1.1050 +
  1.1051 +});
  1.1052 +/* -*- Mode: js; js-indent-level: 2; -*- */
  1.1053 +/*
  1.1054 + * Copyright 2011 Mozilla Foundation and contributors
  1.1055 + * Licensed under the New BSD license. See LICENSE or:
  1.1056 + * http://opensource.org/licenses/BSD-3-Clause
  1.1057 + */
  1.1058 +define('source-map/source-map-generator', ['require', 'exports', 'module' ,  'source-map/base64-vlq', 'source-map/util', 'source-map/array-set'], function(require, exports, module) {
  1.1059 +
  1.1060 +  var base64VLQ = require('source-map/base64-vlq');
  1.1061 +  var util = require('source-map/util');
  1.1062 +  var ArraySet = require('source-map/array-set').ArraySet;
  1.1063 +
  1.1064 +  /**
  1.1065 +   * An instance of the SourceMapGenerator represents a source map which is
  1.1066 +   * being built incrementally. To create a new one, you must pass an object
  1.1067 +   * with the following properties:
  1.1068 +   *
  1.1069 +   *   - file: The filename of the generated source.
  1.1070 +   *   - sourceRoot: An optional root for all URLs in this source map.
  1.1071 +   */
  1.1072 +  function SourceMapGenerator(aArgs) {
  1.1073 +    this._file = util.getArg(aArgs, 'file');
  1.1074 +    this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null);
  1.1075 +    this._sources = new ArraySet();
  1.1076 +    this._names = new ArraySet();
  1.1077 +    this._mappings = [];
  1.1078 +    this._sourcesContents = null;
  1.1079 +  }
  1.1080 +
  1.1081 +  SourceMapGenerator.prototype._version = 3;
  1.1082 +
  1.1083 +  /**
  1.1084 +   * Creates a new SourceMapGenerator based on a SourceMapConsumer
  1.1085 +   *
  1.1086 +   * @param aSourceMapConsumer The SourceMap.
  1.1087 +   */
  1.1088 +  SourceMapGenerator.fromSourceMap =
  1.1089 +    function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
  1.1090 +      var sourceRoot = aSourceMapConsumer.sourceRoot;
  1.1091 +      var generator = new SourceMapGenerator({
  1.1092 +        file: aSourceMapConsumer.file,
  1.1093 +        sourceRoot: sourceRoot
  1.1094 +      });
  1.1095 +      aSourceMapConsumer.eachMapping(function (mapping) {
  1.1096 +        var newMapping = {
  1.1097 +          generated: {
  1.1098 +            line: mapping.generatedLine,
  1.1099 +            column: mapping.generatedColumn
  1.1100 +          }
  1.1101 +        };
  1.1102 +
  1.1103 +        if (mapping.source) {
  1.1104 +          newMapping.source = mapping.source;
  1.1105 +          if (sourceRoot) {
  1.1106 +            newMapping.source = util.relative(sourceRoot, newMapping.source);
  1.1107 +          }
  1.1108 +
  1.1109 +          newMapping.original = {
  1.1110 +            line: mapping.originalLine,
  1.1111 +            column: mapping.originalColumn
  1.1112 +          };
  1.1113 +
  1.1114 +          if (mapping.name) {
  1.1115 +            newMapping.name = mapping.name;
  1.1116 +          }
  1.1117 +        }
  1.1118 +
  1.1119 +        generator.addMapping(newMapping);
  1.1120 +      });
  1.1121 +      aSourceMapConsumer.sources.forEach(function (sourceFile) {
  1.1122 +        var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  1.1123 +        if (content) {
  1.1124 +          generator.setSourceContent(sourceFile, content);
  1.1125 +        }
  1.1126 +      });
  1.1127 +      return generator;
  1.1128 +    };
  1.1129 +
  1.1130 +  /**
  1.1131 +   * Add a single mapping from original source line and column to the generated
  1.1132 +   * source's line and column for this source map being created. The mapping
  1.1133 +   * object should have the following properties:
  1.1134 +   *
  1.1135 +   *   - generated: An object with the generated line and column positions.
  1.1136 +   *   - original: An object with the original line and column positions.
  1.1137 +   *   - source: The original source file (relative to the sourceRoot).
  1.1138 +   *   - name: An optional original token name for this mapping.
  1.1139 +   */
  1.1140 +  SourceMapGenerator.prototype.addMapping =
  1.1141 +    function SourceMapGenerator_addMapping(aArgs) {
  1.1142 +      var generated = util.getArg(aArgs, 'generated');
  1.1143 +      var original = util.getArg(aArgs, 'original', null);
  1.1144 +      var source = util.getArg(aArgs, 'source', null);
  1.1145 +      var name = util.getArg(aArgs, 'name', null);
  1.1146 +
  1.1147 +      this._validateMapping(generated, original, source, name);
  1.1148 +
  1.1149 +      if (source && !this._sources.has(source)) {
  1.1150 +        this._sources.add(source);
  1.1151 +      }
  1.1152 +
  1.1153 +      if (name && !this._names.has(name)) {
  1.1154 +        this._names.add(name);
  1.1155 +      }
  1.1156 +
  1.1157 +      this._mappings.push({
  1.1158 +        generatedLine: generated.line,
  1.1159 +        generatedColumn: generated.column,
  1.1160 +        originalLine: original != null && original.line,
  1.1161 +        originalColumn: original != null && original.column,
  1.1162 +        source: source,
  1.1163 +        name: name
  1.1164 +      });
  1.1165 +    };
  1.1166 +
  1.1167 +  /**
  1.1168 +   * Set the source content for a source file.
  1.1169 +   */
  1.1170 +  SourceMapGenerator.prototype.setSourceContent =
  1.1171 +    function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
  1.1172 +      var source = aSourceFile;
  1.1173 +      if (this._sourceRoot) {
  1.1174 +        source = util.relative(this._sourceRoot, source);
  1.1175 +      }
  1.1176 +
  1.1177 +      if (aSourceContent !== null) {
  1.1178 +        // Add the source content to the _sourcesContents map.
  1.1179 +        // Create a new _sourcesContents map if the property is null.
  1.1180 +        if (!this._sourcesContents) {
  1.1181 +          this._sourcesContents = {};
  1.1182 +        }
  1.1183 +        this._sourcesContents[util.toSetString(source)] = aSourceContent;
  1.1184 +      } else {
  1.1185 +        // Remove the source file from the _sourcesContents map.
  1.1186 +        // If the _sourcesContents map is empty, set the property to null.
  1.1187 +        delete this._sourcesContents[util.toSetString(source)];
  1.1188 +        if (Object.keys(this._sourcesContents).length === 0) {
  1.1189 +          this._sourcesContents = null;
  1.1190 +        }
  1.1191 +      }
  1.1192 +    };
  1.1193 +
  1.1194 +  /**
  1.1195 +   * Applies the mappings of a sub-source-map for a specific source file to the
  1.1196 +   * source map being generated. Each mapping to the supplied source file is
  1.1197 +   * rewritten using the supplied source map. Note: The resolution for the
  1.1198 +   * resulting mappings is the minimium of this map and the supplied map.
  1.1199 +   *
  1.1200 +   * @param aSourceMapConsumer The source map to be applied.
  1.1201 +   * @param aSourceFile Optional. The filename of the source file.
  1.1202 +   *        If omitted, SourceMapConsumer's file property will be used.
  1.1203 +   */
  1.1204 +  SourceMapGenerator.prototype.applySourceMap =
  1.1205 +    function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile) {
  1.1206 +      // If aSourceFile is omitted, we will use the file property of the SourceMap
  1.1207 +      if (!aSourceFile) {
  1.1208 +        aSourceFile = aSourceMapConsumer.file;
  1.1209 +      }
  1.1210 +      var sourceRoot = this._sourceRoot;
  1.1211 +      // Make "aSourceFile" relative if an absolute Url is passed.
  1.1212 +      if (sourceRoot) {
  1.1213 +        aSourceFile = util.relative(sourceRoot, aSourceFile);
  1.1214 +      }
  1.1215 +      // Applying the SourceMap can add and remove items from the sources and
  1.1216 +      // the names array.
  1.1217 +      var newSources = new ArraySet();
  1.1218 +      var newNames = new ArraySet();
  1.1219 +
  1.1220 +      // Find mappings for the "aSourceFile"
  1.1221 +      this._mappings.forEach(function (mapping) {
  1.1222 +        if (mapping.source === aSourceFile && mapping.originalLine) {
  1.1223 +          // Check if it can be mapped by the source map, then update the mapping.
  1.1224 +          var original = aSourceMapConsumer.originalPositionFor({
  1.1225 +            line: mapping.originalLine,
  1.1226 +            column: mapping.originalColumn
  1.1227 +          });
  1.1228 +          if (original.source !== null) {
  1.1229 +            // Copy mapping
  1.1230 +            if (sourceRoot) {
  1.1231 +              mapping.source = util.relative(sourceRoot, original.source);
  1.1232 +            } else {
  1.1233 +              mapping.source = original.source;
  1.1234 +            }
  1.1235 +            mapping.originalLine = original.line;
  1.1236 +            mapping.originalColumn = original.column;
  1.1237 +            if (original.name !== null && mapping.name !== null) {
  1.1238 +              // Only use the identifier name if it's an identifier
  1.1239 +              // in both SourceMaps
  1.1240 +              mapping.name = original.name;
  1.1241 +            }
  1.1242 +          }
  1.1243 +        }
  1.1244 +
  1.1245 +        var source = mapping.source;
  1.1246 +        if (source && !newSources.has(source)) {
  1.1247 +          newSources.add(source);
  1.1248 +        }
  1.1249 +
  1.1250 +        var name = mapping.name;
  1.1251 +        if (name && !newNames.has(name)) {
  1.1252 +          newNames.add(name);
  1.1253 +        }
  1.1254 +
  1.1255 +      }, this);
  1.1256 +      this._sources = newSources;
  1.1257 +      this._names = newNames;
  1.1258 +
  1.1259 +      // Copy sourcesContents of applied map.
  1.1260 +      aSourceMapConsumer.sources.forEach(function (sourceFile) {
  1.1261 +        var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  1.1262 +        if (content) {
  1.1263 +          if (sourceRoot) {
  1.1264 +            sourceFile = util.relative(sourceRoot, sourceFile);
  1.1265 +          }
  1.1266 +          this.setSourceContent(sourceFile, content);
  1.1267 +        }
  1.1268 +      }, this);
  1.1269 +    };
  1.1270 +
  1.1271 +  /**
  1.1272 +   * A mapping can have one of the three levels of data:
  1.1273 +   *
  1.1274 +   *   1. Just the generated position.
  1.1275 +   *   2. The Generated position, original position, and original source.
  1.1276 +   *   3. Generated and original position, original source, as well as a name
  1.1277 +   *      token.
  1.1278 +   *
  1.1279 +   * To maintain consistency, we validate that any new mapping being added falls
  1.1280 +   * in to one of these categories.
  1.1281 +   */
  1.1282 +  SourceMapGenerator.prototype._validateMapping =
  1.1283 +    function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
  1.1284 +                                                aName) {
  1.1285 +      if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  1.1286 +          && aGenerated.line > 0 && aGenerated.column >= 0
  1.1287 +          && !aOriginal && !aSource && !aName) {
  1.1288 +        // Case 1.
  1.1289 +        return;
  1.1290 +      }
  1.1291 +      else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
  1.1292 +               && aOriginal && 'line' in aOriginal && 'column' in aOriginal
  1.1293 +               && aGenerated.line > 0 && aGenerated.column >= 0
  1.1294 +               && aOriginal.line > 0 && aOriginal.column >= 0
  1.1295 +               && aSource) {
  1.1296 +        // Cases 2 and 3.
  1.1297 +        return;
  1.1298 +      }
  1.1299 +      else {
  1.1300 +        throw new Error('Invalid mapping: ' + JSON.stringify({
  1.1301 +          generated: aGenerated,
  1.1302 +          source: aSource,
  1.1303 +          original: aOriginal,
  1.1304 +          name: aName
  1.1305 +        }));
  1.1306 +      }
  1.1307 +    };
  1.1308 +
  1.1309 +  /**
  1.1310 +   * Serialize the accumulated mappings in to the stream of base 64 VLQs
  1.1311 +   * specified by the source map format.
  1.1312 +   */
  1.1313 +  SourceMapGenerator.prototype._serializeMappings =
  1.1314 +    function SourceMapGenerator_serializeMappings() {
  1.1315 +      var previousGeneratedColumn = 0;
  1.1316 +      var previousGeneratedLine = 1;
  1.1317 +      var previousOriginalColumn = 0;
  1.1318 +      var previousOriginalLine = 0;
  1.1319 +      var previousName = 0;
  1.1320 +      var previousSource = 0;
  1.1321 +      var result = '';
  1.1322 +      var mapping;
  1.1323 +
  1.1324 +      // The mappings must be guaranteed to be in sorted order before we start
  1.1325 +      // serializing them or else the generated line numbers (which are defined
  1.1326 +      // via the ';' separators) will be all messed up. Note: it might be more
  1.1327 +      // performant to maintain the sorting as we insert them, rather than as we
  1.1328 +      // serialize them, but the big O is the same either way.
  1.1329 +      this._mappings.sort(util.compareByGeneratedPositions);
  1.1330 +
  1.1331 +      for (var i = 0, len = this._mappings.length; i < len; i++) {
  1.1332 +        mapping = this._mappings[i];
  1.1333 +
  1.1334 +        if (mapping.generatedLine !== previousGeneratedLine) {
  1.1335 +          previousGeneratedColumn = 0;
  1.1336 +          while (mapping.generatedLine !== previousGeneratedLine) {
  1.1337 +            result += ';';
  1.1338 +            previousGeneratedLine++;
  1.1339 +          }
  1.1340 +        }
  1.1341 +        else {
  1.1342 +          if (i > 0) {
  1.1343 +            if (!util.compareByGeneratedPositions(mapping, this._mappings[i - 1])) {
  1.1344 +              continue;
  1.1345 +            }
  1.1346 +            result += ',';
  1.1347 +          }
  1.1348 +        }
  1.1349 +
  1.1350 +        result += base64VLQ.encode(mapping.generatedColumn
  1.1351 +                                   - previousGeneratedColumn);
  1.1352 +        previousGeneratedColumn = mapping.generatedColumn;
  1.1353 +
  1.1354 +        if (mapping.source) {
  1.1355 +          result += base64VLQ.encode(this._sources.indexOf(mapping.source)
  1.1356 +                                     - previousSource);
  1.1357 +          previousSource = this._sources.indexOf(mapping.source);
  1.1358 +
  1.1359 +          // lines are stored 0-based in SourceMap spec version 3
  1.1360 +          result += base64VLQ.encode(mapping.originalLine - 1
  1.1361 +                                     - previousOriginalLine);
  1.1362 +          previousOriginalLine = mapping.originalLine - 1;
  1.1363 +
  1.1364 +          result += base64VLQ.encode(mapping.originalColumn
  1.1365 +                                     - previousOriginalColumn);
  1.1366 +          previousOriginalColumn = mapping.originalColumn;
  1.1367 +
  1.1368 +          if (mapping.name) {
  1.1369 +            result += base64VLQ.encode(this._names.indexOf(mapping.name)
  1.1370 +                                       - previousName);
  1.1371 +            previousName = this._names.indexOf(mapping.name);
  1.1372 +          }
  1.1373 +        }
  1.1374 +      }
  1.1375 +
  1.1376 +      return result;
  1.1377 +    };
  1.1378 +
  1.1379 +  SourceMapGenerator.prototype._generateSourcesContent =
  1.1380 +    function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
  1.1381 +      return aSources.map(function (source) {
  1.1382 +        if (!this._sourcesContents) {
  1.1383 +          return null;
  1.1384 +        }
  1.1385 +        if (aSourceRoot) {
  1.1386 +          source = util.relative(aSourceRoot, source);
  1.1387 +        }
  1.1388 +        var key = util.toSetString(source);
  1.1389 +        return Object.prototype.hasOwnProperty.call(this._sourcesContents,
  1.1390 +                                                    key)
  1.1391 +          ? this._sourcesContents[key]
  1.1392 +          : null;
  1.1393 +      }, this);
  1.1394 +    };
  1.1395 +
  1.1396 +  /**
  1.1397 +   * Externalize the source map.
  1.1398 +   */
  1.1399 +  SourceMapGenerator.prototype.toJSON =
  1.1400 +    function SourceMapGenerator_toJSON() {
  1.1401 +      var map = {
  1.1402 +        version: this._version,
  1.1403 +        file: this._file,
  1.1404 +        sources: this._sources.toArray(),
  1.1405 +        names: this._names.toArray(),
  1.1406 +        mappings: this._serializeMappings()
  1.1407 +      };
  1.1408 +      if (this._sourceRoot) {
  1.1409 +        map.sourceRoot = this._sourceRoot;
  1.1410 +      }
  1.1411 +      if (this._sourcesContents) {
  1.1412 +        map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
  1.1413 +      }
  1.1414 +
  1.1415 +      return map;
  1.1416 +    };
  1.1417 +
  1.1418 +  /**
  1.1419 +   * Render the source map being generated to a string.
  1.1420 +   */
  1.1421 +  SourceMapGenerator.prototype.toString =
  1.1422 +    function SourceMapGenerator_toString() {
  1.1423 +      return JSON.stringify(this);
  1.1424 +    };
  1.1425 +
  1.1426 +  exports.SourceMapGenerator = SourceMapGenerator;
  1.1427 +
  1.1428 +});
  1.1429 +/* -*- Mode: js; js-indent-level: 2; -*- */
  1.1430 +/*
  1.1431 + * Copyright 2011 Mozilla Foundation and contributors
  1.1432 + * Licensed under the New BSD license. See LICENSE or:
  1.1433 + * http://opensource.org/licenses/BSD-3-Clause
  1.1434 + */
  1.1435 +define('source-map/source-node', ['require', 'exports', 'module' ,  'source-map/source-map-generator', 'source-map/util'], function(require, exports, module) {
  1.1436 +
  1.1437 +  var SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
  1.1438 +  var util = require('source-map/util');
  1.1439 +
  1.1440 +  /**
  1.1441 +   * SourceNodes provide a way to abstract over interpolating/concatenating
  1.1442 +   * snippets of generated JavaScript source code while maintaining the line and
  1.1443 +   * column information associated with the original source code.
  1.1444 +   *
  1.1445 +   * @param aLine The original line number.
  1.1446 +   * @param aColumn The original column number.
  1.1447 +   * @param aSource The original source's filename.
  1.1448 +   * @param aChunks Optional. An array of strings which are snippets of
  1.1449 +   *        generated JS, or other SourceNodes.
  1.1450 +   * @param aName The original identifier.
  1.1451 +   */
  1.1452 +  function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
  1.1453 +    this.children = [];
  1.1454 +    this.sourceContents = {};
  1.1455 +    this.line = aLine === undefined ? null : aLine;
  1.1456 +    this.column = aColumn === undefined ? null : aColumn;
  1.1457 +    this.source = aSource === undefined ? null : aSource;
  1.1458 +    this.name = aName === undefined ? null : aName;
  1.1459 +    if (aChunks != null) this.add(aChunks);
  1.1460 +  }
  1.1461 +
  1.1462 +  /**
  1.1463 +   * Creates a SourceNode from generated code and a SourceMapConsumer.
  1.1464 +   *
  1.1465 +   * @param aGeneratedCode The generated code
  1.1466 +   * @param aSourceMapConsumer The SourceMap for the generated code
  1.1467 +   */
  1.1468 +  SourceNode.fromStringWithSourceMap =
  1.1469 +    function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer) {
  1.1470 +      // The SourceNode we want to fill with the generated code
  1.1471 +      // and the SourceMap
  1.1472 +      var node = new SourceNode();
  1.1473 +
  1.1474 +      // The generated code
  1.1475 +      // Processed fragments are removed from this array.
  1.1476 +      var remainingLines = aGeneratedCode.split('\n');
  1.1477 +
  1.1478 +      // We need to remember the position of "remainingLines"
  1.1479 +      var lastGeneratedLine = 1, lastGeneratedColumn = 0;
  1.1480 +
  1.1481 +      // The generate SourceNodes we need a code range.
  1.1482 +      // To extract it current and last mapping is used.
  1.1483 +      // Here we store the last mapping.
  1.1484 +      var lastMapping = null;
  1.1485 +
  1.1486 +      aSourceMapConsumer.eachMapping(function (mapping) {
  1.1487 +        if (lastMapping === null) {
  1.1488 +          // We add the generated code until the first mapping
  1.1489 +          // to the SourceNode without any mapping.
  1.1490 +          // Each line is added as separate string.
  1.1491 +          while (lastGeneratedLine < mapping.generatedLine) {
  1.1492 +            node.add(remainingLines.shift() + "\n");
  1.1493 +            lastGeneratedLine++;
  1.1494 +          }
  1.1495 +          if (lastGeneratedColumn < mapping.generatedColumn) {
  1.1496 +            var nextLine = remainingLines[0];
  1.1497 +            node.add(nextLine.substr(0, mapping.generatedColumn));
  1.1498 +            remainingLines[0] = nextLine.substr(mapping.generatedColumn);
  1.1499 +            lastGeneratedColumn = mapping.generatedColumn;
  1.1500 +          }
  1.1501 +        } else {
  1.1502 +          // We add the code from "lastMapping" to "mapping":
  1.1503 +          // First check if there is a new line in between.
  1.1504 +          if (lastGeneratedLine < mapping.generatedLine) {
  1.1505 +            var code = "";
  1.1506 +            // Associate full lines with "lastMapping"
  1.1507 +            do {
  1.1508 +              code += remainingLines.shift() + "\n";
  1.1509 +              lastGeneratedLine++;
  1.1510 +              lastGeneratedColumn = 0;
  1.1511 +            } while (lastGeneratedLine < mapping.generatedLine);
  1.1512 +            // When we reached the correct line, we add code until we
  1.1513 +            // reach the correct column too.
  1.1514 +            if (lastGeneratedColumn < mapping.generatedColumn) {
  1.1515 +              var nextLine = remainingLines[0];
  1.1516 +              code += nextLine.substr(0, mapping.generatedColumn);
  1.1517 +              remainingLines[0] = nextLine.substr(mapping.generatedColumn);
  1.1518 +              lastGeneratedColumn = mapping.generatedColumn;
  1.1519 +            }
  1.1520 +            // Create the SourceNode.
  1.1521 +            addMappingWithCode(lastMapping, code);
  1.1522 +          } else {
  1.1523 +            // There is no new line in between.
  1.1524 +            // Associate the code between "lastGeneratedColumn" and
  1.1525 +            // "mapping.generatedColumn" with "lastMapping"
  1.1526 +            var nextLine = remainingLines[0];
  1.1527 +            var code = nextLine.substr(0, mapping.generatedColumn -
  1.1528 +                                          lastGeneratedColumn);
  1.1529 +            remainingLines[0] = nextLine.substr(mapping.generatedColumn -
  1.1530 +                                                lastGeneratedColumn);
  1.1531 +            lastGeneratedColumn = mapping.generatedColumn;
  1.1532 +            addMappingWithCode(lastMapping, code);
  1.1533 +          }
  1.1534 +        }
  1.1535 +        lastMapping = mapping;
  1.1536 +      }, this);
  1.1537 +      // We have processed all mappings.
  1.1538 +      // Associate the remaining code in the current line with "lastMapping"
  1.1539 +      // and add the remaining lines without any mapping
  1.1540 +      addMappingWithCode(lastMapping, remainingLines.join("\n"));
  1.1541 +
  1.1542 +      // Copy sourcesContent into SourceNode
  1.1543 +      aSourceMapConsumer.sources.forEach(function (sourceFile) {
  1.1544 +        var content = aSourceMapConsumer.sourceContentFor(sourceFile);
  1.1545 +        if (content) {
  1.1546 +          node.setSourceContent(sourceFile, content);
  1.1547 +        }
  1.1548 +      });
  1.1549 +
  1.1550 +      return node;
  1.1551 +
  1.1552 +      function addMappingWithCode(mapping, code) {
  1.1553 +        if (mapping === null || mapping.source === undefined) {
  1.1554 +          node.add(code);
  1.1555 +        } else {
  1.1556 +          node.add(new SourceNode(mapping.originalLine,
  1.1557 +                                  mapping.originalColumn,
  1.1558 +                                  mapping.source,
  1.1559 +                                  code,
  1.1560 +                                  mapping.name));
  1.1561 +        }
  1.1562 +      }
  1.1563 +    };
  1.1564 +
  1.1565 +  /**
  1.1566 +   * Add a chunk of generated JS to this source node.
  1.1567 +   *
  1.1568 +   * @param aChunk A string snippet of generated JS code, another instance of
  1.1569 +   *        SourceNode, or an array where each member is one of those things.
  1.1570 +   */
  1.1571 +  SourceNode.prototype.add = function SourceNode_add(aChunk) {
  1.1572 +    if (Array.isArray(aChunk)) {
  1.1573 +      aChunk.forEach(function (chunk) {
  1.1574 +        this.add(chunk);
  1.1575 +      }, this);
  1.1576 +    }
  1.1577 +    else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
  1.1578 +      if (aChunk) {
  1.1579 +        this.children.push(aChunk);
  1.1580 +      }
  1.1581 +    }
  1.1582 +    else {
  1.1583 +      throw new TypeError(
  1.1584 +        "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  1.1585 +      );
  1.1586 +    }
  1.1587 +    return this;
  1.1588 +  };
  1.1589 +
  1.1590 +  /**
  1.1591 +   * Add a chunk of generated JS to the beginning of this source node.
  1.1592 +   *
  1.1593 +   * @param aChunk A string snippet of generated JS code, another instance of
  1.1594 +   *        SourceNode, or an array where each member is one of those things.
  1.1595 +   */
  1.1596 +  SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
  1.1597 +    if (Array.isArray(aChunk)) {
  1.1598 +      for (var i = aChunk.length-1; i >= 0; i--) {
  1.1599 +        this.prepend(aChunk[i]);
  1.1600 +      }
  1.1601 +    }
  1.1602 +    else if (aChunk instanceof SourceNode || typeof aChunk === "string") {
  1.1603 +      this.children.unshift(aChunk);
  1.1604 +    }
  1.1605 +    else {
  1.1606 +      throw new TypeError(
  1.1607 +        "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
  1.1608 +      );
  1.1609 +    }
  1.1610 +    return this;
  1.1611 +  };
  1.1612 +
  1.1613 +  /**
  1.1614 +   * Walk over the tree of JS snippets in this node and its children. The
  1.1615 +   * walking function is called once for each snippet of JS and is passed that
  1.1616 +   * snippet and the its original associated source's line/column location.
  1.1617 +   *
  1.1618 +   * @param aFn The traversal function.
  1.1619 +   */
  1.1620 +  SourceNode.prototype.walk = function SourceNode_walk(aFn) {
  1.1621 +    var chunk;
  1.1622 +    for (var i = 0, len = this.children.length; i < len; i++) {
  1.1623 +      chunk = this.children[i];
  1.1624 +      if (chunk instanceof SourceNode) {
  1.1625 +        chunk.walk(aFn);
  1.1626 +      }
  1.1627 +      else {
  1.1628 +        if (chunk !== '') {
  1.1629 +          aFn(chunk, { source: this.source,
  1.1630 +                       line: this.line,
  1.1631 +                       column: this.column,
  1.1632 +                       name: this.name });
  1.1633 +        }
  1.1634 +      }
  1.1635 +    }
  1.1636 +  };
  1.1637 +
  1.1638 +  /**
  1.1639 +   * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
  1.1640 +   * each of `this.children`.
  1.1641 +   *
  1.1642 +   * @param aSep The separator.
  1.1643 +   */
  1.1644 +  SourceNode.prototype.join = function SourceNode_join(aSep) {
  1.1645 +    var newChildren;
  1.1646 +    var i;
  1.1647 +    var len = this.children.length;
  1.1648 +    if (len > 0) {
  1.1649 +      newChildren = [];
  1.1650 +      for (i = 0; i < len-1; i++) {
  1.1651 +        newChildren.push(this.children[i]);
  1.1652 +        newChildren.push(aSep);
  1.1653 +      }
  1.1654 +      newChildren.push(this.children[i]);
  1.1655 +      this.children = newChildren;
  1.1656 +    }
  1.1657 +    return this;
  1.1658 +  };
  1.1659 +
  1.1660 +  /**
  1.1661 +   * Call String.prototype.replace on the very right-most source snippet. Useful
  1.1662 +   * for trimming whitespace from the end of a source node, etc.
  1.1663 +   *
  1.1664 +   * @param aPattern The pattern to replace.
  1.1665 +   * @param aReplacement The thing to replace the pattern with.
  1.1666 +   */
  1.1667 +  SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
  1.1668 +    var lastChild = this.children[this.children.length - 1];
  1.1669 +    if (lastChild instanceof SourceNode) {
  1.1670 +      lastChild.replaceRight(aPattern, aReplacement);
  1.1671 +    }
  1.1672 +    else if (typeof lastChild === 'string') {
  1.1673 +      this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
  1.1674 +    }
  1.1675 +    else {
  1.1676 +      this.children.push(''.replace(aPattern, aReplacement));
  1.1677 +    }
  1.1678 +    return this;
  1.1679 +  };
  1.1680 +
  1.1681 +  /**
  1.1682 +   * Set the source content for a source file. This will be added to the SourceMapGenerator
  1.1683 +   * in the sourcesContent field.
  1.1684 +   *
  1.1685 +   * @param aSourceFile The filename of the source file
  1.1686 +   * @param aSourceContent The content of the source file
  1.1687 +   */
  1.1688 +  SourceNode.prototype.setSourceContent =
  1.1689 +    function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
  1.1690 +      this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
  1.1691 +    };
  1.1692 +
  1.1693 +  /**
  1.1694 +   * Walk over the tree of SourceNodes. The walking function is called for each
  1.1695 +   * source file content and is passed the filename and source content.
  1.1696 +   *
  1.1697 +   * @param aFn The traversal function.
  1.1698 +   */
  1.1699 +  SourceNode.prototype.walkSourceContents =
  1.1700 +    function SourceNode_walkSourceContents(aFn) {
  1.1701 +      for (var i = 0, len = this.children.length; i < len; i++) {
  1.1702 +        if (this.children[i] instanceof SourceNode) {
  1.1703 +          this.children[i].walkSourceContents(aFn);
  1.1704 +        }
  1.1705 +      }
  1.1706 +
  1.1707 +      var sources = Object.keys(this.sourceContents);
  1.1708 +      for (var i = 0, len = sources.length; i < len; i++) {
  1.1709 +        aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
  1.1710 +      }
  1.1711 +    };
  1.1712 +
  1.1713 +  /**
  1.1714 +   * Return the string representation of this source node. Walks over the tree
  1.1715 +   * and concatenates all the various snippets together to one string.
  1.1716 +   */
  1.1717 +  SourceNode.prototype.toString = function SourceNode_toString() {
  1.1718 +    var str = "";
  1.1719 +    this.walk(function (chunk) {
  1.1720 +      str += chunk;
  1.1721 +    });
  1.1722 +    return str;
  1.1723 +  };
  1.1724 +
  1.1725 +  /**
  1.1726 +   * Returns the string representation of this source node along with a source
  1.1727 +   * map.
  1.1728 +   */
  1.1729 +  SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
  1.1730 +    var generated = {
  1.1731 +      code: "",
  1.1732 +      line: 1,
  1.1733 +      column: 0
  1.1734 +    };
  1.1735 +    var map = new SourceMapGenerator(aArgs);
  1.1736 +    var sourceMappingActive = false;
  1.1737 +    var lastOriginalSource = null;
  1.1738 +    var lastOriginalLine = null;
  1.1739 +    var lastOriginalColumn = null;
  1.1740 +    var lastOriginalName = null;
  1.1741 +    this.walk(function (chunk, original) {
  1.1742 +      generated.code += chunk;
  1.1743 +      if (original.source !== null
  1.1744 +          && original.line !== null
  1.1745 +          && original.column !== null) {
  1.1746 +        if(lastOriginalSource !== original.source
  1.1747 +           || lastOriginalLine !== original.line
  1.1748 +           || lastOriginalColumn !== original.column
  1.1749 +           || lastOriginalName !== original.name) {
  1.1750 +          map.addMapping({
  1.1751 +            source: original.source,
  1.1752 +            original: {
  1.1753 +              line: original.line,
  1.1754 +              column: original.column
  1.1755 +            },
  1.1756 +            generated: {
  1.1757 +              line: generated.line,
  1.1758 +              column: generated.column
  1.1759 +            },
  1.1760 +            name: original.name
  1.1761 +          });
  1.1762 +        }
  1.1763 +        lastOriginalSource = original.source;
  1.1764 +        lastOriginalLine = original.line;
  1.1765 +        lastOriginalColumn = original.column;
  1.1766 +        lastOriginalName = original.name;
  1.1767 +        sourceMappingActive = true;
  1.1768 +      } else if (sourceMappingActive) {
  1.1769 +        map.addMapping({
  1.1770 +          generated: {
  1.1771 +            line: generated.line,
  1.1772 +            column: generated.column
  1.1773 +          }
  1.1774 +        });
  1.1775 +        lastOriginalSource = null;
  1.1776 +        sourceMappingActive = false;
  1.1777 +      }
  1.1778 +      chunk.split('').forEach(function (ch) {
  1.1779 +        if (ch === '\n') {
  1.1780 +          generated.line++;
  1.1781 +          generated.column = 0;
  1.1782 +        } else {
  1.1783 +          generated.column++;
  1.1784 +        }
  1.1785 +      });
  1.1786 +    });
  1.1787 +    this.walkSourceContents(function (sourceFile, sourceContent) {
  1.1788 +      map.setSourceContent(sourceFile, sourceContent);
  1.1789 +    });
  1.1790 +
  1.1791 +    return { code: generated.code, map: map };
  1.1792 +  };
  1.1793 +
  1.1794 +  exports.SourceNode = SourceNode;
  1.1795 +
  1.1796 +});
  1.1797 +/* -*- Mode: js; js-indent-level: 2; -*- */
  1.1798 +///////////////////////////////////////////////////////////////////////////////
  1.1799 +
  1.1800 +this.SourceMapConsumer = require('source-map/source-map-consumer').SourceMapConsumer;
  1.1801 +this.SourceMapGenerator = require('source-map/source-map-generator').SourceMapGenerator;
  1.1802 +this.SourceNode = require('source-map/source-node').SourceNode;

mercurial