Tim van der Lippe | 16b8228 | 2021-11-08 13:50:26 +0000 | [diff] [blame^] | 1 | (function webpackUniversalModuleDefinition(root, factory) { |
| 2 | if(typeof exports === 'object' && typeof module === 'object') |
| 3 | module.exports = factory(); |
| 4 | else if(typeof define === 'function' && define.amd) |
| 5 | define([], factory); |
| 6 | else if(typeof exports === 'object') |
| 7 | exports["sourceMap"] = factory(); |
| 8 | else |
| 9 | root["sourceMap"] = factory(); |
| 10 | })(this, function() { |
| 11 | return /******/ (function(modules) { // webpackBootstrap |
| 12 | /******/ // The module cache |
| 13 | /******/ var installedModules = {}; |
| 14 | |
| 15 | /******/ // The require function |
| 16 | /******/ function __webpack_require__(moduleId) { |
| 17 | |
| 18 | /******/ // Check if module is in cache |
| 19 | /******/ if(installedModules[moduleId]) |
| 20 | /******/ return installedModules[moduleId].exports; |
| 21 | |
| 22 | /******/ // Create a new module (and put it into the cache) |
| 23 | /******/ var module = installedModules[moduleId] = { |
| 24 | /******/ exports: {}, |
| 25 | /******/ id: moduleId, |
| 26 | /******/ loaded: false |
| 27 | /******/ }; |
| 28 | |
| 29 | /******/ // Execute the module function |
| 30 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); |
| 31 | |
| 32 | /******/ // Flag the module as loaded |
| 33 | /******/ module.loaded = true; |
| 34 | |
| 35 | /******/ // Return the exports of the module |
| 36 | /******/ return module.exports; |
| 37 | /******/ } |
| 38 | |
| 39 | |
| 40 | /******/ // expose the modules object (__webpack_modules__) |
| 41 | /******/ __webpack_require__.m = modules; |
| 42 | |
| 43 | /******/ // expose the module cache |
| 44 | /******/ __webpack_require__.c = installedModules; |
| 45 | |
| 46 | /******/ // __webpack_public_path__ |
| 47 | /******/ __webpack_require__.p = ""; |
| 48 | |
| 49 | /******/ // Load entry module and return exports |
| 50 | /******/ return __webpack_require__(0); |
| 51 | /******/ }) |
| 52 | /************************************************************************/ |
| 53 | /******/ ([ |
| 54 | /* 0 */ |
| 55 | /***/ (function(module, exports, __webpack_require__) { |
| 56 | |
| 57 | /* |
| 58 | * Copyright 2009-2011 Mozilla Foundation and contributors |
| 59 | * Licensed under the New BSD license. See LICENSE.txt or: |
| 60 | * http://opensource.org/licenses/BSD-3-Clause |
| 61 | */ |
| 62 | exports.SourceMapGenerator = __webpack_require__(1).SourceMapGenerator; |
| 63 | exports.SourceMapConsumer = __webpack_require__(7).SourceMapConsumer; |
| 64 | exports.SourceNode = __webpack_require__(10).SourceNode; |
| 65 | |
| 66 | |
| 67 | /***/ }), |
| 68 | /* 1 */ |
| 69 | /***/ (function(module, exports, __webpack_require__) { |
| 70 | |
| 71 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 72 | /* |
| 73 | * Copyright 2011 Mozilla Foundation and contributors |
| 74 | * Licensed under the New BSD license. See LICENSE or: |
| 75 | * http://opensource.org/licenses/BSD-3-Clause |
| 76 | */ |
| 77 | |
| 78 | var base64VLQ = __webpack_require__(2); |
| 79 | var util = __webpack_require__(4); |
| 80 | var ArraySet = __webpack_require__(5).ArraySet; |
| 81 | var MappingList = __webpack_require__(6).MappingList; |
| 82 | |
| 83 | /** |
| 84 | * An instance of the SourceMapGenerator represents a source map which is |
| 85 | * being built incrementally. You may pass an object with the following |
| 86 | * properties: |
| 87 | * |
| 88 | * - file: The filename of the generated source. |
| 89 | * - sourceRoot: A root for all relative URLs in this source map. |
| 90 | */ |
| 91 | function SourceMapGenerator(aArgs) { |
| 92 | if (!aArgs) { |
| 93 | aArgs = {}; |
| 94 | } |
| 95 | this._file = util.getArg(aArgs, 'file', null); |
| 96 | this._sourceRoot = util.getArg(aArgs, 'sourceRoot', null); |
| 97 | this._skipValidation = util.getArg(aArgs, 'skipValidation', false); |
| 98 | this._sources = new ArraySet(); |
| 99 | this._names = new ArraySet(); |
| 100 | this._mappings = new MappingList(); |
| 101 | this._sourcesContents = null; |
| 102 | } |
| 103 | |
| 104 | SourceMapGenerator.prototype._version = 3; |
| 105 | |
| 106 | /** |
| 107 | * Creates a new SourceMapGenerator based on a SourceMapConsumer |
| 108 | * |
| 109 | * @param aSourceMapConsumer The SourceMap. |
| 110 | */ |
| 111 | SourceMapGenerator.fromSourceMap = |
| 112 | function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) { |
| 113 | var sourceRoot = aSourceMapConsumer.sourceRoot; |
| 114 | var generator = new SourceMapGenerator({ |
| 115 | file: aSourceMapConsumer.file, |
| 116 | sourceRoot: sourceRoot |
| 117 | }); |
| 118 | aSourceMapConsumer.eachMapping(function (mapping) { |
| 119 | var newMapping = { |
| 120 | generated: { |
| 121 | line: mapping.generatedLine, |
| 122 | column: mapping.generatedColumn |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | if (mapping.source != null) { |
| 127 | newMapping.source = mapping.source; |
| 128 | if (sourceRoot != null) { |
| 129 | newMapping.source = util.relative(sourceRoot, newMapping.source); |
| 130 | } |
| 131 | |
| 132 | newMapping.original = { |
| 133 | line: mapping.originalLine, |
| 134 | column: mapping.originalColumn |
| 135 | }; |
| 136 | |
| 137 | if (mapping.name != null) { |
| 138 | newMapping.name = mapping.name; |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | generator.addMapping(newMapping); |
| 143 | }); |
| 144 | aSourceMapConsumer.sources.forEach(function (sourceFile) { |
| 145 | var sourceRelative = sourceFile; |
| 146 | if (sourceRoot !== null) { |
| 147 | sourceRelative = util.relative(sourceRoot, sourceFile); |
| 148 | } |
| 149 | |
| 150 | if (!generator._sources.has(sourceRelative)) { |
| 151 | generator._sources.add(sourceRelative); |
| 152 | } |
| 153 | |
| 154 | var content = aSourceMapConsumer.sourceContentFor(sourceFile); |
| 155 | if (content != null) { |
| 156 | generator.setSourceContent(sourceFile, content); |
| 157 | } |
| 158 | }); |
| 159 | return generator; |
| 160 | }; |
| 161 | |
| 162 | /** |
| 163 | * Add a single mapping from original source line and column to the generated |
| 164 | * source's line and column for this source map being created. The mapping |
| 165 | * object should have the following properties: |
| 166 | * |
| 167 | * - generated: An object with the generated line and column positions. |
| 168 | * - original: An object with the original line and column positions. |
| 169 | * - source: The original source file (relative to the sourceRoot). |
| 170 | * - name: An optional original token name for this mapping. |
| 171 | */ |
| 172 | SourceMapGenerator.prototype.addMapping = |
| 173 | function SourceMapGenerator_addMapping(aArgs) { |
| 174 | var generated = util.getArg(aArgs, 'generated'); |
| 175 | var original = util.getArg(aArgs, 'original', null); |
| 176 | var source = util.getArg(aArgs, 'source', null); |
| 177 | var name = util.getArg(aArgs, 'name', null); |
| 178 | |
| 179 | if (!this._skipValidation) { |
| 180 | this._validateMapping(generated, original, source, name); |
| 181 | } |
| 182 | |
| 183 | if (source != null) { |
| 184 | source = String(source); |
| 185 | if (!this._sources.has(source)) { |
| 186 | this._sources.add(source); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | if (name != null) { |
| 191 | name = String(name); |
| 192 | if (!this._names.has(name)) { |
| 193 | this._names.add(name); |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | this._mappings.add({ |
| 198 | generatedLine: generated.line, |
| 199 | generatedColumn: generated.column, |
| 200 | originalLine: original != null && original.line, |
| 201 | originalColumn: original != null && original.column, |
| 202 | source: source, |
| 203 | name: name |
| 204 | }); |
| 205 | }; |
| 206 | |
| 207 | /** |
| 208 | * Set the source content for a source file. |
| 209 | */ |
| 210 | SourceMapGenerator.prototype.setSourceContent = |
| 211 | function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) { |
| 212 | var source = aSourceFile; |
| 213 | if (this._sourceRoot != null) { |
| 214 | source = util.relative(this._sourceRoot, source); |
| 215 | } |
| 216 | |
| 217 | if (aSourceContent != null) { |
| 218 | // Add the source content to the _sourcesContents map. |
| 219 | // Create a new _sourcesContents map if the property is null. |
| 220 | if (!this._sourcesContents) { |
| 221 | this._sourcesContents = Object.create(null); |
| 222 | } |
| 223 | this._sourcesContents[util.toSetString(source)] = aSourceContent; |
| 224 | } else if (this._sourcesContents) { |
| 225 | // Remove the source file from the _sourcesContents map. |
| 226 | // If the _sourcesContents map is empty, set the property to null. |
| 227 | delete this._sourcesContents[util.toSetString(source)]; |
| 228 | if (Object.keys(this._sourcesContents).length === 0) { |
| 229 | this._sourcesContents = null; |
| 230 | } |
| 231 | } |
| 232 | }; |
| 233 | |
| 234 | /** |
| 235 | * Applies the mappings of a sub-source-map for a specific source file to the |
| 236 | * source map being generated. Each mapping to the supplied source file is |
| 237 | * rewritten using the supplied source map. Note: The resolution for the |
| 238 | * resulting mappings is the minimium of this map and the supplied map. |
| 239 | * |
| 240 | * @param aSourceMapConsumer The source map to be applied. |
| 241 | * @param aSourceFile Optional. The filename of the source file. |
| 242 | * If omitted, SourceMapConsumer's file property will be used. |
| 243 | * @param aSourceMapPath Optional. The dirname of the path to the source map |
| 244 | * to be applied. If relative, it is relative to the SourceMapConsumer. |
| 245 | * This parameter is needed when the two source maps aren't in the same |
| 246 | * directory, and the source map to be applied contains relative source |
| 247 | * paths. If so, those relative source paths need to be rewritten |
| 248 | * relative to the SourceMapGenerator. |
| 249 | */ |
| 250 | SourceMapGenerator.prototype.applySourceMap = |
| 251 | function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) { |
| 252 | var sourceFile = aSourceFile; |
| 253 | // If aSourceFile is omitted, we will use the file property of the SourceMap |
| 254 | if (aSourceFile == null) { |
| 255 | if (aSourceMapConsumer.file == null) { |
| 256 | throw new Error( |
| 257 | 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' + |
| 258 | 'or the source map\'s "file" property. Both were omitted.' |
| 259 | ); |
| 260 | } |
| 261 | sourceFile = aSourceMapConsumer.file; |
| 262 | } |
| 263 | var sourceRoot = this._sourceRoot; |
| 264 | // Make "sourceFile" relative if an absolute Url is passed. |
| 265 | if (sourceRoot != null) { |
| 266 | sourceFile = util.relative(sourceRoot, sourceFile); |
| 267 | } |
| 268 | // Applying the SourceMap can add and remove items from the sources and |
| 269 | // the names array. |
| 270 | var newSources = new ArraySet(); |
| 271 | var newNames = new ArraySet(); |
| 272 | |
| 273 | // Find mappings for the "sourceFile" |
| 274 | this._mappings.unsortedForEach(function (mapping) { |
| 275 | if (mapping.source === sourceFile && mapping.originalLine != null) { |
| 276 | // Check if it can be mapped by the source map, then update the mapping. |
| 277 | var original = aSourceMapConsumer.originalPositionFor({ |
| 278 | line: mapping.originalLine, |
| 279 | column: mapping.originalColumn |
| 280 | }); |
| 281 | if (original.source != null) { |
| 282 | // Copy mapping |
| 283 | mapping.source = original.source; |
| 284 | if (aSourceMapPath != null) { |
| 285 | mapping.source = util.join(aSourceMapPath, mapping.source) |
| 286 | } |
| 287 | if (sourceRoot != null) { |
| 288 | mapping.source = util.relative(sourceRoot, mapping.source); |
| 289 | } |
| 290 | mapping.originalLine = original.line; |
| 291 | mapping.originalColumn = original.column; |
| 292 | if (original.name != null) { |
| 293 | mapping.name = original.name; |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | var source = mapping.source; |
| 299 | if (source != null && !newSources.has(source)) { |
| 300 | newSources.add(source); |
| 301 | } |
| 302 | |
| 303 | var name = mapping.name; |
| 304 | if (name != null && !newNames.has(name)) { |
| 305 | newNames.add(name); |
| 306 | } |
| 307 | |
| 308 | }, this); |
| 309 | this._sources = newSources; |
| 310 | this._names = newNames; |
| 311 | |
| 312 | // Copy sourcesContents of applied map. |
| 313 | aSourceMapConsumer.sources.forEach(function (sourceFile) { |
| 314 | var content = aSourceMapConsumer.sourceContentFor(sourceFile); |
| 315 | if (content != null) { |
| 316 | if (aSourceMapPath != null) { |
| 317 | sourceFile = util.join(aSourceMapPath, sourceFile); |
| 318 | } |
| 319 | if (sourceRoot != null) { |
| 320 | sourceFile = util.relative(sourceRoot, sourceFile); |
| 321 | } |
| 322 | this.setSourceContent(sourceFile, content); |
| 323 | } |
| 324 | }, this); |
| 325 | }; |
| 326 | |
| 327 | /** |
| 328 | * A mapping can have one of the three levels of data: |
| 329 | * |
| 330 | * 1. Just the generated position. |
| 331 | * 2. The Generated position, original position, and original source. |
| 332 | * 3. Generated and original position, original source, as well as a name |
| 333 | * token. |
| 334 | * |
| 335 | * To maintain consistency, we validate that any new mapping being added falls |
| 336 | * in to one of these categories. |
| 337 | */ |
| 338 | SourceMapGenerator.prototype._validateMapping = |
| 339 | function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource, |
| 340 | aName) { |
| 341 | // When aOriginal is truthy but has empty values for .line and .column, |
| 342 | // it is most likely a programmer error. In this case we throw a very |
| 343 | // specific error message to try to guide them the right way. |
| 344 | // For example: https://github.com/Polymer/polymer-bundler/pull/519 |
| 345 | if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') { |
| 346 | throw new Error( |
| 347 | 'original.line and original.column are not numbers -- you probably meant to omit ' + |
| 348 | 'the original mapping entirely and only map the generated position. If so, pass ' + |
| 349 | 'null for the original mapping instead of an object with empty or null values.' |
| 350 | ); |
| 351 | } |
| 352 | |
| 353 | if (aGenerated && 'line' in aGenerated && 'column' in aGenerated |
| 354 | && aGenerated.line > 0 && aGenerated.column >= 0 |
| 355 | && !aOriginal && !aSource && !aName) { |
| 356 | // Case 1. |
| 357 | return; |
| 358 | } |
| 359 | else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated |
| 360 | && aOriginal && 'line' in aOriginal && 'column' in aOriginal |
| 361 | && aGenerated.line > 0 && aGenerated.column >= 0 |
| 362 | && aOriginal.line > 0 && aOriginal.column >= 0 |
| 363 | && aSource) { |
| 364 | // Cases 2 and 3. |
| 365 | return; |
| 366 | } |
| 367 | else { |
| 368 | throw new Error('Invalid mapping: ' + JSON.stringify({ |
| 369 | generated: aGenerated, |
| 370 | source: aSource, |
| 371 | original: aOriginal, |
| 372 | name: aName |
| 373 | })); |
| 374 | } |
| 375 | }; |
| 376 | |
| 377 | /** |
| 378 | * Serialize the accumulated mappings in to the stream of base 64 VLQs |
| 379 | * specified by the source map format. |
| 380 | */ |
| 381 | SourceMapGenerator.prototype._serializeMappings = |
| 382 | function SourceMapGenerator_serializeMappings() { |
| 383 | var previousGeneratedColumn = 0; |
| 384 | var previousGeneratedLine = 1; |
| 385 | var previousOriginalColumn = 0; |
| 386 | var previousOriginalLine = 0; |
| 387 | var previousName = 0; |
| 388 | var previousSource = 0; |
| 389 | var result = ''; |
| 390 | var next; |
| 391 | var mapping; |
| 392 | var nameIdx; |
| 393 | var sourceIdx; |
| 394 | |
| 395 | var mappings = this._mappings.toArray(); |
| 396 | for (var i = 0, len = mappings.length; i < len; i++) { |
| 397 | mapping = mappings[i]; |
| 398 | next = '' |
| 399 | |
| 400 | if (mapping.generatedLine !== previousGeneratedLine) { |
| 401 | previousGeneratedColumn = 0; |
| 402 | while (mapping.generatedLine !== previousGeneratedLine) { |
| 403 | next += ';'; |
| 404 | previousGeneratedLine++; |
| 405 | } |
| 406 | } |
| 407 | else { |
| 408 | if (i > 0) { |
| 409 | if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) { |
| 410 | continue; |
| 411 | } |
| 412 | next += ','; |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | next += base64VLQ.encode(mapping.generatedColumn |
| 417 | - previousGeneratedColumn); |
| 418 | previousGeneratedColumn = mapping.generatedColumn; |
| 419 | |
| 420 | if (mapping.source != null) { |
| 421 | sourceIdx = this._sources.indexOf(mapping.source); |
| 422 | next += base64VLQ.encode(sourceIdx - previousSource); |
| 423 | previousSource = sourceIdx; |
| 424 | |
| 425 | // lines are stored 0-based in SourceMap spec version 3 |
| 426 | next += base64VLQ.encode(mapping.originalLine - 1 |
| 427 | - previousOriginalLine); |
| 428 | previousOriginalLine = mapping.originalLine - 1; |
| 429 | |
| 430 | next += base64VLQ.encode(mapping.originalColumn |
| 431 | - previousOriginalColumn); |
| 432 | previousOriginalColumn = mapping.originalColumn; |
| 433 | |
| 434 | if (mapping.name != null) { |
| 435 | nameIdx = this._names.indexOf(mapping.name); |
| 436 | next += base64VLQ.encode(nameIdx - previousName); |
| 437 | previousName = nameIdx; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | result += next; |
| 442 | } |
| 443 | |
| 444 | return result; |
| 445 | }; |
| 446 | |
| 447 | SourceMapGenerator.prototype._generateSourcesContent = |
| 448 | function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) { |
| 449 | return aSources.map(function (source) { |
| 450 | if (!this._sourcesContents) { |
| 451 | return null; |
| 452 | } |
| 453 | if (aSourceRoot != null) { |
| 454 | source = util.relative(aSourceRoot, source); |
| 455 | } |
| 456 | var key = util.toSetString(source); |
| 457 | return Object.prototype.hasOwnProperty.call(this._sourcesContents, key) |
| 458 | ? this._sourcesContents[key] |
| 459 | : null; |
| 460 | }, this); |
| 461 | }; |
| 462 | |
| 463 | /** |
| 464 | * Externalize the source map. |
| 465 | */ |
| 466 | SourceMapGenerator.prototype.toJSON = |
| 467 | function SourceMapGenerator_toJSON() { |
| 468 | var map = { |
| 469 | version: this._version, |
| 470 | sources: this._sources.toArray(), |
| 471 | names: this._names.toArray(), |
| 472 | mappings: this._serializeMappings() |
| 473 | }; |
| 474 | if (this._file != null) { |
| 475 | map.file = this._file; |
| 476 | } |
| 477 | if (this._sourceRoot != null) { |
| 478 | map.sourceRoot = this._sourceRoot; |
| 479 | } |
| 480 | if (this._sourcesContents) { |
| 481 | map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot); |
| 482 | } |
| 483 | |
| 484 | return map; |
| 485 | }; |
| 486 | |
| 487 | /** |
| 488 | * Render the source map being generated to a string. |
| 489 | */ |
| 490 | SourceMapGenerator.prototype.toString = |
| 491 | function SourceMapGenerator_toString() { |
| 492 | return JSON.stringify(this.toJSON()); |
| 493 | }; |
| 494 | |
| 495 | exports.SourceMapGenerator = SourceMapGenerator; |
| 496 | |
| 497 | |
| 498 | /***/ }), |
| 499 | /* 2 */ |
| 500 | /***/ (function(module, exports, __webpack_require__) { |
| 501 | |
| 502 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 503 | /* |
| 504 | * Copyright 2011 Mozilla Foundation and contributors |
| 505 | * Licensed under the New BSD license. See LICENSE or: |
| 506 | * http://opensource.org/licenses/BSD-3-Clause |
| 507 | * |
| 508 | * Based on the Base 64 VLQ implementation in Closure Compiler: |
| 509 | * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java |
| 510 | * |
| 511 | * Copyright 2011 The Closure Compiler Authors. All rights reserved. |
| 512 | * Redistribution and use in source and binary forms, with or without |
| 513 | * modification, are permitted provided that the following conditions are |
| 514 | * met: |
| 515 | * |
| 516 | * * Redistributions of source code must retain the above copyright |
| 517 | * notice, this list of conditions and the following disclaimer. |
| 518 | * * Redistributions in binary form must reproduce the above |
| 519 | * copyright notice, this list of conditions and the following |
| 520 | * disclaimer in the documentation and/or other materials provided |
| 521 | * with the distribution. |
| 522 | * * Neither the name of Google Inc. nor the names of its |
| 523 | * contributors may be used to endorse or promote products derived |
| 524 | * from this software without specific prior written permission. |
| 525 | * |
| 526 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 527 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 528 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 529 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 530 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 531 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 532 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 533 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 534 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 535 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 536 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 537 | */ |
| 538 | |
| 539 | var base64 = __webpack_require__(3); |
| 540 | |
| 541 | // A single base 64 digit can contain 6 bits of data. For the base 64 variable |
| 542 | // length quantities we use in the source map spec, the first bit is the sign, |
| 543 | // the next four bits are the actual value, and the 6th bit is the |
| 544 | // continuation bit. The continuation bit tells us whether there are more |
| 545 | // digits in this value following this digit. |
| 546 | // |
| 547 | // Continuation |
| 548 | // | Sign |
| 549 | // | | |
| 550 | // V V |
| 551 | // 101011 |
| 552 | |
| 553 | var VLQ_BASE_SHIFT = 5; |
| 554 | |
| 555 | // binary: 100000 |
| 556 | var VLQ_BASE = 1 << VLQ_BASE_SHIFT; |
| 557 | |
| 558 | // binary: 011111 |
| 559 | var VLQ_BASE_MASK = VLQ_BASE - 1; |
| 560 | |
| 561 | // binary: 100000 |
| 562 | var VLQ_CONTINUATION_BIT = VLQ_BASE; |
| 563 | |
| 564 | /** |
| 565 | * Converts from a two-complement value to a value where the sign bit is |
| 566 | * placed in the least significant bit. For example, as decimals: |
| 567 | * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary) |
| 568 | * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary) |
| 569 | */ |
| 570 | function toVLQSigned(aValue) { |
| 571 | return aValue < 0 |
| 572 | ? ((-aValue) << 1) + 1 |
| 573 | : (aValue << 1) + 0; |
| 574 | } |
| 575 | |
| 576 | /** |
| 577 | * Converts to a two-complement value from a value where the sign bit is |
| 578 | * placed in the least significant bit. For example, as decimals: |
| 579 | * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1 |
| 580 | * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2 |
| 581 | */ |
| 582 | function fromVLQSigned(aValue) { |
| 583 | var isNegative = (aValue & 1) === 1; |
| 584 | var shifted = aValue >> 1; |
| 585 | return isNegative |
| 586 | ? -shifted |
| 587 | : shifted; |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Returns the base 64 VLQ encoded value. |
| 592 | */ |
| 593 | exports.encode = function base64VLQ_encode(aValue) { |
| 594 | var encoded = ""; |
| 595 | var digit; |
| 596 | |
| 597 | var vlq = toVLQSigned(aValue); |
| 598 | |
| 599 | do { |
| 600 | digit = vlq & VLQ_BASE_MASK; |
| 601 | vlq >>>= VLQ_BASE_SHIFT; |
| 602 | if (vlq > 0) { |
| 603 | // There are still more digits in this value, so we must make sure the |
| 604 | // continuation bit is marked. |
| 605 | digit |= VLQ_CONTINUATION_BIT; |
| 606 | } |
| 607 | encoded += base64.encode(digit); |
| 608 | } while (vlq > 0); |
| 609 | |
| 610 | return encoded; |
| 611 | }; |
| 612 | |
| 613 | /** |
| 614 | * Decodes the next base 64 VLQ value from the given string and returns the |
| 615 | * value and the rest of the string via the out parameter. |
| 616 | */ |
| 617 | exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) { |
| 618 | var strLen = aStr.length; |
| 619 | var result = 0; |
| 620 | var shift = 0; |
| 621 | var continuation, digit; |
| 622 | |
| 623 | do { |
| 624 | if (aIndex >= strLen) { |
| 625 | throw new Error("Expected more digits in base 64 VLQ value."); |
| 626 | } |
| 627 | |
| 628 | digit = base64.decode(aStr.charCodeAt(aIndex++)); |
| 629 | if (digit === -1) { |
| 630 | throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1)); |
| 631 | } |
| 632 | |
| 633 | continuation = !!(digit & VLQ_CONTINUATION_BIT); |
| 634 | digit &= VLQ_BASE_MASK; |
| 635 | result = result + (digit << shift); |
| 636 | shift += VLQ_BASE_SHIFT; |
| 637 | } while (continuation); |
| 638 | |
| 639 | aOutParam.value = fromVLQSigned(result); |
| 640 | aOutParam.rest = aIndex; |
| 641 | }; |
| 642 | |
| 643 | |
| 644 | /***/ }), |
| 645 | /* 3 */ |
| 646 | /***/ (function(module, exports) { |
| 647 | |
| 648 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 649 | /* |
| 650 | * Copyright 2011 Mozilla Foundation and contributors |
| 651 | * Licensed under the New BSD license. See LICENSE or: |
| 652 | * http://opensource.org/licenses/BSD-3-Clause |
| 653 | */ |
| 654 | |
| 655 | var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split(''); |
| 656 | |
| 657 | /** |
| 658 | * Encode an integer in the range of 0 to 63 to a single base 64 digit. |
| 659 | */ |
| 660 | exports.encode = function (number) { |
| 661 | if (0 <= number && number < intToCharMap.length) { |
| 662 | return intToCharMap[number]; |
| 663 | } |
| 664 | throw new TypeError("Must be between 0 and 63: " + number); |
| 665 | }; |
| 666 | |
| 667 | /** |
| 668 | * Decode a single base 64 character code digit to an integer. Returns -1 on |
| 669 | * failure. |
| 670 | */ |
| 671 | exports.decode = function (charCode) { |
| 672 | var bigA = 65; // 'A' |
| 673 | var bigZ = 90; // 'Z' |
| 674 | |
| 675 | var littleA = 97; // 'a' |
| 676 | var littleZ = 122; // 'z' |
| 677 | |
| 678 | var zero = 48; // '0' |
| 679 | var nine = 57; // '9' |
| 680 | |
| 681 | var plus = 43; // '+' |
| 682 | var slash = 47; // '/' |
| 683 | |
| 684 | var littleOffset = 26; |
| 685 | var numberOffset = 52; |
| 686 | |
| 687 | // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ |
| 688 | if (bigA <= charCode && charCode <= bigZ) { |
| 689 | return (charCode - bigA); |
| 690 | } |
| 691 | |
| 692 | // 26 - 51: abcdefghijklmnopqrstuvwxyz |
| 693 | if (littleA <= charCode && charCode <= littleZ) { |
| 694 | return (charCode - littleA + littleOffset); |
| 695 | } |
| 696 | |
| 697 | // 52 - 61: 0123456789 |
| 698 | if (zero <= charCode && charCode <= nine) { |
| 699 | return (charCode - zero + numberOffset); |
| 700 | } |
| 701 | |
| 702 | // 62: + |
| 703 | if (charCode == plus) { |
| 704 | return 62; |
| 705 | } |
| 706 | |
| 707 | // 63: / |
| 708 | if (charCode == slash) { |
| 709 | return 63; |
| 710 | } |
| 711 | |
| 712 | // Invalid base64 digit. |
| 713 | return -1; |
| 714 | }; |
| 715 | |
| 716 | |
| 717 | /***/ }), |
| 718 | /* 4 */ |
| 719 | /***/ (function(module, exports) { |
| 720 | |
| 721 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 722 | /* |
| 723 | * Copyright 2011 Mozilla Foundation and contributors |
| 724 | * Licensed under the New BSD license. See LICENSE or: |
| 725 | * http://opensource.org/licenses/BSD-3-Clause |
| 726 | */ |
| 727 | |
| 728 | /** |
| 729 | * This is a helper function for getting values from parameter/options |
| 730 | * objects. |
| 731 | * |
| 732 | * @param args The object we are extracting values from |
| 733 | * @param name The name of the property we are getting. |
| 734 | * @param defaultValue An optional value to return if the property is missing |
| 735 | * from the object. If this is not specified and the property is missing, an |
| 736 | * error will be thrown. |
| 737 | */ |
| 738 | function getArg(aArgs, aName, aDefaultValue) { |
| 739 | if (aName in aArgs) { |
| 740 | return aArgs[aName]; |
| 741 | } else if (arguments.length === 3) { |
| 742 | return aDefaultValue; |
| 743 | } else { |
| 744 | throw new Error('"' + aName + '" is a required argument.'); |
| 745 | } |
| 746 | } |
| 747 | exports.getArg = getArg; |
| 748 | |
| 749 | var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/; |
| 750 | var dataUrlRegexp = /^data:.+\,.+$/; |
| 751 | |
| 752 | function urlParse(aUrl) { |
| 753 | var match = aUrl.match(urlRegexp); |
| 754 | if (!match) { |
| 755 | return null; |
| 756 | } |
| 757 | return { |
| 758 | scheme: match[1], |
| 759 | auth: match[2], |
| 760 | host: match[3], |
| 761 | port: match[4], |
| 762 | path: match[5] |
| 763 | }; |
| 764 | } |
| 765 | exports.urlParse = urlParse; |
| 766 | |
| 767 | function urlGenerate(aParsedUrl) { |
| 768 | var url = ''; |
| 769 | if (aParsedUrl.scheme) { |
| 770 | url += aParsedUrl.scheme + ':'; |
| 771 | } |
| 772 | url += '//'; |
| 773 | if (aParsedUrl.auth) { |
| 774 | url += aParsedUrl.auth + '@'; |
| 775 | } |
| 776 | if (aParsedUrl.host) { |
| 777 | url += aParsedUrl.host; |
| 778 | } |
| 779 | if (aParsedUrl.port) { |
| 780 | url += ":" + aParsedUrl.port |
| 781 | } |
| 782 | if (aParsedUrl.path) { |
| 783 | url += aParsedUrl.path; |
| 784 | } |
| 785 | return url; |
| 786 | } |
| 787 | exports.urlGenerate = urlGenerate; |
| 788 | |
| 789 | var MAX_CACHED_INPUTS = 32; |
| 790 | |
| 791 | /** |
| 792 | * Takes some function `f(input) -> result` and returns a memoized version of |
| 793 | * `f`. |
| 794 | * |
| 795 | * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The |
| 796 | * memoization is a dumb-simple, linear least-recently-used cache. |
| 797 | */ |
| 798 | function lruMemoize(f) { |
| 799 | var cache = []; |
| 800 | |
| 801 | return function(input) { |
| 802 | for (var i = 0; i < cache.length; i++) { |
| 803 | if (cache[i].input === input) { |
| 804 | var temp = cache[0]; |
| 805 | cache[0] = cache[i]; |
| 806 | cache[i] = temp; |
| 807 | return cache[0].result; |
| 808 | } |
| 809 | } |
| 810 | |
| 811 | var result = f(input); |
| 812 | |
| 813 | cache.unshift({ |
| 814 | input, |
| 815 | result, |
| 816 | }); |
| 817 | |
| 818 | if (cache.length > MAX_CACHED_INPUTS) { |
| 819 | cache.pop(); |
| 820 | } |
| 821 | |
| 822 | return result; |
| 823 | }; |
| 824 | } |
| 825 | |
| 826 | /** |
| 827 | * Normalizes a path, or the path portion of a URL: |
| 828 | * |
| 829 | * - Replaces consecutive slashes with one slash. |
| 830 | * - Removes unnecessary '.' parts. |
| 831 | * - Removes unnecessary '<dir>/..' parts. |
| 832 | * |
| 833 | * Based on code in the Node.js 'path' core module. |
| 834 | * |
| 835 | * @param aPath The path or url to normalize. |
| 836 | */ |
| 837 | var normalize = lruMemoize(function normalize(aPath) { |
| 838 | var path = aPath; |
| 839 | var url = urlParse(aPath); |
| 840 | if (url) { |
| 841 | if (!url.path) { |
| 842 | return aPath; |
| 843 | } |
| 844 | path = url.path; |
| 845 | } |
| 846 | var isAbsolute = exports.isAbsolute(path); |
| 847 | // Split the path into parts between `/` characters. This is much faster than |
| 848 | // using `.split(/\/+/g)`. |
| 849 | var parts = []; |
| 850 | var start = 0; |
| 851 | var i = 0; |
| 852 | while (true) { |
| 853 | start = i; |
| 854 | i = path.indexOf("/", start); |
| 855 | if (i === -1) { |
| 856 | parts.push(path.slice(start)); |
| 857 | break; |
| 858 | } else { |
| 859 | parts.push(path.slice(start, i)); |
| 860 | while (i < path.length && path[i] === "/") { |
| 861 | i++; |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | for (var part, up = 0, i = parts.length - 1; i >= 0; i--) { |
| 867 | part = parts[i]; |
| 868 | if (part === '.') { |
| 869 | parts.splice(i, 1); |
| 870 | } else if (part === '..') { |
| 871 | up++; |
| 872 | } else if (up > 0) { |
| 873 | if (part === '') { |
| 874 | // The first part is blank if the path is absolute. Trying to go |
| 875 | // above the root is a no-op. Therefore we can remove all '..' parts |
| 876 | // directly after the root. |
| 877 | parts.splice(i + 1, up); |
| 878 | up = 0; |
| 879 | } else { |
| 880 | parts.splice(i, 2); |
| 881 | up--; |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | path = parts.join('/'); |
| 886 | |
| 887 | if (path === '') { |
| 888 | path = isAbsolute ? '/' : '.'; |
| 889 | } |
| 890 | |
| 891 | if (url) { |
| 892 | url.path = path; |
| 893 | return urlGenerate(url); |
| 894 | } |
| 895 | return path; |
| 896 | }); |
| 897 | exports.normalize = normalize; |
| 898 | |
| 899 | /** |
| 900 | * Joins two paths/URLs. |
| 901 | * |
| 902 | * @param aRoot The root path or URL. |
| 903 | * @param aPath The path or URL to be joined with the root. |
| 904 | * |
| 905 | * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a |
| 906 | * scheme-relative URL: Then the scheme of aRoot, if any, is prepended |
| 907 | * first. |
| 908 | * - Otherwise aPath is a path. If aRoot is a URL, then its path portion |
| 909 | * is updated with the result and aRoot is returned. Otherwise the result |
| 910 | * is returned. |
| 911 | * - If aPath is absolute, the result is aPath. |
| 912 | * - Otherwise the two paths are joined with a slash. |
| 913 | * - Joining for example 'http://' and 'www.example.com' is also supported. |
| 914 | */ |
| 915 | function join(aRoot, aPath) { |
| 916 | if (aRoot === "") { |
| 917 | aRoot = "."; |
| 918 | } |
| 919 | if (aPath === "") { |
| 920 | aPath = "."; |
| 921 | } |
| 922 | var aPathUrl = urlParse(aPath); |
| 923 | var aRootUrl = urlParse(aRoot); |
| 924 | if (aRootUrl) { |
| 925 | aRoot = aRootUrl.path || '/'; |
| 926 | } |
| 927 | |
| 928 | // `join(foo, '//www.example.org')` |
| 929 | if (aPathUrl && !aPathUrl.scheme) { |
| 930 | if (aRootUrl) { |
| 931 | aPathUrl.scheme = aRootUrl.scheme; |
| 932 | } |
| 933 | return urlGenerate(aPathUrl); |
| 934 | } |
| 935 | |
| 936 | if (aPathUrl || aPath.match(dataUrlRegexp)) { |
| 937 | return aPath; |
| 938 | } |
| 939 | |
| 940 | // `join('http://', 'www.example.com')` |
| 941 | if (aRootUrl && !aRootUrl.host && !aRootUrl.path) { |
| 942 | aRootUrl.host = aPath; |
| 943 | return urlGenerate(aRootUrl); |
| 944 | } |
| 945 | |
| 946 | var joined = aPath.charAt(0) === '/' |
| 947 | ? aPath |
| 948 | : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath); |
| 949 | |
| 950 | if (aRootUrl) { |
| 951 | aRootUrl.path = joined; |
| 952 | return urlGenerate(aRootUrl); |
| 953 | } |
| 954 | return joined; |
| 955 | } |
| 956 | exports.join = join; |
| 957 | |
| 958 | exports.isAbsolute = function (aPath) { |
| 959 | return aPath.charAt(0) === '/' || urlRegexp.test(aPath); |
| 960 | }; |
| 961 | |
| 962 | /** |
| 963 | * Make a path relative to a URL or another path. |
| 964 | * |
| 965 | * @param aRoot The root path or URL. |
| 966 | * @param aPath The path or URL to be made relative to aRoot. |
| 967 | */ |
| 968 | function relative(aRoot, aPath) { |
| 969 | if (aRoot === "") { |
| 970 | aRoot = "."; |
| 971 | } |
| 972 | |
| 973 | aRoot = aRoot.replace(/\/$/, ''); |
| 974 | |
| 975 | // It is possible for the path to be above the root. In this case, simply |
| 976 | // checking whether the root is a prefix of the path won't work. Instead, we |
| 977 | // need to remove components from the root one by one, until either we find |
| 978 | // a prefix that fits, or we run out of components to remove. |
| 979 | var level = 0; |
| 980 | while (aPath.indexOf(aRoot + '/') !== 0) { |
| 981 | var index = aRoot.lastIndexOf("/"); |
| 982 | if (index < 0) { |
| 983 | return aPath; |
| 984 | } |
| 985 | |
| 986 | // If the only part of the root that is left is the scheme (i.e. http://, |
| 987 | // file:///, etc.), one or more slashes (/), or simply nothing at all, we |
| 988 | // have exhausted all components, so the path is not relative to the root. |
| 989 | aRoot = aRoot.slice(0, index); |
| 990 | if (aRoot.match(/^([^\/]+:\/)?\/*$/)) { |
| 991 | return aPath; |
| 992 | } |
| 993 | |
| 994 | ++level; |
| 995 | } |
| 996 | |
| 997 | // Make sure we add a "../" for each component we removed from the root. |
| 998 | return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1); |
| 999 | } |
| 1000 | exports.relative = relative; |
| 1001 | |
| 1002 | var supportsNullProto = (function () { |
| 1003 | var obj = Object.create(null); |
| 1004 | return !('__proto__' in obj); |
| 1005 | }()); |
| 1006 | |
| 1007 | function identity (s) { |
| 1008 | return s; |
| 1009 | } |
| 1010 | |
| 1011 | /** |
| 1012 | * Because behavior goes wacky when you set `__proto__` on objects, we |
| 1013 | * have to prefix all the strings in our set with an arbitrary character. |
| 1014 | * |
| 1015 | * See https://github.com/mozilla/source-map/pull/31 and |
| 1016 | * https://github.com/mozilla/source-map/issues/30 |
| 1017 | * |
| 1018 | * @param String aStr |
| 1019 | */ |
| 1020 | function toSetString(aStr) { |
| 1021 | if (isProtoString(aStr)) { |
| 1022 | return '$' + aStr; |
| 1023 | } |
| 1024 | |
| 1025 | return aStr; |
| 1026 | } |
| 1027 | exports.toSetString = supportsNullProto ? identity : toSetString; |
| 1028 | |
| 1029 | function fromSetString(aStr) { |
| 1030 | if (isProtoString(aStr)) { |
| 1031 | return aStr.slice(1); |
| 1032 | } |
| 1033 | |
| 1034 | return aStr; |
| 1035 | } |
| 1036 | exports.fromSetString = supportsNullProto ? identity : fromSetString; |
| 1037 | |
| 1038 | function isProtoString(s) { |
| 1039 | if (!s) { |
| 1040 | return false; |
| 1041 | } |
| 1042 | |
| 1043 | var length = s.length; |
| 1044 | |
| 1045 | if (length < 9 /* "__proto__".length */) { |
| 1046 | return false; |
| 1047 | } |
| 1048 | |
| 1049 | if (s.charCodeAt(length - 1) !== 95 /* '_' */ || |
| 1050 | s.charCodeAt(length - 2) !== 95 /* '_' */ || |
| 1051 | s.charCodeAt(length - 3) !== 111 /* 'o' */ || |
| 1052 | s.charCodeAt(length - 4) !== 116 /* 't' */ || |
| 1053 | s.charCodeAt(length - 5) !== 111 /* 'o' */ || |
| 1054 | s.charCodeAt(length - 6) !== 114 /* 'r' */ || |
| 1055 | s.charCodeAt(length - 7) !== 112 /* 'p' */ || |
| 1056 | s.charCodeAt(length - 8) !== 95 /* '_' */ || |
| 1057 | s.charCodeAt(length - 9) !== 95 /* '_' */) { |
| 1058 | return false; |
| 1059 | } |
| 1060 | |
| 1061 | for (var i = length - 10; i >= 0; i--) { |
| 1062 | if (s.charCodeAt(i) !== 36 /* '$' */) { |
| 1063 | return false; |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | return true; |
| 1068 | } |
| 1069 | |
| 1070 | /** |
| 1071 | * Comparator between two mappings where the original positions are compared. |
| 1072 | * |
| 1073 | * Optionally pass in `true` as `onlyCompareGenerated` to consider two |
| 1074 | * mappings with the same original source/line/column, but different generated |
| 1075 | * line and column the same. Useful when searching for a mapping with a |
| 1076 | * stubbed out mapping. |
| 1077 | */ |
| 1078 | function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) { |
| 1079 | var cmp = strcmp(mappingA.source, mappingB.source); |
| 1080 | if (cmp !== 0) { |
| 1081 | return cmp; |
| 1082 | } |
| 1083 | |
| 1084 | cmp = mappingA.originalLine - mappingB.originalLine; |
| 1085 | if (cmp !== 0) { |
| 1086 | return cmp; |
| 1087 | } |
| 1088 | |
| 1089 | cmp = mappingA.originalColumn - mappingB.originalColumn; |
| 1090 | if (cmp !== 0 || onlyCompareOriginal) { |
| 1091 | return cmp; |
| 1092 | } |
| 1093 | |
| 1094 | cmp = mappingA.generatedColumn - mappingB.generatedColumn; |
| 1095 | if (cmp !== 0) { |
| 1096 | return cmp; |
| 1097 | } |
| 1098 | |
| 1099 | cmp = mappingA.generatedLine - mappingB.generatedLine; |
| 1100 | if (cmp !== 0) { |
| 1101 | return cmp; |
| 1102 | } |
| 1103 | |
| 1104 | return strcmp(mappingA.name, mappingB.name); |
| 1105 | } |
| 1106 | exports.compareByOriginalPositions = compareByOriginalPositions; |
| 1107 | |
| 1108 | function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) { |
| 1109 | var cmp |
| 1110 | |
| 1111 | cmp = mappingA.originalLine - mappingB.originalLine; |
| 1112 | if (cmp !== 0) { |
| 1113 | return cmp; |
| 1114 | } |
| 1115 | |
| 1116 | cmp = mappingA.originalColumn - mappingB.originalColumn; |
| 1117 | if (cmp !== 0 || onlyCompareOriginal) { |
| 1118 | return cmp; |
| 1119 | } |
| 1120 | |
| 1121 | cmp = mappingA.generatedColumn - mappingB.generatedColumn; |
| 1122 | if (cmp !== 0) { |
| 1123 | return cmp; |
| 1124 | } |
| 1125 | |
| 1126 | cmp = mappingA.generatedLine - mappingB.generatedLine; |
| 1127 | if (cmp !== 0) { |
| 1128 | return cmp; |
| 1129 | } |
| 1130 | |
| 1131 | return strcmp(mappingA.name, mappingB.name); |
| 1132 | } |
| 1133 | exports.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource; |
| 1134 | |
| 1135 | /** |
| 1136 | * Comparator between two mappings with deflated source and name indices where |
| 1137 | * the generated positions are compared. |
| 1138 | * |
| 1139 | * Optionally pass in `true` as `onlyCompareGenerated` to consider two |
| 1140 | * mappings with the same generated line and column, but different |
| 1141 | * source/name/original line and column the same. Useful when searching for a |
| 1142 | * mapping with a stubbed out mapping. |
| 1143 | */ |
| 1144 | function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) { |
| 1145 | var cmp = mappingA.generatedLine - mappingB.generatedLine; |
| 1146 | if (cmp !== 0) { |
| 1147 | return cmp; |
| 1148 | } |
| 1149 | |
| 1150 | cmp = mappingA.generatedColumn - mappingB.generatedColumn; |
| 1151 | if (cmp !== 0 || onlyCompareGenerated) { |
| 1152 | return cmp; |
| 1153 | } |
| 1154 | |
| 1155 | cmp = strcmp(mappingA.source, mappingB.source); |
| 1156 | if (cmp !== 0) { |
| 1157 | return cmp; |
| 1158 | } |
| 1159 | |
| 1160 | cmp = mappingA.originalLine - mappingB.originalLine; |
| 1161 | if (cmp !== 0) { |
| 1162 | return cmp; |
| 1163 | } |
| 1164 | |
| 1165 | cmp = mappingA.originalColumn - mappingB.originalColumn; |
| 1166 | if (cmp !== 0) { |
| 1167 | return cmp; |
| 1168 | } |
| 1169 | |
| 1170 | return strcmp(mappingA.name, mappingB.name); |
| 1171 | } |
| 1172 | exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated; |
| 1173 | |
| 1174 | function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) { |
| 1175 | var cmp = mappingA.generatedColumn - mappingB.generatedColumn; |
| 1176 | if (cmp !== 0 || onlyCompareGenerated) { |
| 1177 | return cmp; |
| 1178 | } |
| 1179 | |
| 1180 | cmp = strcmp(mappingA.source, mappingB.source); |
| 1181 | if (cmp !== 0) { |
| 1182 | return cmp; |
| 1183 | } |
| 1184 | |
| 1185 | cmp = mappingA.originalLine - mappingB.originalLine; |
| 1186 | if (cmp !== 0) { |
| 1187 | return cmp; |
| 1188 | } |
| 1189 | |
| 1190 | cmp = mappingA.originalColumn - mappingB.originalColumn; |
| 1191 | if (cmp !== 0) { |
| 1192 | return cmp; |
| 1193 | } |
| 1194 | |
| 1195 | return strcmp(mappingA.name, mappingB.name); |
| 1196 | } |
| 1197 | exports.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine; |
| 1198 | |
| 1199 | function strcmp(aStr1, aStr2) { |
| 1200 | if (aStr1 === aStr2) { |
| 1201 | return 0; |
| 1202 | } |
| 1203 | |
| 1204 | if (aStr1 === null) { |
| 1205 | return 1; // aStr2 !== null |
| 1206 | } |
| 1207 | |
| 1208 | if (aStr2 === null) { |
| 1209 | return -1; // aStr1 !== null |
| 1210 | } |
| 1211 | |
| 1212 | if (aStr1 > aStr2) { |
| 1213 | return 1; |
| 1214 | } |
| 1215 | |
| 1216 | return -1; |
| 1217 | } |
| 1218 | |
| 1219 | /** |
| 1220 | * Comparator between two mappings with inflated source and name strings where |
| 1221 | * the generated positions are compared. |
| 1222 | */ |
| 1223 | function compareByGeneratedPositionsInflated(mappingA, mappingB) { |
| 1224 | var cmp = mappingA.generatedLine - mappingB.generatedLine; |
| 1225 | if (cmp !== 0) { |
| 1226 | return cmp; |
| 1227 | } |
| 1228 | |
| 1229 | cmp = mappingA.generatedColumn - mappingB.generatedColumn; |
| 1230 | if (cmp !== 0) { |
| 1231 | return cmp; |
| 1232 | } |
| 1233 | |
| 1234 | cmp = strcmp(mappingA.source, mappingB.source); |
| 1235 | if (cmp !== 0) { |
| 1236 | return cmp; |
| 1237 | } |
| 1238 | |
| 1239 | cmp = mappingA.originalLine - mappingB.originalLine; |
| 1240 | if (cmp !== 0) { |
| 1241 | return cmp; |
| 1242 | } |
| 1243 | |
| 1244 | cmp = mappingA.originalColumn - mappingB.originalColumn; |
| 1245 | if (cmp !== 0) { |
| 1246 | return cmp; |
| 1247 | } |
| 1248 | |
| 1249 | return strcmp(mappingA.name, mappingB.name); |
| 1250 | } |
| 1251 | exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated; |
| 1252 | |
| 1253 | /** |
| 1254 | * Strip any JSON XSSI avoidance prefix from the string (as documented |
| 1255 | * in the source maps specification), and then parse the string as |
| 1256 | * JSON. |
| 1257 | */ |
| 1258 | function parseSourceMapInput(str) { |
| 1259 | return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, '')); |
| 1260 | } |
| 1261 | exports.parseSourceMapInput = parseSourceMapInput; |
| 1262 | |
| 1263 | /** |
| 1264 | * Compute the URL of a source given the the source root, the source's |
| 1265 | * URL, and the source map's URL. |
| 1266 | */ |
| 1267 | function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) { |
| 1268 | sourceURL = sourceURL || ''; |
| 1269 | |
| 1270 | if (sourceRoot) { |
| 1271 | // This follows what Chrome does. |
| 1272 | if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') { |
| 1273 | sourceRoot += '/'; |
| 1274 | } |
| 1275 | // The spec says: |
| 1276 | // Line 4: An optional source root, useful for relocating source |
| 1277 | // files on a server or removing repeated values in the |
| 1278 | // “sources” entry. This value is prepended to the individual |
| 1279 | // entries in the “source” field. |
| 1280 | sourceURL = sourceRoot + sourceURL; |
| 1281 | } |
| 1282 | |
| 1283 | // Historically, SourceMapConsumer did not take the sourceMapURL as |
| 1284 | // a parameter. This mode is still somewhat supported, which is why |
| 1285 | // this code block is conditional. However, it's preferable to pass |
| 1286 | // the source map URL to SourceMapConsumer, so that this function |
| 1287 | // can implement the source URL resolution algorithm as outlined in |
| 1288 | // the spec. This block is basically the equivalent of: |
| 1289 | // new URL(sourceURL, sourceMapURL).toString() |
| 1290 | // ... except it avoids using URL, which wasn't available in the |
| 1291 | // older releases of node still supported by this library. |
| 1292 | // |
| 1293 | // The spec says: |
| 1294 | // If the sources are not absolute URLs after prepending of the |
| 1295 | // “sourceRoot”, the sources are resolved relative to the |
| 1296 | // SourceMap (like resolving script src in a html document). |
| 1297 | if (sourceMapURL) { |
| 1298 | var parsed = urlParse(sourceMapURL); |
| 1299 | if (!parsed) { |
| 1300 | throw new Error("sourceMapURL could not be parsed"); |
| 1301 | } |
| 1302 | if (parsed.path) { |
| 1303 | // Strip the last path component, but keep the "/". |
| 1304 | var index = parsed.path.lastIndexOf('/'); |
| 1305 | if (index >= 0) { |
| 1306 | parsed.path = parsed.path.substring(0, index + 1); |
| 1307 | } |
| 1308 | } |
| 1309 | sourceURL = join(urlGenerate(parsed), sourceURL); |
| 1310 | } |
| 1311 | |
| 1312 | return normalize(sourceURL); |
| 1313 | } |
| 1314 | exports.computeSourceURL = computeSourceURL; |
| 1315 | |
| 1316 | |
| 1317 | /***/ }), |
| 1318 | /* 5 */ |
| 1319 | /***/ (function(module, exports, __webpack_require__) { |
| 1320 | |
| 1321 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 1322 | /* |
| 1323 | * Copyright 2011 Mozilla Foundation and contributors |
| 1324 | * Licensed under the New BSD license. See LICENSE or: |
| 1325 | * http://opensource.org/licenses/BSD-3-Clause |
| 1326 | */ |
| 1327 | |
| 1328 | var util = __webpack_require__(4); |
| 1329 | var has = Object.prototype.hasOwnProperty; |
| 1330 | var hasNativeMap = typeof Map !== "undefined"; |
| 1331 | |
| 1332 | /** |
| 1333 | * A data structure which is a combination of an array and a set. Adding a new |
| 1334 | * member is O(1), testing for membership is O(1), and finding the index of an |
| 1335 | * element is O(1). Removing elements from the set is not supported. Only |
| 1336 | * strings are supported for membership. |
| 1337 | */ |
| 1338 | function ArraySet() { |
| 1339 | this._array = []; |
| 1340 | this._set = hasNativeMap ? new Map() : Object.create(null); |
| 1341 | } |
| 1342 | |
| 1343 | /** |
| 1344 | * Static method for creating ArraySet instances from an existing array. |
| 1345 | */ |
| 1346 | ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) { |
| 1347 | var set = new ArraySet(); |
| 1348 | for (var i = 0, len = aArray.length; i < len; i++) { |
| 1349 | set.add(aArray[i], aAllowDuplicates); |
| 1350 | } |
| 1351 | return set; |
| 1352 | }; |
| 1353 | |
| 1354 | /** |
| 1355 | * Return how many unique items are in this ArraySet. If duplicates have been |
| 1356 | * added, than those do not count towards the size. |
| 1357 | * |
| 1358 | * @returns Number |
| 1359 | */ |
| 1360 | ArraySet.prototype.size = function ArraySet_size() { |
| 1361 | return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length; |
| 1362 | }; |
| 1363 | |
| 1364 | /** |
| 1365 | * Add the given string to this set. |
| 1366 | * |
| 1367 | * @param String aStr |
| 1368 | */ |
| 1369 | ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) { |
| 1370 | var sStr = hasNativeMap ? aStr : util.toSetString(aStr); |
| 1371 | var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr); |
| 1372 | var idx = this._array.length; |
| 1373 | if (!isDuplicate || aAllowDuplicates) { |
| 1374 | this._array.push(aStr); |
| 1375 | } |
| 1376 | if (!isDuplicate) { |
| 1377 | if (hasNativeMap) { |
| 1378 | this._set.set(aStr, idx); |
| 1379 | } else { |
| 1380 | this._set[sStr] = idx; |
| 1381 | } |
| 1382 | } |
| 1383 | }; |
| 1384 | |
| 1385 | /** |
| 1386 | * Is the given string a member of this set? |
| 1387 | * |
| 1388 | * @param String aStr |
| 1389 | */ |
| 1390 | ArraySet.prototype.has = function ArraySet_has(aStr) { |
| 1391 | if (hasNativeMap) { |
| 1392 | return this._set.has(aStr); |
| 1393 | } else { |
| 1394 | var sStr = util.toSetString(aStr); |
| 1395 | return has.call(this._set, sStr); |
| 1396 | } |
| 1397 | }; |
| 1398 | |
| 1399 | /** |
| 1400 | * What is the index of the given string in the array? |
| 1401 | * |
| 1402 | * @param String aStr |
| 1403 | */ |
| 1404 | ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) { |
| 1405 | if (hasNativeMap) { |
| 1406 | var idx = this._set.get(aStr); |
| 1407 | if (idx >= 0) { |
| 1408 | return idx; |
| 1409 | } |
| 1410 | } else { |
| 1411 | var sStr = util.toSetString(aStr); |
| 1412 | if (has.call(this._set, sStr)) { |
| 1413 | return this._set[sStr]; |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | throw new Error('"' + aStr + '" is not in the set.'); |
| 1418 | }; |
| 1419 | |
| 1420 | /** |
| 1421 | * What is the element at the given index? |
| 1422 | * |
| 1423 | * @param Number aIdx |
| 1424 | */ |
| 1425 | ArraySet.prototype.at = function ArraySet_at(aIdx) { |
| 1426 | if (aIdx >= 0 && aIdx < this._array.length) { |
| 1427 | return this._array[aIdx]; |
| 1428 | } |
| 1429 | throw new Error('No element indexed by ' + aIdx); |
| 1430 | }; |
| 1431 | |
| 1432 | /** |
| 1433 | * Returns the array representation of this set (which has the proper indices |
| 1434 | * indicated by indexOf). Note that this is a copy of the internal array used |
| 1435 | * for storing the members so that no one can mess with internal state. |
| 1436 | */ |
| 1437 | ArraySet.prototype.toArray = function ArraySet_toArray() { |
| 1438 | return this._array.slice(); |
| 1439 | }; |
| 1440 | |
| 1441 | exports.ArraySet = ArraySet; |
| 1442 | |
| 1443 | |
| 1444 | /***/ }), |
| 1445 | /* 6 */ |
| 1446 | /***/ (function(module, exports, __webpack_require__) { |
| 1447 | |
| 1448 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 1449 | /* |
| 1450 | * Copyright 2014 Mozilla Foundation and contributors |
| 1451 | * Licensed under the New BSD license. See LICENSE or: |
| 1452 | * http://opensource.org/licenses/BSD-3-Clause |
| 1453 | */ |
| 1454 | |
| 1455 | var util = __webpack_require__(4); |
| 1456 | |
| 1457 | /** |
| 1458 | * Determine whether mappingB is after mappingA with respect to generated |
| 1459 | * position. |
| 1460 | */ |
| 1461 | function generatedPositionAfter(mappingA, mappingB) { |
| 1462 | // Optimized for most common case |
| 1463 | var lineA = mappingA.generatedLine; |
| 1464 | var lineB = mappingB.generatedLine; |
| 1465 | var columnA = mappingA.generatedColumn; |
| 1466 | var columnB = mappingB.generatedColumn; |
| 1467 | return lineB > lineA || lineB == lineA && columnB >= columnA || |
| 1468 | util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0; |
| 1469 | } |
| 1470 | |
| 1471 | /** |
| 1472 | * A data structure to provide a sorted view of accumulated mappings in a |
| 1473 | * performance conscious manner. It trades a neglibable overhead in general |
| 1474 | * case for a large speedup in case of mappings being added in order. |
| 1475 | */ |
| 1476 | function MappingList() { |
| 1477 | this._array = []; |
| 1478 | this._sorted = true; |
| 1479 | // Serves as infimum |
| 1480 | this._last = {generatedLine: -1, generatedColumn: 0}; |
| 1481 | } |
| 1482 | |
| 1483 | /** |
| 1484 | * Iterate through internal items. This method takes the same arguments that |
| 1485 | * `Array.prototype.forEach` takes. |
| 1486 | * |
| 1487 | * NOTE: The order of the mappings is NOT guaranteed. |
| 1488 | */ |
| 1489 | MappingList.prototype.unsortedForEach = |
| 1490 | function MappingList_forEach(aCallback, aThisArg) { |
| 1491 | this._array.forEach(aCallback, aThisArg); |
| 1492 | }; |
| 1493 | |
| 1494 | /** |
| 1495 | * Add the given source mapping. |
| 1496 | * |
| 1497 | * @param Object aMapping |
| 1498 | */ |
| 1499 | MappingList.prototype.add = function MappingList_add(aMapping) { |
| 1500 | if (generatedPositionAfter(this._last, aMapping)) { |
| 1501 | this._last = aMapping; |
| 1502 | this._array.push(aMapping); |
| 1503 | } else { |
| 1504 | this._sorted = false; |
| 1505 | this._array.push(aMapping); |
| 1506 | } |
| 1507 | }; |
| 1508 | |
| 1509 | /** |
| 1510 | * Returns the flat, sorted array of mappings. The mappings are sorted by |
| 1511 | * generated position. |
| 1512 | * |
| 1513 | * WARNING: This method returns internal data without copying, for |
| 1514 | * performance. The return value must NOT be mutated, and should be treated as |
| 1515 | * an immutable borrow. If you want to take ownership, you must make your own |
| 1516 | * copy. |
| 1517 | */ |
| 1518 | MappingList.prototype.toArray = function MappingList_toArray() { |
| 1519 | if (!this._sorted) { |
| 1520 | this._array.sort(util.compareByGeneratedPositionsInflated); |
| 1521 | this._sorted = true; |
| 1522 | } |
| 1523 | return this._array; |
| 1524 | }; |
| 1525 | |
| 1526 | exports.MappingList = MappingList; |
| 1527 | |
| 1528 | |
| 1529 | /***/ }), |
| 1530 | /* 7 */ |
| 1531 | /***/ (function(module, exports, __webpack_require__) { |
| 1532 | |
| 1533 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 1534 | /* |
| 1535 | * Copyright 2011 Mozilla Foundation and contributors |
| 1536 | * Licensed under the New BSD license. See LICENSE or: |
| 1537 | * http://opensource.org/licenses/BSD-3-Clause |
| 1538 | */ |
| 1539 | |
| 1540 | var util = __webpack_require__(4); |
| 1541 | var binarySearch = __webpack_require__(8); |
| 1542 | var ArraySet = __webpack_require__(5).ArraySet; |
| 1543 | var base64VLQ = __webpack_require__(2); |
| 1544 | var quickSort = __webpack_require__(9).quickSort; |
| 1545 | |
| 1546 | function SourceMapConsumer(aSourceMap, aSourceMapURL) { |
| 1547 | var sourceMap = aSourceMap; |
| 1548 | if (typeof aSourceMap === 'string') { |
| 1549 | sourceMap = util.parseSourceMapInput(aSourceMap); |
| 1550 | } |
| 1551 | |
| 1552 | return sourceMap.sections != null |
| 1553 | ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL) |
| 1554 | : new BasicSourceMapConsumer(sourceMap, aSourceMapURL); |
| 1555 | } |
| 1556 | |
| 1557 | SourceMapConsumer.fromSourceMap = function(aSourceMap, aSourceMapURL) { |
| 1558 | return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL); |
| 1559 | } |
| 1560 | |
| 1561 | /** |
| 1562 | * The version of the source mapping spec that we are consuming. |
| 1563 | */ |
| 1564 | SourceMapConsumer.prototype._version = 3; |
| 1565 | |
| 1566 | // `__generatedMappings` and `__originalMappings` are arrays that hold the |
| 1567 | // parsed mapping coordinates from the source map's "mappings" attribute. They |
| 1568 | // are lazily instantiated, accessed via the `_generatedMappings` and |
| 1569 | // `_originalMappings` getters respectively, and we only parse the mappings |
| 1570 | // and create these arrays once queried for a source location. We jump through |
| 1571 | // these hoops because there can be many thousands of mappings, and parsing |
| 1572 | // them is expensive, so we only want to do it if we must. |
| 1573 | // |
| 1574 | // Each object in the arrays is of the form: |
| 1575 | // |
| 1576 | // { |
| 1577 | // generatedLine: The line number in the generated code, |
| 1578 | // generatedColumn: The column number in the generated code, |
| 1579 | // source: The path to the original source file that generated this |
| 1580 | // chunk of code, |
| 1581 | // originalLine: The line number in the original source that |
| 1582 | // corresponds to this chunk of generated code, |
| 1583 | // originalColumn: The column number in the original source that |
| 1584 | // corresponds to this chunk of generated code, |
| 1585 | // name: The name of the original symbol which generated this chunk of |
| 1586 | // code. |
| 1587 | // } |
| 1588 | // |
| 1589 | // All properties except for `generatedLine` and `generatedColumn` can be |
| 1590 | // `null`. |
| 1591 | // |
| 1592 | // `_generatedMappings` is ordered by the generated positions. |
| 1593 | // |
| 1594 | // `_originalMappings` is ordered by the original positions. |
| 1595 | |
| 1596 | SourceMapConsumer.prototype.__generatedMappings = null; |
| 1597 | Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', { |
| 1598 | configurable: true, |
| 1599 | enumerable: true, |
| 1600 | get: function () { |
| 1601 | if (!this.__generatedMappings) { |
| 1602 | this._parseMappings(this._mappings, this.sourceRoot); |
| 1603 | } |
| 1604 | |
| 1605 | return this.__generatedMappings; |
| 1606 | } |
| 1607 | }); |
| 1608 | |
| 1609 | SourceMapConsumer.prototype.__originalMappings = null; |
| 1610 | Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', { |
| 1611 | configurable: true, |
| 1612 | enumerable: true, |
| 1613 | get: function () { |
| 1614 | if (!this.__originalMappings) { |
| 1615 | this._parseMappings(this._mappings, this.sourceRoot); |
| 1616 | } |
| 1617 | |
| 1618 | return this.__originalMappings; |
| 1619 | } |
| 1620 | }); |
| 1621 | |
| 1622 | SourceMapConsumer.prototype._charIsMappingSeparator = |
| 1623 | function SourceMapConsumer_charIsMappingSeparator(aStr, index) { |
| 1624 | var c = aStr.charAt(index); |
| 1625 | return c === ";" || c === ","; |
| 1626 | }; |
| 1627 | |
| 1628 | /** |
| 1629 | * Parse the mappings in a string in to a data structure which we can easily |
| 1630 | * query (the ordered arrays in the `this.__generatedMappings` and |
| 1631 | * `this.__originalMappings` properties). |
| 1632 | */ |
| 1633 | SourceMapConsumer.prototype._parseMappings = |
| 1634 | function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { |
| 1635 | throw new Error("Subclasses must implement _parseMappings"); |
| 1636 | }; |
| 1637 | |
| 1638 | SourceMapConsumer.GENERATED_ORDER = 1; |
| 1639 | SourceMapConsumer.ORIGINAL_ORDER = 2; |
| 1640 | |
| 1641 | SourceMapConsumer.GREATEST_LOWER_BOUND = 1; |
| 1642 | SourceMapConsumer.LEAST_UPPER_BOUND = 2; |
| 1643 | |
| 1644 | /** |
| 1645 | * Iterate over each mapping between an original source/line/column and a |
| 1646 | * generated line/column in this source map. |
| 1647 | * |
| 1648 | * @param Function aCallback |
| 1649 | * The function that is called with each mapping. |
| 1650 | * @param Object aContext |
| 1651 | * Optional. If specified, this object will be the value of `this` every |
| 1652 | * time that `aCallback` is called. |
| 1653 | * @param aOrder |
| 1654 | * Either `SourceMapConsumer.GENERATED_ORDER` or |
| 1655 | * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to |
| 1656 | * iterate over the mappings sorted by the generated file's line/column |
| 1657 | * order or the original's source/line/column order, respectively. Defaults to |
| 1658 | * `SourceMapConsumer.GENERATED_ORDER`. |
| 1659 | */ |
| 1660 | SourceMapConsumer.prototype.eachMapping = |
| 1661 | function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) { |
| 1662 | var context = aContext || null; |
| 1663 | var order = aOrder || SourceMapConsumer.GENERATED_ORDER; |
| 1664 | |
| 1665 | var mappings; |
| 1666 | switch (order) { |
| 1667 | case SourceMapConsumer.GENERATED_ORDER: |
| 1668 | mappings = this._generatedMappings; |
| 1669 | break; |
| 1670 | case SourceMapConsumer.ORIGINAL_ORDER: |
| 1671 | mappings = this._originalMappings; |
| 1672 | break; |
| 1673 | default: |
| 1674 | throw new Error("Unknown order of iteration."); |
| 1675 | } |
| 1676 | |
| 1677 | var sourceRoot = this.sourceRoot; |
| 1678 | mappings.map(function (mapping) { |
| 1679 | var source = mapping.source === null ? null : this._sources.at(mapping.source); |
| 1680 | source = util.computeSourceURL(sourceRoot, source, this._sourceMapURL); |
| 1681 | return { |
| 1682 | source: source, |
| 1683 | generatedLine: mapping.generatedLine, |
| 1684 | generatedColumn: mapping.generatedColumn, |
| 1685 | originalLine: mapping.originalLine, |
| 1686 | originalColumn: mapping.originalColumn, |
| 1687 | name: mapping.name === null ? null : this._names.at(mapping.name) |
| 1688 | }; |
| 1689 | }, this).forEach(aCallback, context); |
| 1690 | }; |
| 1691 | |
| 1692 | /** |
| 1693 | * Returns all generated line and column information for the original source, |
| 1694 | * line, and column provided. If no column is provided, returns all mappings |
| 1695 | * corresponding to a either the line we are searching for or the next |
| 1696 | * closest line that has any mappings. Otherwise, returns all mappings |
| 1697 | * corresponding to the given line and either the column we are searching for |
| 1698 | * or the next closest column that has any offsets. |
| 1699 | * |
| 1700 | * The only argument is an object with the following properties: |
| 1701 | * |
| 1702 | * - source: The filename of the original source. |
| 1703 | * - line: The line number in the original source. The line number is 1-based. |
| 1704 | * - column: Optional. the column number in the original source. |
| 1705 | * The column number is 0-based. |
| 1706 | * |
| 1707 | * and an array of objects is returned, each with the following properties: |
| 1708 | * |
| 1709 | * - line: The line number in the generated source, or null. The |
| 1710 | * line number is 1-based. |
| 1711 | * - column: The column number in the generated source, or null. |
| 1712 | * The column number is 0-based. |
| 1713 | */ |
| 1714 | SourceMapConsumer.prototype.allGeneratedPositionsFor = |
| 1715 | function SourceMapConsumer_allGeneratedPositionsFor(aArgs) { |
| 1716 | var line = util.getArg(aArgs, 'line'); |
| 1717 | |
| 1718 | // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping |
| 1719 | // returns the index of the closest mapping less than the needle. By |
| 1720 | // setting needle.originalColumn to 0, we thus find the last mapping for |
| 1721 | // the given line, provided such a mapping exists. |
| 1722 | var needle = { |
| 1723 | source: util.getArg(aArgs, 'source'), |
| 1724 | originalLine: line, |
| 1725 | originalColumn: util.getArg(aArgs, 'column', 0) |
| 1726 | }; |
| 1727 | |
| 1728 | needle.source = this._findSourceIndex(needle.source); |
| 1729 | if (needle.source < 0) { |
| 1730 | return []; |
| 1731 | } |
| 1732 | |
| 1733 | var mappings = []; |
| 1734 | |
| 1735 | var index = this._findMapping(needle, |
| 1736 | this._originalMappings, |
| 1737 | "originalLine", |
| 1738 | "originalColumn", |
| 1739 | util.compareByOriginalPositions, |
| 1740 | binarySearch.LEAST_UPPER_BOUND); |
| 1741 | if (index >= 0) { |
| 1742 | var mapping = this._originalMappings[index]; |
| 1743 | |
| 1744 | if (aArgs.column === undefined) { |
| 1745 | var originalLine = mapping.originalLine; |
| 1746 | |
| 1747 | // Iterate until either we run out of mappings, or we run into |
| 1748 | // a mapping for a different line than the one we found. Since |
| 1749 | // mappings are sorted, this is guaranteed to find all mappings for |
| 1750 | // the line we found. |
| 1751 | while (mapping && mapping.originalLine === originalLine) { |
| 1752 | mappings.push({ |
| 1753 | line: util.getArg(mapping, 'generatedLine', null), |
| 1754 | column: util.getArg(mapping, 'generatedColumn', null), |
| 1755 | lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) |
| 1756 | }); |
| 1757 | |
| 1758 | mapping = this._originalMappings[++index]; |
| 1759 | } |
| 1760 | } else { |
| 1761 | var originalColumn = mapping.originalColumn; |
| 1762 | |
| 1763 | // Iterate until either we run out of mappings, or we run into |
| 1764 | // a mapping for a different line than the one we were searching for. |
| 1765 | // Since mappings are sorted, this is guaranteed to find all mappings for |
| 1766 | // the line we are searching for. |
| 1767 | while (mapping && |
| 1768 | mapping.originalLine === line && |
| 1769 | mapping.originalColumn == originalColumn) { |
| 1770 | mappings.push({ |
| 1771 | line: util.getArg(mapping, 'generatedLine', null), |
| 1772 | column: util.getArg(mapping, 'generatedColumn', null), |
| 1773 | lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) |
| 1774 | }); |
| 1775 | |
| 1776 | mapping = this._originalMappings[++index]; |
| 1777 | } |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | return mappings; |
| 1782 | }; |
| 1783 | |
| 1784 | exports.SourceMapConsumer = SourceMapConsumer; |
| 1785 | |
| 1786 | /** |
| 1787 | * A BasicSourceMapConsumer instance represents a parsed source map which we can |
| 1788 | * query for information about the original file positions by giving it a file |
| 1789 | * position in the generated source. |
| 1790 | * |
| 1791 | * The first parameter is the raw source map (either as a JSON string, or |
| 1792 | * already parsed to an object). According to the spec, source maps have the |
| 1793 | * following attributes: |
| 1794 | * |
| 1795 | * - version: Which version of the source map spec this map is following. |
| 1796 | * - sources: An array of URLs to the original source files. |
| 1797 | * - names: An array of identifiers which can be referrenced by individual mappings. |
| 1798 | * - sourceRoot: Optional. The URL root from which all sources are relative. |
| 1799 | * - sourcesContent: Optional. An array of contents of the original source files. |
| 1800 | * - mappings: A string of base64 VLQs which contain the actual mappings. |
| 1801 | * - file: Optional. The generated file this source map is associated with. |
| 1802 | * |
| 1803 | * Here is an example source map, taken from the source map spec[0]: |
| 1804 | * |
| 1805 | * { |
| 1806 | * version : 3, |
| 1807 | * file: "out.js", |
| 1808 | * sourceRoot : "", |
| 1809 | * sources: ["foo.js", "bar.js"], |
| 1810 | * names: ["src", "maps", "are", "fun"], |
| 1811 | * mappings: "AA,AB;;ABCDE;" |
| 1812 | * } |
| 1813 | * |
| 1814 | * The second parameter, if given, is a string whose value is the URL |
| 1815 | * at which the source map was found. This URL is used to compute the |
| 1816 | * sources array. |
| 1817 | * |
| 1818 | * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1# |
| 1819 | */ |
| 1820 | function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) { |
| 1821 | var sourceMap = aSourceMap; |
| 1822 | if (typeof aSourceMap === 'string') { |
| 1823 | sourceMap = util.parseSourceMapInput(aSourceMap); |
| 1824 | } |
| 1825 | |
| 1826 | var version = util.getArg(sourceMap, 'version'); |
| 1827 | var sources = util.getArg(sourceMap, 'sources'); |
| 1828 | // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which |
| 1829 | // requires the array) to play nice here. |
| 1830 | var names = util.getArg(sourceMap, 'names', []); |
| 1831 | var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null); |
| 1832 | var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null); |
| 1833 | var mappings = util.getArg(sourceMap, 'mappings'); |
| 1834 | var file = util.getArg(sourceMap, 'file', null); |
| 1835 | |
| 1836 | // Once again, Sass deviates from the spec and supplies the version as a |
| 1837 | // string rather than a number, so we use loose equality checking here. |
| 1838 | if (version != this._version) { |
| 1839 | throw new Error('Unsupported version: ' + version); |
| 1840 | } |
| 1841 | |
| 1842 | if (sourceRoot) { |
| 1843 | sourceRoot = util.normalize(sourceRoot); |
| 1844 | } |
| 1845 | |
| 1846 | sources = sources |
| 1847 | .map(String) |
| 1848 | // Some source maps produce relative source paths like "./foo.js" instead of |
| 1849 | // "foo.js". Normalize these first so that future comparisons will succeed. |
| 1850 | // See bugzil.la/1090768. |
| 1851 | .map(util.normalize) |
| 1852 | // Always ensure that absolute sources are internally stored relative to |
| 1853 | // the source root, if the source root is absolute. Not doing this would |
| 1854 | // be particularly problematic when the source root is a prefix of the |
| 1855 | // source (valid, but why??). See github issue #199 and bugzil.la/1188982. |
| 1856 | .map(function (source) { |
| 1857 | return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source) |
| 1858 | ? util.relative(sourceRoot, source) |
| 1859 | : source; |
| 1860 | }); |
| 1861 | |
| 1862 | // Pass `true` below to allow duplicate names and sources. While source maps |
| 1863 | // are intended to be compressed and deduplicated, the TypeScript compiler |
| 1864 | // sometimes generates source maps with duplicates in them. See Github issue |
| 1865 | // #72 and bugzil.la/889492. |
| 1866 | this._names = ArraySet.fromArray(names.map(String), true); |
| 1867 | this._sources = ArraySet.fromArray(sources, true); |
| 1868 | |
| 1869 | this._absoluteSources = this._sources.toArray().map(function (s) { |
| 1870 | return util.computeSourceURL(sourceRoot, s, aSourceMapURL); |
| 1871 | }); |
| 1872 | |
| 1873 | this.sourceRoot = sourceRoot; |
| 1874 | this.sourcesContent = sourcesContent; |
| 1875 | this._mappings = mappings; |
| 1876 | this._sourceMapURL = aSourceMapURL; |
| 1877 | this.file = file; |
| 1878 | } |
| 1879 | |
| 1880 | BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); |
| 1881 | BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer; |
| 1882 | |
| 1883 | /** |
| 1884 | * Utility function to find the index of a source. Returns -1 if not |
| 1885 | * found. |
| 1886 | */ |
| 1887 | BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) { |
| 1888 | var relativeSource = aSource; |
| 1889 | if (this.sourceRoot != null) { |
| 1890 | relativeSource = util.relative(this.sourceRoot, relativeSource); |
| 1891 | } |
| 1892 | |
| 1893 | if (this._sources.has(relativeSource)) { |
| 1894 | return this._sources.indexOf(relativeSource); |
| 1895 | } |
| 1896 | |
| 1897 | // Maybe aSource is an absolute URL as returned by |sources|. In |
| 1898 | // this case we can't simply undo the transform. |
| 1899 | var i; |
| 1900 | for (i = 0; i < this._absoluteSources.length; ++i) { |
| 1901 | if (this._absoluteSources[i] == aSource) { |
| 1902 | return i; |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | return -1; |
| 1907 | }; |
| 1908 | |
| 1909 | /** |
| 1910 | * Create a BasicSourceMapConsumer from a SourceMapGenerator. |
| 1911 | * |
| 1912 | * @param SourceMapGenerator aSourceMap |
| 1913 | * The source map that will be consumed. |
| 1914 | * @param String aSourceMapURL |
| 1915 | * The URL at which the source map can be found (optional) |
| 1916 | * @returns BasicSourceMapConsumer |
| 1917 | */ |
| 1918 | BasicSourceMapConsumer.fromSourceMap = |
| 1919 | function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) { |
| 1920 | var smc = Object.create(BasicSourceMapConsumer.prototype); |
| 1921 | |
| 1922 | var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true); |
| 1923 | var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true); |
| 1924 | smc.sourceRoot = aSourceMap._sourceRoot; |
| 1925 | smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(), |
| 1926 | smc.sourceRoot); |
| 1927 | smc.file = aSourceMap._file; |
| 1928 | smc._sourceMapURL = aSourceMapURL; |
| 1929 | smc._absoluteSources = smc._sources.toArray().map(function (s) { |
| 1930 | return util.computeSourceURL(smc.sourceRoot, s, aSourceMapURL); |
| 1931 | }); |
| 1932 | |
| 1933 | // Because we are modifying the entries (by converting string sources and |
| 1934 | // names to indices into the sources and names ArraySets), we have to make |
| 1935 | // a copy of the entry or else bad things happen. Shared mutable state |
| 1936 | // strikes again! See github issue #191. |
| 1937 | |
| 1938 | var generatedMappings = aSourceMap._mappings.toArray().slice(); |
| 1939 | var destGeneratedMappings = smc.__generatedMappings = []; |
| 1940 | var destOriginalMappings = smc.__originalMappings = []; |
| 1941 | |
| 1942 | for (var i = 0, length = generatedMappings.length; i < length; i++) { |
| 1943 | var srcMapping = generatedMappings[i]; |
| 1944 | var destMapping = new Mapping; |
| 1945 | destMapping.generatedLine = srcMapping.generatedLine; |
| 1946 | destMapping.generatedColumn = srcMapping.generatedColumn; |
| 1947 | |
| 1948 | if (srcMapping.source) { |
| 1949 | destMapping.source = sources.indexOf(srcMapping.source); |
| 1950 | destMapping.originalLine = srcMapping.originalLine; |
| 1951 | destMapping.originalColumn = srcMapping.originalColumn; |
| 1952 | |
| 1953 | if (srcMapping.name) { |
| 1954 | destMapping.name = names.indexOf(srcMapping.name); |
| 1955 | } |
| 1956 | |
| 1957 | destOriginalMappings.push(destMapping); |
| 1958 | } |
| 1959 | |
| 1960 | destGeneratedMappings.push(destMapping); |
| 1961 | } |
| 1962 | |
| 1963 | quickSort(smc.__originalMappings, util.compareByOriginalPositions); |
| 1964 | |
| 1965 | return smc; |
| 1966 | }; |
| 1967 | |
| 1968 | /** |
| 1969 | * The version of the source mapping spec that we are consuming. |
| 1970 | */ |
| 1971 | BasicSourceMapConsumer.prototype._version = 3; |
| 1972 | |
| 1973 | /** |
| 1974 | * The list of original sources. |
| 1975 | */ |
| 1976 | Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', { |
| 1977 | get: function () { |
| 1978 | return this._absoluteSources.slice(); |
| 1979 | } |
| 1980 | }); |
| 1981 | |
| 1982 | /** |
| 1983 | * Provide the JIT with a nice shape / hidden class. |
| 1984 | */ |
| 1985 | function Mapping() { |
| 1986 | this.generatedLine = 0; |
| 1987 | this.generatedColumn = 0; |
| 1988 | this.source = null; |
| 1989 | this.originalLine = null; |
| 1990 | this.originalColumn = null; |
| 1991 | this.name = null; |
| 1992 | } |
| 1993 | |
| 1994 | /** |
| 1995 | * Parse the mappings in a string in to a data structure which we can easily |
| 1996 | * query (the ordered arrays in the `this.__generatedMappings` and |
| 1997 | * `this.__originalMappings` properties). |
| 1998 | */ |
| 1999 | |
| 2000 | const compareGenerated = util.compareByGeneratedPositionsDeflatedNoLine; |
| 2001 | function sortGenerated(array, start) { |
| 2002 | let l = array.length; |
| 2003 | let n = array.length - start; |
| 2004 | if (n <= 1) { |
| 2005 | return; |
| 2006 | } else if (n == 2) { |
| 2007 | let a = array[start]; |
| 2008 | let b = array[start + 1]; |
| 2009 | if (compareGenerated(a, b) > 0) { |
| 2010 | array[start] = b; |
| 2011 | array[start + 1] = a; |
| 2012 | } |
| 2013 | } else if (n < 20) { |
| 2014 | for (let i = start; i < l; i++) { |
| 2015 | for (let j = i; j > start; j--) { |
| 2016 | let a = array[j - 1]; |
| 2017 | let b = array[j]; |
| 2018 | if (compareGenerated(a, b) <= 0) { |
| 2019 | break; |
| 2020 | } |
| 2021 | array[j - 1] = b; |
| 2022 | array[j] = a; |
| 2023 | } |
| 2024 | } |
| 2025 | } else { |
| 2026 | quickSort(array, compareGenerated, start); |
| 2027 | } |
| 2028 | } |
| 2029 | BasicSourceMapConsumer.prototype._parseMappings = |
| 2030 | function SourceMapConsumer_parseMappings(aStr, aSourceRoot) { |
| 2031 | var generatedLine = 1; |
| 2032 | var previousGeneratedColumn = 0; |
| 2033 | var previousOriginalLine = 0; |
| 2034 | var previousOriginalColumn = 0; |
| 2035 | var previousSource = 0; |
| 2036 | var previousName = 0; |
| 2037 | var length = aStr.length; |
| 2038 | var index = 0; |
| 2039 | var cachedSegments = {}; |
| 2040 | var temp = {}; |
| 2041 | var originalMappings = []; |
| 2042 | var generatedMappings = []; |
| 2043 | var mapping, str, segment, end, value; |
| 2044 | |
| 2045 | let subarrayStart = 0; |
| 2046 | while (index < length) { |
| 2047 | if (aStr.charAt(index) === ';') { |
| 2048 | generatedLine++; |
| 2049 | index++; |
| 2050 | previousGeneratedColumn = 0; |
| 2051 | |
| 2052 | sortGenerated(generatedMappings, subarrayStart); |
| 2053 | subarrayStart = generatedMappings.length; |
| 2054 | } |
| 2055 | else if (aStr.charAt(index) === ',') { |
| 2056 | index++; |
| 2057 | } |
| 2058 | else { |
| 2059 | mapping = new Mapping(); |
| 2060 | mapping.generatedLine = generatedLine; |
| 2061 | |
| 2062 | for (end = index; end < length; end++) { |
| 2063 | if (this._charIsMappingSeparator(aStr, end)) { |
| 2064 | break; |
| 2065 | } |
| 2066 | } |
| 2067 | str = aStr.slice(index, end); |
| 2068 | |
| 2069 | segment = []; |
| 2070 | while (index < end) { |
| 2071 | base64VLQ.decode(aStr, index, temp); |
| 2072 | value = temp.value; |
| 2073 | index = temp.rest; |
| 2074 | segment.push(value); |
| 2075 | } |
| 2076 | |
| 2077 | if (segment.length === 2) { |
| 2078 | throw new Error('Found a source, but no line and column'); |
| 2079 | } |
| 2080 | |
| 2081 | if (segment.length === 3) { |
| 2082 | throw new Error('Found a source and line, but no column'); |
| 2083 | } |
| 2084 | |
| 2085 | // Generated column. |
| 2086 | mapping.generatedColumn = previousGeneratedColumn + segment[0]; |
| 2087 | previousGeneratedColumn = mapping.generatedColumn; |
| 2088 | |
| 2089 | if (segment.length > 1) { |
| 2090 | // Original source. |
| 2091 | mapping.source = previousSource + segment[1]; |
| 2092 | previousSource += segment[1]; |
| 2093 | |
| 2094 | // Original line. |
| 2095 | mapping.originalLine = previousOriginalLine + segment[2]; |
| 2096 | previousOriginalLine = mapping.originalLine; |
| 2097 | // Lines are stored 0-based |
| 2098 | mapping.originalLine += 1; |
| 2099 | |
| 2100 | // Original column. |
| 2101 | mapping.originalColumn = previousOriginalColumn + segment[3]; |
| 2102 | previousOriginalColumn = mapping.originalColumn; |
| 2103 | |
| 2104 | if (segment.length > 4) { |
| 2105 | // Original name. |
| 2106 | mapping.name = previousName + segment[4]; |
| 2107 | previousName += segment[4]; |
| 2108 | } |
| 2109 | } |
| 2110 | |
| 2111 | generatedMappings.push(mapping); |
| 2112 | if (typeof mapping.originalLine === 'number') { |
| 2113 | let currentSource = mapping.source; |
| 2114 | while (originalMappings.length <= currentSource) { |
| 2115 | originalMappings.push(null); |
| 2116 | } |
| 2117 | if (originalMappings[currentSource] === null) { |
| 2118 | originalMappings[currentSource] = []; |
| 2119 | } |
| 2120 | originalMappings[currentSource].push(mapping); |
| 2121 | } |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | sortGenerated(generatedMappings, subarrayStart); |
| 2126 | this.__generatedMappings = generatedMappings; |
| 2127 | |
| 2128 | for (var i = 0; i < originalMappings.length; i++) { |
| 2129 | if (originalMappings[i] != null) { |
| 2130 | quickSort(originalMappings[i], util.compareByOriginalPositionsNoSource); |
| 2131 | } |
| 2132 | } |
| 2133 | this.__originalMappings = [].concat(...originalMappings); |
| 2134 | }; |
| 2135 | |
| 2136 | /** |
| 2137 | * Find the mapping that best matches the hypothetical "needle" mapping that |
| 2138 | * we are searching for in the given "haystack" of mappings. |
| 2139 | */ |
| 2140 | BasicSourceMapConsumer.prototype._findMapping = |
| 2141 | function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName, |
| 2142 | aColumnName, aComparator, aBias) { |
| 2143 | // To return the position we are searching for, we must first find the |
| 2144 | // mapping for the given position and then return the opposite position it |
| 2145 | // points to. Because the mappings are sorted, we can use binary search to |
| 2146 | // find the best mapping. |
| 2147 | |
| 2148 | if (aNeedle[aLineName] <= 0) { |
| 2149 | throw new TypeError('Line must be greater than or equal to 1, got ' |
| 2150 | + aNeedle[aLineName]); |
| 2151 | } |
| 2152 | if (aNeedle[aColumnName] < 0) { |
| 2153 | throw new TypeError('Column must be greater than or equal to 0, got ' |
| 2154 | + aNeedle[aColumnName]); |
| 2155 | } |
| 2156 | |
| 2157 | return binarySearch.search(aNeedle, aMappings, aComparator, aBias); |
| 2158 | }; |
| 2159 | |
| 2160 | /** |
| 2161 | * Compute the last column for each generated mapping. The last column is |
| 2162 | * inclusive. |
| 2163 | */ |
| 2164 | BasicSourceMapConsumer.prototype.computeColumnSpans = |
| 2165 | function SourceMapConsumer_computeColumnSpans() { |
| 2166 | for (var index = 0; index < this._generatedMappings.length; ++index) { |
| 2167 | var mapping = this._generatedMappings[index]; |
| 2168 | |
| 2169 | // Mappings do not contain a field for the last generated columnt. We |
| 2170 | // can come up with an optimistic estimate, however, by assuming that |
| 2171 | // mappings are contiguous (i.e. given two consecutive mappings, the |
| 2172 | // first mapping ends where the second one starts). |
| 2173 | if (index + 1 < this._generatedMappings.length) { |
| 2174 | var nextMapping = this._generatedMappings[index + 1]; |
| 2175 | |
| 2176 | if (mapping.generatedLine === nextMapping.generatedLine) { |
| 2177 | mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1; |
| 2178 | continue; |
| 2179 | } |
| 2180 | } |
| 2181 | |
| 2182 | // The last mapping for each line spans the entire line. |
| 2183 | mapping.lastGeneratedColumn = Infinity; |
| 2184 | } |
| 2185 | }; |
| 2186 | |
| 2187 | /** |
| 2188 | * Returns the original source, line, and column information for the generated |
| 2189 | * source's line and column positions provided. The only argument is an object |
| 2190 | * with the following properties: |
| 2191 | * |
| 2192 | * - line: The line number in the generated source. The line number |
| 2193 | * is 1-based. |
| 2194 | * - column: The column number in the generated source. The column |
| 2195 | * number is 0-based. |
| 2196 | * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or |
| 2197 | * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the |
| 2198 | * closest element that is smaller than or greater than the one we are |
| 2199 | * searching for, respectively, if the exact element cannot be found. |
| 2200 | * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. |
| 2201 | * |
| 2202 | * and an object is returned with the following properties: |
| 2203 | * |
| 2204 | * - source: The original source file, or null. |
| 2205 | * - line: The line number in the original source, or null. The |
| 2206 | * line number is 1-based. |
| 2207 | * - column: The column number in the original source, or null. The |
| 2208 | * column number is 0-based. |
| 2209 | * - name: The original identifier, or null. |
| 2210 | */ |
| 2211 | BasicSourceMapConsumer.prototype.originalPositionFor = |
| 2212 | function SourceMapConsumer_originalPositionFor(aArgs) { |
| 2213 | var needle = { |
| 2214 | generatedLine: util.getArg(aArgs, 'line'), |
| 2215 | generatedColumn: util.getArg(aArgs, 'column') |
| 2216 | }; |
| 2217 | |
| 2218 | var index = this._findMapping( |
| 2219 | needle, |
| 2220 | this._generatedMappings, |
| 2221 | "generatedLine", |
| 2222 | "generatedColumn", |
| 2223 | util.compareByGeneratedPositionsDeflated, |
| 2224 | util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) |
| 2225 | ); |
| 2226 | |
| 2227 | if (index >= 0) { |
| 2228 | var mapping = this._generatedMappings[index]; |
| 2229 | |
| 2230 | if (mapping.generatedLine === needle.generatedLine) { |
| 2231 | var source = util.getArg(mapping, 'source', null); |
| 2232 | if (source !== null) { |
| 2233 | source = this._sources.at(source); |
| 2234 | source = util.computeSourceURL(this.sourceRoot, source, this._sourceMapURL); |
| 2235 | } |
| 2236 | var name = util.getArg(mapping, 'name', null); |
| 2237 | if (name !== null) { |
| 2238 | name = this._names.at(name); |
| 2239 | } |
| 2240 | return { |
| 2241 | source: source, |
| 2242 | line: util.getArg(mapping, 'originalLine', null), |
| 2243 | column: util.getArg(mapping, 'originalColumn', null), |
| 2244 | name: name |
| 2245 | }; |
| 2246 | } |
| 2247 | } |
| 2248 | |
| 2249 | return { |
| 2250 | source: null, |
| 2251 | line: null, |
| 2252 | column: null, |
| 2253 | name: null |
| 2254 | }; |
| 2255 | }; |
| 2256 | |
| 2257 | /** |
| 2258 | * Return true if we have the source content for every source in the source |
| 2259 | * map, false otherwise. |
| 2260 | */ |
| 2261 | BasicSourceMapConsumer.prototype.hasContentsOfAllSources = |
| 2262 | function BasicSourceMapConsumer_hasContentsOfAllSources() { |
| 2263 | if (!this.sourcesContent) { |
| 2264 | return false; |
| 2265 | } |
| 2266 | return this.sourcesContent.length >= this._sources.size() && |
| 2267 | !this.sourcesContent.some(function (sc) { return sc == null; }); |
| 2268 | }; |
| 2269 | |
| 2270 | /** |
| 2271 | * Returns the original source content. The only argument is the url of the |
| 2272 | * original source file. Returns null if no original source content is |
| 2273 | * available. |
| 2274 | */ |
| 2275 | BasicSourceMapConsumer.prototype.sourceContentFor = |
| 2276 | function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { |
| 2277 | if (!this.sourcesContent) { |
| 2278 | return null; |
| 2279 | } |
| 2280 | |
| 2281 | var index = this._findSourceIndex(aSource); |
| 2282 | if (index >= 0) { |
| 2283 | return this.sourcesContent[index]; |
| 2284 | } |
| 2285 | |
| 2286 | var relativeSource = aSource; |
| 2287 | if (this.sourceRoot != null) { |
| 2288 | relativeSource = util.relative(this.sourceRoot, relativeSource); |
| 2289 | } |
| 2290 | |
| 2291 | var url; |
| 2292 | if (this.sourceRoot != null |
| 2293 | && (url = util.urlParse(this.sourceRoot))) { |
| 2294 | // XXX: file:// URIs and absolute paths lead to unexpected behavior for |
| 2295 | // many users. We can help them out when they expect file:// URIs to |
| 2296 | // behave like it would if they were running a local HTTP server. See |
| 2297 | // https://bugzilla.mozilla.org/show_bug.cgi?id=885597. |
| 2298 | var fileUriAbsPath = relativeSource.replace(/^file:\/\//, ""); |
| 2299 | if (url.scheme == "file" |
| 2300 | && this._sources.has(fileUriAbsPath)) { |
| 2301 | return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)] |
| 2302 | } |
| 2303 | |
| 2304 | if ((!url.path || url.path == "/") |
| 2305 | && this._sources.has("/" + relativeSource)) { |
| 2306 | return this.sourcesContent[this._sources.indexOf("/" + relativeSource)]; |
| 2307 | } |
| 2308 | } |
| 2309 | |
| 2310 | // This function is used recursively from |
| 2311 | // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we |
| 2312 | // don't want to throw if we can't find the source - we just want to |
| 2313 | // return null, so we provide a flag to exit gracefully. |
| 2314 | if (nullOnMissing) { |
| 2315 | return null; |
| 2316 | } |
| 2317 | else { |
| 2318 | throw new Error('"' + relativeSource + '" is not in the SourceMap.'); |
| 2319 | } |
| 2320 | }; |
| 2321 | |
| 2322 | /** |
| 2323 | * Returns the generated line and column information for the original source, |
| 2324 | * line, and column positions provided. The only argument is an object with |
| 2325 | * the following properties: |
| 2326 | * |
| 2327 | * - source: The filename of the original source. |
| 2328 | * - line: The line number in the original source. The line number |
| 2329 | * is 1-based. |
| 2330 | * - column: The column number in the original source. The column |
| 2331 | * number is 0-based. |
| 2332 | * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or |
| 2333 | * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the |
| 2334 | * closest element that is smaller than or greater than the one we are |
| 2335 | * searching for, respectively, if the exact element cannot be found. |
| 2336 | * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'. |
| 2337 | * |
| 2338 | * and an object is returned with the following properties: |
| 2339 | * |
| 2340 | * - line: The line number in the generated source, or null. The |
| 2341 | * line number is 1-based. |
| 2342 | * - column: The column number in the generated source, or null. |
| 2343 | * The column number is 0-based. |
| 2344 | */ |
| 2345 | BasicSourceMapConsumer.prototype.generatedPositionFor = |
| 2346 | function SourceMapConsumer_generatedPositionFor(aArgs) { |
| 2347 | var source = util.getArg(aArgs, 'source'); |
| 2348 | source = this._findSourceIndex(source); |
| 2349 | if (source < 0) { |
| 2350 | return { |
| 2351 | line: null, |
| 2352 | column: null, |
| 2353 | lastColumn: null |
| 2354 | }; |
| 2355 | } |
| 2356 | |
| 2357 | var needle = { |
| 2358 | source: source, |
| 2359 | originalLine: util.getArg(aArgs, 'line'), |
| 2360 | originalColumn: util.getArg(aArgs, 'column') |
| 2361 | }; |
| 2362 | |
| 2363 | var index = this._findMapping( |
| 2364 | needle, |
| 2365 | this._originalMappings, |
| 2366 | "originalLine", |
| 2367 | "originalColumn", |
| 2368 | util.compareByOriginalPositions, |
| 2369 | util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND) |
| 2370 | ); |
| 2371 | |
| 2372 | if (index >= 0) { |
| 2373 | var mapping = this._originalMappings[index]; |
| 2374 | |
| 2375 | if (mapping.source === needle.source) { |
| 2376 | return { |
| 2377 | line: util.getArg(mapping, 'generatedLine', null), |
| 2378 | column: util.getArg(mapping, 'generatedColumn', null), |
| 2379 | lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null) |
| 2380 | }; |
| 2381 | } |
| 2382 | } |
| 2383 | |
| 2384 | return { |
| 2385 | line: null, |
| 2386 | column: null, |
| 2387 | lastColumn: null |
| 2388 | }; |
| 2389 | }; |
| 2390 | |
| 2391 | exports.BasicSourceMapConsumer = BasicSourceMapConsumer; |
| 2392 | |
| 2393 | /** |
| 2394 | * An IndexedSourceMapConsumer instance represents a parsed source map which |
| 2395 | * we can query for information. It differs from BasicSourceMapConsumer in |
| 2396 | * that it takes "indexed" source maps (i.e. ones with a "sections" field) as |
| 2397 | * input. |
| 2398 | * |
| 2399 | * The first parameter is a raw source map (either as a JSON string, or already |
| 2400 | * parsed to an object). According to the spec for indexed source maps, they |
| 2401 | * have the following attributes: |
| 2402 | * |
| 2403 | * - version: Which version of the source map spec this map is following. |
| 2404 | * - file: Optional. The generated file this source map is associated with. |
| 2405 | * - sections: A list of section definitions. |
| 2406 | * |
| 2407 | * Each value under the "sections" field has two fields: |
| 2408 | * - offset: The offset into the original specified at which this section |
| 2409 | * begins to apply, defined as an object with a "line" and "column" |
| 2410 | * field. |
| 2411 | * - map: A source map definition. This source map could also be indexed, |
| 2412 | * but doesn't have to be. |
| 2413 | * |
| 2414 | * Instead of the "map" field, it's also possible to have a "url" field |
| 2415 | * specifying a URL to retrieve a source map from, but that's currently |
| 2416 | * unsupported. |
| 2417 | * |
| 2418 | * Here's an example source map, taken from the source map spec[0], but |
| 2419 | * modified to omit a section which uses the "url" field. |
| 2420 | * |
| 2421 | * { |
| 2422 | * version : 3, |
| 2423 | * file: "app.js", |
| 2424 | * sections: [{ |
| 2425 | * offset: {line:100, column:10}, |
| 2426 | * map: { |
| 2427 | * version : 3, |
| 2428 | * file: "section.js", |
| 2429 | * sources: ["foo.js", "bar.js"], |
| 2430 | * names: ["src", "maps", "are", "fun"], |
| 2431 | * mappings: "AAAA,E;;ABCDE;" |
| 2432 | * } |
| 2433 | * }], |
| 2434 | * } |
| 2435 | * |
| 2436 | * The second parameter, if given, is a string whose value is the URL |
| 2437 | * at which the source map was found. This URL is used to compute the |
| 2438 | * sources array. |
| 2439 | * |
| 2440 | * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt |
| 2441 | */ |
| 2442 | function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) { |
| 2443 | var sourceMap = aSourceMap; |
| 2444 | if (typeof aSourceMap === 'string') { |
| 2445 | sourceMap = util.parseSourceMapInput(aSourceMap); |
| 2446 | } |
| 2447 | |
| 2448 | var version = util.getArg(sourceMap, 'version'); |
| 2449 | var sections = util.getArg(sourceMap, 'sections'); |
| 2450 | |
| 2451 | if (version != this._version) { |
| 2452 | throw new Error('Unsupported version: ' + version); |
| 2453 | } |
| 2454 | |
| 2455 | this._sources = new ArraySet(); |
| 2456 | this._names = new ArraySet(); |
| 2457 | |
| 2458 | var lastOffset = { |
| 2459 | line: -1, |
| 2460 | column: 0 |
| 2461 | }; |
| 2462 | this._sections = sections.map(function (s) { |
| 2463 | if (s.url) { |
| 2464 | // The url field will require support for asynchronicity. |
| 2465 | // See https://github.com/mozilla/source-map/issues/16 |
| 2466 | throw new Error('Support for url field in sections not implemented.'); |
| 2467 | } |
| 2468 | var offset = util.getArg(s, 'offset'); |
| 2469 | var offsetLine = util.getArg(offset, 'line'); |
| 2470 | var offsetColumn = util.getArg(offset, 'column'); |
| 2471 | |
| 2472 | if (offsetLine < lastOffset.line || |
| 2473 | (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) { |
| 2474 | throw new Error('Section offsets must be ordered and non-overlapping.'); |
| 2475 | } |
| 2476 | lastOffset = offset; |
| 2477 | |
| 2478 | return { |
| 2479 | generatedOffset: { |
| 2480 | // The offset fields are 0-based, but we use 1-based indices when |
| 2481 | // encoding/decoding from VLQ. |
| 2482 | generatedLine: offsetLine + 1, |
| 2483 | generatedColumn: offsetColumn + 1 |
| 2484 | }, |
| 2485 | consumer: new SourceMapConsumer(util.getArg(s, 'map'), aSourceMapURL) |
| 2486 | } |
| 2487 | }); |
| 2488 | } |
| 2489 | |
| 2490 | IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype); |
| 2491 | IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer; |
| 2492 | |
| 2493 | /** |
| 2494 | * The version of the source mapping spec that we are consuming. |
| 2495 | */ |
| 2496 | IndexedSourceMapConsumer.prototype._version = 3; |
| 2497 | |
| 2498 | /** |
| 2499 | * The list of original sources. |
| 2500 | */ |
| 2501 | Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', { |
| 2502 | get: function () { |
| 2503 | var sources = []; |
| 2504 | for (var i = 0; i < this._sections.length; i++) { |
| 2505 | for (var j = 0; j < this._sections[i].consumer.sources.length; j++) { |
| 2506 | sources.push(this._sections[i].consumer.sources[j]); |
| 2507 | } |
| 2508 | } |
| 2509 | return sources; |
| 2510 | } |
| 2511 | }); |
| 2512 | |
| 2513 | /** |
| 2514 | * Returns the original source, line, and column information for the generated |
| 2515 | * source's line and column positions provided. The only argument is an object |
| 2516 | * with the following properties: |
| 2517 | * |
| 2518 | * - line: The line number in the generated source. The line number |
| 2519 | * is 1-based. |
| 2520 | * - column: The column number in the generated source. The column |
| 2521 | * number is 0-based. |
| 2522 | * |
| 2523 | * and an object is returned with the following properties: |
| 2524 | * |
| 2525 | * - source: The original source file, or null. |
| 2526 | * - line: The line number in the original source, or null. The |
| 2527 | * line number is 1-based. |
| 2528 | * - column: The column number in the original source, or null. The |
| 2529 | * column number is 0-based. |
| 2530 | * - name: The original identifier, or null. |
| 2531 | */ |
| 2532 | IndexedSourceMapConsumer.prototype.originalPositionFor = |
| 2533 | function IndexedSourceMapConsumer_originalPositionFor(aArgs) { |
| 2534 | var needle = { |
| 2535 | generatedLine: util.getArg(aArgs, 'line'), |
| 2536 | generatedColumn: util.getArg(aArgs, 'column') |
| 2537 | }; |
| 2538 | |
| 2539 | // Find the section containing the generated position we're trying to map |
| 2540 | // to an original position. |
| 2541 | var sectionIndex = binarySearch.search(needle, this._sections, |
| 2542 | function(needle, section) { |
| 2543 | var cmp = needle.generatedLine - section.generatedOffset.generatedLine; |
| 2544 | if (cmp) { |
| 2545 | return cmp; |
| 2546 | } |
| 2547 | |
| 2548 | return (needle.generatedColumn - |
| 2549 | section.generatedOffset.generatedColumn); |
| 2550 | }); |
| 2551 | var section = this._sections[sectionIndex]; |
| 2552 | |
| 2553 | if (!section) { |
| 2554 | return { |
| 2555 | source: null, |
| 2556 | line: null, |
| 2557 | column: null, |
| 2558 | name: null |
| 2559 | }; |
| 2560 | } |
| 2561 | |
| 2562 | return section.consumer.originalPositionFor({ |
| 2563 | line: needle.generatedLine - |
| 2564 | (section.generatedOffset.generatedLine - 1), |
| 2565 | column: needle.generatedColumn - |
| 2566 | (section.generatedOffset.generatedLine === needle.generatedLine |
| 2567 | ? section.generatedOffset.generatedColumn - 1 |
| 2568 | : 0), |
| 2569 | bias: aArgs.bias |
| 2570 | }); |
| 2571 | }; |
| 2572 | |
| 2573 | /** |
| 2574 | * Return true if we have the source content for every source in the source |
| 2575 | * map, false otherwise. |
| 2576 | */ |
| 2577 | IndexedSourceMapConsumer.prototype.hasContentsOfAllSources = |
| 2578 | function IndexedSourceMapConsumer_hasContentsOfAllSources() { |
| 2579 | return this._sections.every(function (s) { |
| 2580 | return s.consumer.hasContentsOfAllSources(); |
| 2581 | }); |
| 2582 | }; |
| 2583 | |
| 2584 | /** |
| 2585 | * Returns the original source content. The only argument is the url of the |
| 2586 | * original source file. Returns null if no original source content is |
| 2587 | * available. |
| 2588 | */ |
| 2589 | IndexedSourceMapConsumer.prototype.sourceContentFor = |
| 2590 | function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) { |
| 2591 | for (var i = 0; i < this._sections.length; i++) { |
| 2592 | var section = this._sections[i]; |
| 2593 | |
| 2594 | var content = section.consumer.sourceContentFor(aSource, true); |
| 2595 | if (content) { |
| 2596 | return content; |
| 2597 | } |
| 2598 | } |
| 2599 | if (nullOnMissing) { |
| 2600 | return null; |
| 2601 | } |
| 2602 | else { |
| 2603 | throw new Error('"' + aSource + '" is not in the SourceMap.'); |
| 2604 | } |
| 2605 | }; |
| 2606 | |
| 2607 | /** |
| 2608 | * Returns the generated line and column information for the original source, |
| 2609 | * line, and column positions provided. The only argument is an object with |
| 2610 | * the following properties: |
| 2611 | * |
| 2612 | * - source: The filename of the original source. |
| 2613 | * - line: The line number in the original source. The line number |
| 2614 | * is 1-based. |
| 2615 | * - column: The column number in the original source. The column |
| 2616 | * number is 0-based. |
| 2617 | * |
| 2618 | * and an object is returned with the following properties: |
| 2619 | * |
| 2620 | * - line: The line number in the generated source, or null. The |
| 2621 | * line number is 1-based. |
| 2622 | * - column: The column number in the generated source, or null. |
| 2623 | * The column number is 0-based. |
| 2624 | */ |
| 2625 | IndexedSourceMapConsumer.prototype.generatedPositionFor = |
| 2626 | function IndexedSourceMapConsumer_generatedPositionFor(aArgs) { |
| 2627 | for (var i = 0; i < this._sections.length; i++) { |
| 2628 | var section = this._sections[i]; |
| 2629 | |
| 2630 | // Only consider this section if the requested source is in the list of |
| 2631 | // sources of the consumer. |
| 2632 | if (section.consumer._findSourceIndex(util.getArg(aArgs, 'source')) === -1) { |
| 2633 | continue; |
| 2634 | } |
| 2635 | var generatedPosition = section.consumer.generatedPositionFor(aArgs); |
| 2636 | if (generatedPosition) { |
| 2637 | var ret = { |
| 2638 | line: generatedPosition.line + |
| 2639 | (section.generatedOffset.generatedLine - 1), |
| 2640 | column: generatedPosition.column + |
| 2641 | (section.generatedOffset.generatedLine === generatedPosition.line |
| 2642 | ? section.generatedOffset.generatedColumn - 1 |
| 2643 | : 0) |
| 2644 | }; |
| 2645 | return ret; |
| 2646 | } |
| 2647 | } |
| 2648 | |
| 2649 | return { |
| 2650 | line: null, |
| 2651 | column: null |
| 2652 | }; |
| 2653 | }; |
| 2654 | |
| 2655 | /** |
| 2656 | * Parse the mappings in a string in to a data structure which we can easily |
| 2657 | * query (the ordered arrays in the `this.__generatedMappings` and |
| 2658 | * `this.__originalMappings` properties). |
| 2659 | */ |
| 2660 | IndexedSourceMapConsumer.prototype._parseMappings = |
| 2661 | function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) { |
| 2662 | this.__generatedMappings = []; |
| 2663 | this.__originalMappings = []; |
| 2664 | for (var i = 0; i < this._sections.length; i++) { |
| 2665 | var section = this._sections[i]; |
| 2666 | var sectionMappings = section.consumer._generatedMappings; |
| 2667 | for (var j = 0; j < sectionMappings.length; j++) { |
| 2668 | var mapping = sectionMappings[j]; |
| 2669 | |
| 2670 | var source = section.consumer._sources.at(mapping.source); |
| 2671 | source = util.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL); |
| 2672 | this._sources.add(source); |
| 2673 | source = this._sources.indexOf(source); |
| 2674 | |
| 2675 | var name = null; |
| 2676 | if (mapping.name) { |
| 2677 | name = section.consumer._names.at(mapping.name); |
| 2678 | this._names.add(name); |
| 2679 | name = this._names.indexOf(name); |
| 2680 | } |
| 2681 | |
| 2682 | // The mappings coming from the consumer for the section have |
| 2683 | // generated positions relative to the start of the section, so we |
| 2684 | // need to offset them to be relative to the start of the concatenated |
| 2685 | // generated file. |
| 2686 | var adjustedMapping = { |
| 2687 | source: source, |
| 2688 | generatedLine: mapping.generatedLine + |
| 2689 | (section.generatedOffset.generatedLine - 1), |
| 2690 | generatedColumn: mapping.generatedColumn + |
| 2691 | (section.generatedOffset.generatedLine === mapping.generatedLine |
| 2692 | ? section.generatedOffset.generatedColumn - 1 |
| 2693 | : 0), |
| 2694 | originalLine: mapping.originalLine, |
| 2695 | originalColumn: mapping.originalColumn, |
| 2696 | name: name |
| 2697 | }; |
| 2698 | |
| 2699 | this.__generatedMappings.push(adjustedMapping); |
| 2700 | if (typeof adjustedMapping.originalLine === 'number') { |
| 2701 | this.__originalMappings.push(adjustedMapping); |
| 2702 | } |
| 2703 | } |
| 2704 | } |
| 2705 | |
| 2706 | quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated); |
| 2707 | quickSort(this.__originalMappings, util.compareByOriginalPositions); |
| 2708 | }; |
| 2709 | |
| 2710 | exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer; |
| 2711 | |
| 2712 | |
| 2713 | /***/ }), |
| 2714 | /* 8 */ |
| 2715 | /***/ (function(module, exports) { |
| 2716 | |
| 2717 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 2718 | /* |
| 2719 | * Copyright 2011 Mozilla Foundation and contributors |
| 2720 | * Licensed under the New BSD license. See LICENSE or: |
| 2721 | * http://opensource.org/licenses/BSD-3-Clause |
| 2722 | */ |
| 2723 | |
| 2724 | exports.GREATEST_LOWER_BOUND = 1; |
| 2725 | exports.LEAST_UPPER_BOUND = 2; |
| 2726 | |
| 2727 | /** |
| 2728 | * Recursive implementation of binary search. |
| 2729 | * |
| 2730 | * @param aLow Indices here and lower do not contain the needle. |
| 2731 | * @param aHigh Indices here and higher do not contain the needle. |
| 2732 | * @param aNeedle The element being searched for. |
| 2733 | * @param aHaystack The non-empty array being searched. |
| 2734 | * @param aCompare Function which takes two elements and returns -1, 0, or 1. |
| 2735 | * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or |
| 2736 | * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the |
| 2737 | * closest element that is smaller than or greater than the one we are |
| 2738 | * searching for, respectively, if the exact element cannot be found. |
| 2739 | */ |
| 2740 | function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) { |
| 2741 | // This function terminates when one of the following is true: |
| 2742 | // |
| 2743 | // 1. We find the exact element we are looking for. |
| 2744 | // |
| 2745 | // 2. We did not find the exact element, but we can return the index of |
| 2746 | // the next-closest element. |
| 2747 | // |
| 2748 | // 3. We did not find the exact element, and there is no next-closest |
| 2749 | // element than the one we are searching for, so we return -1. |
| 2750 | var mid = Math.floor((aHigh - aLow) / 2) + aLow; |
| 2751 | var cmp = aCompare(aNeedle, aHaystack[mid], true); |
| 2752 | if (cmp === 0) { |
| 2753 | // Found the element we are looking for. |
| 2754 | return mid; |
| 2755 | } |
| 2756 | else if (cmp > 0) { |
| 2757 | // Our needle is greater than aHaystack[mid]. |
| 2758 | if (aHigh - mid > 1) { |
| 2759 | // The element is in the upper half. |
| 2760 | return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias); |
| 2761 | } |
| 2762 | |
| 2763 | // The exact needle element was not found in this haystack. Determine if |
| 2764 | // we are in termination case (3) or (2) and return the appropriate thing. |
| 2765 | if (aBias == exports.LEAST_UPPER_BOUND) { |
| 2766 | return aHigh < aHaystack.length ? aHigh : -1; |
| 2767 | } else { |
| 2768 | return mid; |
| 2769 | } |
| 2770 | } |
| 2771 | else { |
| 2772 | // Our needle is less than aHaystack[mid]. |
| 2773 | if (mid - aLow > 1) { |
| 2774 | // The element is in the lower half. |
| 2775 | return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias); |
| 2776 | } |
| 2777 | |
| 2778 | // we are in termination case (3) or (2) and return the appropriate thing. |
| 2779 | if (aBias == exports.LEAST_UPPER_BOUND) { |
| 2780 | return mid; |
| 2781 | } else { |
| 2782 | return aLow < 0 ? -1 : aLow; |
| 2783 | } |
| 2784 | } |
| 2785 | } |
| 2786 | |
| 2787 | /** |
| 2788 | * This is an implementation of binary search which will always try and return |
| 2789 | * the index of the closest element if there is no exact hit. This is because |
| 2790 | * mappings between original and generated line/col pairs are single points, |
| 2791 | * and there is an implicit region between each of them, so a miss just means |
| 2792 | * that you aren't on the very start of a region. |
| 2793 | * |
| 2794 | * @param aNeedle The element you are looking for. |
| 2795 | * @param aHaystack The array that is being searched. |
| 2796 | * @param aCompare A function which takes the needle and an element in the |
| 2797 | * array and returns -1, 0, or 1 depending on whether the needle is less |
| 2798 | * than, equal to, or greater than the element, respectively. |
| 2799 | * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or |
| 2800 | * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the |
| 2801 | * closest element that is smaller than or greater than the one we are |
| 2802 | * searching for, respectively, if the exact element cannot be found. |
| 2803 | * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'. |
| 2804 | */ |
| 2805 | exports.search = function search(aNeedle, aHaystack, aCompare, aBias) { |
| 2806 | if (aHaystack.length === 0) { |
| 2807 | return -1; |
| 2808 | } |
| 2809 | |
| 2810 | var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack, |
| 2811 | aCompare, aBias || exports.GREATEST_LOWER_BOUND); |
| 2812 | if (index < 0) { |
| 2813 | return -1; |
| 2814 | } |
| 2815 | |
| 2816 | // We have found either the exact element, or the next-closest element than |
| 2817 | // the one we are searching for. However, there may be more than one such |
| 2818 | // element. Make sure we always return the smallest of these. |
| 2819 | while (index - 1 >= 0) { |
| 2820 | if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) { |
| 2821 | break; |
| 2822 | } |
| 2823 | --index; |
| 2824 | } |
| 2825 | |
| 2826 | return index; |
| 2827 | }; |
| 2828 | |
| 2829 | |
| 2830 | /***/ }), |
| 2831 | /* 9 */ |
| 2832 | /***/ (function(module, exports) { |
| 2833 | |
| 2834 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 2835 | /* |
| 2836 | * Copyright 2011 Mozilla Foundation and contributors |
| 2837 | * Licensed under the New BSD license. See LICENSE or: |
| 2838 | * http://opensource.org/licenses/BSD-3-Clause |
| 2839 | */ |
| 2840 | |
| 2841 | // It turns out that some (most?) JavaScript engines don't self-host |
| 2842 | // `Array.prototype.sort`. This makes sense because C++ will likely remain |
| 2843 | // faster than JS when doing raw CPU-intensive sorting. However, when using a |
| 2844 | // custom comparator function, calling back and forth between the VM's C++ and |
| 2845 | // JIT'd JS is rather slow *and* loses JIT type information, resulting in |
| 2846 | // worse generated code for the comparator function than would be optimal. In |
| 2847 | // fact, when sorting with a comparator, these costs outweigh the benefits of |
| 2848 | // sorting in C++. By using our own JS-implemented Quick Sort (below), we get |
| 2849 | // a ~3500ms mean speed-up in `bench/bench.html`. |
| 2850 | |
| 2851 | function SortTemplate(comparator) { |
| 2852 | |
| 2853 | /** |
| 2854 | * Swap the elements indexed by `x` and `y` in the array `ary`. |
| 2855 | * |
| 2856 | * @param {Array} ary |
| 2857 | * The array. |
| 2858 | * @param {Number} x |
| 2859 | * The index of the first item. |
| 2860 | * @param {Number} y |
| 2861 | * The index of the second item. |
| 2862 | */ |
| 2863 | function swap(ary, x, y) { |
| 2864 | var temp = ary[x]; |
| 2865 | ary[x] = ary[y]; |
| 2866 | ary[y] = temp; |
| 2867 | } |
| 2868 | |
| 2869 | /** |
| 2870 | * Returns a random integer within the range `low .. high` inclusive. |
| 2871 | * |
| 2872 | * @param {Number} low |
| 2873 | * The lower bound on the range. |
| 2874 | * @param {Number} high |
| 2875 | * The upper bound on the range. |
| 2876 | */ |
| 2877 | function randomIntInRange(low, high) { |
| 2878 | return Math.round(low + (Math.random() * (high - low))); |
| 2879 | } |
| 2880 | |
| 2881 | /** |
| 2882 | * The Quick Sort algorithm. |
| 2883 | * |
| 2884 | * @param {Array} ary |
| 2885 | * An array to sort. |
| 2886 | * @param {function} comparator |
| 2887 | * Function to use to compare two items. |
| 2888 | * @param {Number} p |
| 2889 | * Start index of the array |
| 2890 | * @param {Number} r |
| 2891 | * End index of the array |
| 2892 | */ |
| 2893 | function doQuickSort(ary, comparator, p, r) { |
| 2894 | // If our lower bound is less than our upper bound, we (1) partition the |
| 2895 | // array into two pieces and (2) recurse on each half. If it is not, this is |
| 2896 | // the empty array and our base case. |
| 2897 | |
| 2898 | if (p < r) { |
| 2899 | // (1) Partitioning. |
| 2900 | // |
| 2901 | // The partitioning chooses a pivot between `p` and `r` and moves all |
| 2902 | // elements that are less than or equal to the pivot to the before it, and |
| 2903 | // all the elements that are greater than it after it. The effect is that |
| 2904 | // once partition is done, the pivot is in the exact place it will be when |
| 2905 | // the array is put in sorted order, and it will not need to be moved |
| 2906 | // again. This runs in O(n) time. |
| 2907 | |
| 2908 | // Always choose a random pivot so that an input array which is reverse |
| 2909 | // sorted does not cause O(n^2) running time. |
| 2910 | var pivotIndex = randomIntInRange(p, r); |
| 2911 | var i = p - 1; |
| 2912 | |
| 2913 | swap(ary, pivotIndex, r); |
| 2914 | var pivot = ary[r]; |
| 2915 | |
| 2916 | // Immediately after `j` is incremented in this loop, the following hold |
| 2917 | // true: |
| 2918 | // |
| 2919 | // * Every element in `ary[p .. i]` is less than or equal to the pivot. |
| 2920 | // |
| 2921 | // * Every element in `ary[i+1 .. j-1]` is greater than the pivot. |
| 2922 | for (var j = p; j < r; j++) { |
| 2923 | if (comparator(ary[j], pivot, false) <= 0) { |
| 2924 | i += 1; |
| 2925 | swap(ary, i, j); |
| 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | swap(ary, i + 1, j); |
| 2930 | var q = i + 1; |
| 2931 | |
| 2932 | // (2) Recurse on each half. |
| 2933 | |
| 2934 | doQuickSort(ary, comparator, p, q - 1); |
| 2935 | doQuickSort(ary, comparator, q + 1, r); |
| 2936 | } |
| 2937 | } |
| 2938 | |
| 2939 | return doQuickSort; |
| 2940 | } |
| 2941 | |
| 2942 | function cloneSort(comparator) { |
| 2943 | let template = SortTemplate.toString(); |
| 2944 | let templateFn = new Function(`return ${template}`)(); |
| 2945 | return templateFn(comparator); |
| 2946 | } |
| 2947 | |
| 2948 | /** |
| 2949 | * Sort the given array in-place with the given comparator function. |
| 2950 | * |
| 2951 | * @param {Array} ary |
| 2952 | * An array to sort. |
| 2953 | * @param {function} comparator |
| 2954 | * Function to use to compare two items. |
| 2955 | */ |
| 2956 | |
| 2957 | let sortCache = new WeakMap(); |
| 2958 | exports.quickSort = function (ary, comparator, start = 0) { |
| 2959 | let doQuickSort = sortCache.get(comparator); |
| 2960 | if (doQuickSort === void 0) { |
| 2961 | doQuickSort = cloneSort(comparator); |
| 2962 | sortCache.set(comparator, doQuickSort); |
| 2963 | } |
| 2964 | doQuickSort(ary, comparator, start, ary.length - 1); |
| 2965 | }; |
| 2966 | |
| 2967 | |
| 2968 | /***/ }), |
| 2969 | /* 10 */ |
| 2970 | /***/ (function(module, exports, __webpack_require__) { |
| 2971 | |
| 2972 | /* -*- Mode: js; js-indent-level: 2; -*- */ |
| 2973 | /* |
| 2974 | * Copyright 2011 Mozilla Foundation and contributors |
| 2975 | * Licensed under the New BSD license. See LICENSE or: |
| 2976 | * http://opensource.org/licenses/BSD-3-Clause |
| 2977 | */ |
| 2978 | |
| 2979 | var SourceMapGenerator = __webpack_require__(1).SourceMapGenerator; |
| 2980 | var util = __webpack_require__(4); |
| 2981 | |
| 2982 | // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other |
| 2983 | // operating systems these days (capturing the result). |
| 2984 | var REGEX_NEWLINE = /(\r?\n)/; |
| 2985 | |
| 2986 | // Newline character code for charCodeAt() comparisons |
| 2987 | var NEWLINE_CODE = 10; |
| 2988 | |
| 2989 | // Private symbol for identifying `SourceNode`s when multiple versions of |
| 2990 | // the source-map library are loaded. This MUST NOT CHANGE across |
| 2991 | // versions! |
| 2992 | var isSourceNode = "$$$isSourceNode$$$"; |
| 2993 | |
| 2994 | /** |
| 2995 | * SourceNodes provide a way to abstract over interpolating/concatenating |
| 2996 | * snippets of generated JavaScript source code while maintaining the line and |
| 2997 | * column information associated with the original source code. |
| 2998 | * |
| 2999 | * @param aLine The original line number. |
| 3000 | * @param aColumn The original column number. |
| 3001 | * @param aSource The original source's filename. |
| 3002 | * @param aChunks Optional. An array of strings which are snippets of |
| 3003 | * generated JS, or other SourceNodes. |
| 3004 | * @param aName The original identifier. |
| 3005 | */ |
| 3006 | function SourceNode(aLine, aColumn, aSource, aChunks, aName) { |
| 3007 | this.children = []; |
| 3008 | this.sourceContents = {}; |
| 3009 | this.line = aLine == null ? null : aLine; |
| 3010 | this.column = aColumn == null ? null : aColumn; |
| 3011 | this.source = aSource == null ? null : aSource; |
| 3012 | this.name = aName == null ? null : aName; |
| 3013 | this[isSourceNode] = true; |
| 3014 | if (aChunks != null) this.add(aChunks); |
| 3015 | } |
| 3016 | |
| 3017 | /** |
| 3018 | * Creates a SourceNode from generated code and a SourceMapConsumer. |
| 3019 | * |
| 3020 | * @param aGeneratedCode The generated code |
| 3021 | * @param aSourceMapConsumer The SourceMap for the generated code |
| 3022 | * @param aRelativePath Optional. The path that relative sources in the |
| 3023 | * SourceMapConsumer should be relative to. |
| 3024 | */ |
| 3025 | SourceNode.fromStringWithSourceMap = |
| 3026 | function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) { |
| 3027 | // The SourceNode we want to fill with the generated code |
| 3028 | // and the SourceMap |
| 3029 | var node = new SourceNode(); |
| 3030 | |
| 3031 | // All even indices of this array are one line of the generated code, |
| 3032 | // while all odd indices are the newlines between two adjacent lines |
| 3033 | // (since `REGEX_NEWLINE` captures its match). |
| 3034 | // Processed fragments are accessed by calling `shiftNextLine`. |
| 3035 | var remainingLines = aGeneratedCode.split(REGEX_NEWLINE); |
| 3036 | var remainingLinesIndex = 0; |
| 3037 | var shiftNextLine = function() { |
| 3038 | var lineContents = getNextLine(); |
| 3039 | // The last line of a file might not have a newline. |
| 3040 | var newLine = getNextLine() || ""; |
| 3041 | return lineContents + newLine; |
| 3042 | |
| 3043 | function getNextLine() { |
| 3044 | return remainingLinesIndex < remainingLines.length ? |
| 3045 | remainingLines[remainingLinesIndex++] : undefined; |
| 3046 | } |
| 3047 | }; |
| 3048 | |
| 3049 | // We need to remember the position of "remainingLines" |
| 3050 | var lastGeneratedLine = 1, lastGeneratedColumn = 0; |
| 3051 | |
| 3052 | // The generate SourceNodes we need a code range. |
| 3053 | // To extract it current and last mapping is used. |
| 3054 | // Here we store the last mapping. |
| 3055 | var lastMapping = null; |
| 3056 | |
| 3057 | aSourceMapConsumer.eachMapping(function (mapping) { |
| 3058 | if (lastMapping !== null) { |
| 3059 | // We add the code from "lastMapping" to "mapping": |
| 3060 | // First check if there is a new line in between. |
| 3061 | if (lastGeneratedLine < mapping.generatedLine) { |
| 3062 | // Associate first line with "lastMapping" |
| 3063 | addMappingWithCode(lastMapping, shiftNextLine()); |
| 3064 | lastGeneratedLine++; |
| 3065 | lastGeneratedColumn = 0; |
| 3066 | // The remaining code is added without mapping |
| 3067 | } else { |
| 3068 | // There is no new line in between. |
| 3069 | // Associate the code between "lastGeneratedColumn" and |
| 3070 | // "mapping.generatedColumn" with "lastMapping" |
| 3071 | var nextLine = remainingLines[remainingLinesIndex] || ''; |
| 3072 | var code = nextLine.substr(0, mapping.generatedColumn - |
| 3073 | lastGeneratedColumn); |
| 3074 | remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn - |
| 3075 | lastGeneratedColumn); |
| 3076 | lastGeneratedColumn = mapping.generatedColumn; |
| 3077 | addMappingWithCode(lastMapping, code); |
| 3078 | // No more remaining code, continue |
| 3079 | lastMapping = mapping; |
| 3080 | return; |
| 3081 | } |
| 3082 | } |
| 3083 | // We add the generated code until the first mapping |
| 3084 | // to the SourceNode without any mapping. |
| 3085 | // Each line is added as separate string. |
| 3086 | while (lastGeneratedLine < mapping.generatedLine) { |
| 3087 | node.add(shiftNextLine()); |
| 3088 | lastGeneratedLine++; |
| 3089 | } |
| 3090 | if (lastGeneratedColumn < mapping.generatedColumn) { |
| 3091 | var nextLine = remainingLines[remainingLinesIndex] || ''; |
| 3092 | node.add(nextLine.substr(0, mapping.generatedColumn)); |
| 3093 | remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn); |
| 3094 | lastGeneratedColumn = mapping.generatedColumn; |
| 3095 | } |
| 3096 | lastMapping = mapping; |
| 3097 | }, this); |
| 3098 | // We have processed all mappings. |
| 3099 | if (remainingLinesIndex < remainingLines.length) { |
| 3100 | if (lastMapping) { |
| 3101 | // Associate the remaining code in the current line with "lastMapping" |
| 3102 | addMappingWithCode(lastMapping, shiftNextLine()); |
| 3103 | } |
| 3104 | // and add the remaining lines without any mapping |
| 3105 | node.add(remainingLines.splice(remainingLinesIndex).join("")); |
| 3106 | } |
| 3107 | |
| 3108 | // Copy sourcesContent into SourceNode |
| 3109 | aSourceMapConsumer.sources.forEach(function (sourceFile) { |
| 3110 | var content = aSourceMapConsumer.sourceContentFor(sourceFile); |
| 3111 | if (content != null) { |
| 3112 | if (aRelativePath != null) { |
| 3113 | sourceFile = util.join(aRelativePath, sourceFile); |
| 3114 | } |
| 3115 | node.setSourceContent(sourceFile, content); |
| 3116 | } |
| 3117 | }); |
| 3118 | |
| 3119 | return node; |
| 3120 | |
| 3121 | function addMappingWithCode(mapping, code) { |
| 3122 | if (mapping === null || mapping.source === undefined) { |
| 3123 | node.add(code); |
| 3124 | } else { |
| 3125 | var source = aRelativePath |
| 3126 | ? util.join(aRelativePath, mapping.source) |
| 3127 | : mapping.source; |
| 3128 | node.add(new SourceNode(mapping.originalLine, |
| 3129 | mapping.originalColumn, |
| 3130 | source, |
| 3131 | code, |
| 3132 | mapping.name)); |
| 3133 | } |
| 3134 | } |
| 3135 | }; |
| 3136 | |
| 3137 | /** |
| 3138 | * Add a chunk of generated JS to this source node. |
| 3139 | * |
| 3140 | * @param aChunk A string snippet of generated JS code, another instance of |
| 3141 | * SourceNode, or an array where each member is one of those things. |
| 3142 | */ |
| 3143 | SourceNode.prototype.add = function SourceNode_add(aChunk) { |
| 3144 | if (Array.isArray(aChunk)) { |
| 3145 | aChunk.forEach(function (chunk) { |
| 3146 | this.add(chunk); |
| 3147 | }, this); |
| 3148 | } |
| 3149 | else if (aChunk[isSourceNode] || typeof aChunk === "string") { |
| 3150 | if (aChunk) { |
| 3151 | this.children.push(aChunk); |
| 3152 | } |
| 3153 | } |
| 3154 | else { |
| 3155 | throw new TypeError( |
| 3156 | "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk |
| 3157 | ); |
| 3158 | } |
| 3159 | return this; |
| 3160 | }; |
| 3161 | |
| 3162 | /** |
| 3163 | * Add a chunk of generated JS to the beginning of this source node. |
| 3164 | * |
| 3165 | * @param aChunk A string snippet of generated JS code, another instance of |
| 3166 | * SourceNode, or an array where each member is one of those things. |
| 3167 | */ |
| 3168 | SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) { |
| 3169 | if (Array.isArray(aChunk)) { |
| 3170 | for (var i = aChunk.length-1; i >= 0; i--) { |
| 3171 | this.prepend(aChunk[i]); |
| 3172 | } |
| 3173 | } |
| 3174 | else if (aChunk[isSourceNode] || typeof aChunk === "string") { |
| 3175 | this.children.unshift(aChunk); |
| 3176 | } |
| 3177 | else { |
| 3178 | throw new TypeError( |
| 3179 | "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk |
| 3180 | ); |
| 3181 | } |
| 3182 | return this; |
| 3183 | }; |
| 3184 | |
| 3185 | /** |
| 3186 | * Walk over the tree of JS snippets in this node and its children. The |
| 3187 | * walking function is called once for each snippet of JS and is passed that |
| 3188 | * snippet and the its original associated source's line/column location. |
| 3189 | * |
| 3190 | * @param aFn The traversal function. |
| 3191 | */ |
| 3192 | SourceNode.prototype.walk = function SourceNode_walk(aFn) { |
| 3193 | var chunk; |
| 3194 | for (var i = 0, len = this.children.length; i < len; i++) { |
| 3195 | chunk = this.children[i]; |
| 3196 | if (chunk[isSourceNode]) { |
| 3197 | chunk.walk(aFn); |
| 3198 | } |
| 3199 | else { |
| 3200 | if (chunk !== '') { |
| 3201 | aFn(chunk, { source: this.source, |
| 3202 | line: this.line, |
| 3203 | column: this.column, |
| 3204 | name: this.name }); |
| 3205 | } |
| 3206 | } |
| 3207 | } |
| 3208 | }; |
| 3209 | |
| 3210 | /** |
| 3211 | * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between |
| 3212 | * each of `this.children`. |
| 3213 | * |
| 3214 | * @param aSep The separator. |
| 3215 | */ |
| 3216 | SourceNode.prototype.join = function SourceNode_join(aSep) { |
| 3217 | var newChildren; |
| 3218 | var i; |
| 3219 | var len = this.children.length; |
| 3220 | if (len > 0) { |
| 3221 | newChildren = []; |
| 3222 | for (i = 0; i < len-1; i++) { |
| 3223 | newChildren.push(this.children[i]); |
| 3224 | newChildren.push(aSep); |
| 3225 | } |
| 3226 | newChildren.push(this.children[i]); |
| 3227 | this.children = newChildren; |
| 3228 | } |
| 3229 | return this; |
| 3230 | }; |
| 3231 | |
| 3232 | /** |
| 3233 | * Call String.prototype.replace on the very right-most source snippet. Useful |
| 3234 | * for trimming whitespace from the end of a source node, etc. |
| 3235 | * |
| 3236 | * @param aPattern The pattern to replace. |
| 3237 | * @param aReplacement The thing to replace the pattern with. |
| 3238 | */ |
| 3239 | SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) { |
| 3240 | var lastChild = this.children[this.children.length - 1]; |
| 3241 | if (lastChild[isSourceNode]) { |
| 3242 | lastChild.replaceRight(aPattern, aReplacement); |
| 3243 | } |
| 3244 | else if (typeof lastChild === 'string') { |
| 3245 | this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement); |
| 3246 | } |
| 3247 | else { |
| 3248 | this.children.push(''.replace(aPattern, aReplacement)); |
| 3249 | } |
| 3250 | return this; |
| 3251 | }; |
| 3252 | |
| 3253 | /** |
| 3254 | * Set the source content for a source file. This will be added to the SourceMapGenerator |
| 3255 | * in the sourcesContent field. |
| 3256 | * |
| 3257 | * @param aSourceFile The filename of the source file |
| 3258 | * @param aSourceContent The content of the source file |
| 3259 | */ |
| 3260 | SourceNode.prototype.setSourceContent = |
| 3261 | function SourceNode_setSourceContent(aSourceFile, aSourceContent) { |
| 3262 | this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent; |
| 3263 | }; |
| 3264 | |
| 3265 | /** |
| 3266 | * Walk over the tree of SourceNodes. The walking function is called for each |
| 3267 | * source file content and is passed the filename and source content. |
| 3268 | * |
| 3269 | * @param aFn The traversal function. |
| 3270 | */ |
| 3271 | SourceNode.prototype.walkSourceContents = |
| 3272 | function SourceNode_walkSourceContents(aFn) { |
| 3273 | for (var i = 0, len = this.children.length; i < len; i++) { |
| 3274 | if (this.children[i][isSourceNode]) { |
| 3275 | this.children[i].walkSourceContents(aFn); |
| 3276 | } |
| 3277 | } |
| 3278 | |
| 3279 | var sources = Object.keys(this.sourceContents); |
| 3280 | for (var i = 0, len = sources.length; i < len; i++) { |
| 3281 | aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]); |
| 3282 | } |
| 3283 | }; |
| 3284 | |
| 3285 | /** |
| 3286 | * Return the string representation of this source node. Walks over the tree |
| 3287 | * and concatenates all the various snippets together to one string. |
| 3288 | */ |
| 3289 | SourceNode.prototype.toString = function SourceNode_toString() { |
| 3290 | var str = ""; |
| 3291 | this.walk(function (chunk) { |
| 3292 | str += chunk; |
| 3293 | }); |
| 3294 | return str; |
| 3295 | }; |
| 3296 | |
| 3297 | /** |
| 3298 | * Returns the string representation of this source node along with a source |
| 3299 | * map. |
| 3300 | */ |
| 3301 | SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) { |
| 3302 | var generated = { |
| 3303 | code: "", |
| 3304 | line: 1, |
| 3305 | column: 0 |
| 3306 | }; |
| 3307 | var map = new SourceMapGenerator(aArgs); |
| 3308 | var sourceMappingActive = false; |
| 3309 | var lastOriginalSource = null; |
| 3310 | var lastOriginalLine = null; |
| 3311 | var lastOriginalColumn = null; |
| 3312 | var lastOriginalName = null; |
| 3313 | this.walk(function (chunk, original) { |
| 3314 | generated.code += chunk; |
| 3315 | if (original.source !== null |
| 3316 | && original.line !== null |
| 3317 | && original.column !== null) { |
| 3318 | if(lastOriginalSource !== original.source |
| 3319 | || lastOriginalLine !== original.line |
| 3320 | || lastOriginalColumn !== original.column |
| 3321 | || lastOriginalName !== original.name) { |
| 3322 | map.addMapping({ |
| 3323 | source: original.source, |
| 3324 | original: { |
| 3325 | line: original.line, |
| 3326 | column: original.column |
| 3327 | }, |
| 3328 | generated: { |
| 3329 | line: generated.line, |
| 3330 | column: generated.column |
| 3331 | }, |
| 3332 | name: original.name |
| 3333 | }); |
| 3334 | } |
| 3335 | lastOriginalSource = original.source; |
| 3336 | lastOriginalLine = original.line; |
| 3337 | lastOriginalColumn = original.column; |
| 3338 | lastOriginalName = original.name; |
| 3339 | sourceMappingActive = true; |
| 3340 | } else if (sourceMappingActive) { |
| 3341 | map.addMapping({ |
| 3342 | generated: { |
| 3343 | line: generated.line, |
| 3344 | column: generated.column |
| 3345 | } |
| 3346 | }); |
| 3347 | lastOriginalSource = null; |
| 3348 | sourceMappingActive = false; |
| 3349 | } |
| 3350 | for (var idx = 0, length = chunk.length; idx < length; idx++) { |
| 3351 | if (chunk.charCodeAt(idx) === NEWLINE_CODE) { |
| 3352 | generated.line++; |
| 3353 | generated.column = 0; |
| 3354 | // Mappings end at eol |
| 3355 | if (idx + 1 === length) { |
| 3356 | lastOriginalSource = null; |
| 3357 | sourceMappingActive = false; |
| 3358 | } else if (sourceMappingActive) { |
| 3359 | map.addMapping({ |
| 3360 | source: original.source, |
| 3361 | original: { |
| 3362 | line: original.line, |
| 3363 | column: original.column |
| 3364 | }, |
| 3365 | generated: { |
| 3366 | line: generated.line, |
| 3367 | column: generated.column |
| 3368 | }, |
| 3369 | name: original.name |
| 3370 | }); |
| 3371 | } |
| 3372 | } else { |
| 3373 | generated.column++; |
| 3374 | } |
| 3375 | } |
| 3376 | }); |
| 3377 | this.walkSourceContents(function (sourceFile, sourceContent) { |
| 3378 | map.setSourceContent(sourceFile, sourceContent); |
| 3379 | }); |
| 3380 | |
| 3381 | return { code: generated.code, map: map }; |
| 3382 | }; |
| 3383 | |
| 3384 | exports.SourceNode = SourceNode; |
| 3385 | |
| 3386 | |
| 3387 | /***/ }) |
| 3388 | /******/ ]) |
| 3389 | }); |
| 3390 | ; |