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)
6 else if(typeof exports === 'object')
7 exports["sourceMap"] = factory();
9 root["sourceMap"] = factory();
11 return /******/ (function(modules) { // webpackBootstrap
12 /******/ // The module cache
13 /******/ var installedModules = {};
15 /******/ // The require function
16 /******/ function __webpack_require__(moduleId) {
18 /******/ // Check if module is in cache
19 /******/ if(installedModules[moduleId])
20 /******/ return installedModules[moduleId].exports;
22 /******/ // Create a new module (and put it into the cache)
23 /******/ var module = installedModules[moduleId] = {
25 /******/ id: moduleId,
26 /******/ loaded: false
29 /******/ // Execute the module function
30 /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
32 /******/ // Flag the module as loaded
33 /******/ module.loaded = true;
35 /******/ // Return the exports of the module
36 /******/ return module.exports;
40 /******/ // expose the modules object (__webpack_modules__)
41 /******/ __webpack_require__.m = modules;
43 /******/ // expose the module cache
44 /******/ __webpack_require__.c = installedModules;
46 /******/ // __webpack_public_path__
47 /******/ __webpack_require__.p = "";
49 /******/ // Load entry module and return exports
50 /******/ return __webpack_require__(0);
52 /************************************************************************/
55 /***/ function(module, exports, __webpack_require__) {
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
62 exports.SourceMapGenerator = __webpack_require__(1).SourceMapGenerator;
63 exports.SourceMapConsumer = __webpack_require__(7).SourceMapConsumer;
64 exports.SourceNode = __webpack_require__(10).SourceNode;
69 /***/ function(module, exports, __webpack_require__) {
71 /* -*- Mode: js; js-indent-level: 2; -*- */
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
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;
84 * An instance of the SourceMapGenerator represents a source map which is
85 * being built incrementally. You may pass an object with the following
88 * - file: The filename of the generated source.
89 * - sourceRoot: A root for all relative URLs in this source map.
91 function SourceMapGenerator(aArgs) {
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;
104 SourceMapGenerator.prototype._version = 3;
107 * Creates a new SourceMapGenerator based on a SourceMapConsumer
109 * @param aSourceMapConsumer The SourceMap.
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
118 aSourceMapConsumer.eachMapping(function (mapping) {
121 line: mapping.generatedLine,
122 column: mapping.generatedColumn
126 if (mapping.source != null) {
127 newMapping.source = mapping.source;
128 if (sourceRoot != null) {
129 newMapping.source = util.relative(sourceRoot, newMapping.source);
132 newMapping.original = {
133 line: mapping.originalLine,
134 column: mapping.originalColumn
137 if (mapping.name != null) {
138 newMapping.name = mapping.name;
142 generator.addMapping(newMapping);
144 aSourceMapConsumer.sources.forEach(function (sourceFile) {
145 var content = aSourceMapConsumer.sourceContentFor(sourceFile);
146 if (content != null) {
147 generator.setSourceContent(sourceFile, content);
154 * Add a single mapping from original source line and column to the generated
155 * source's line and column for this source map being created. The mapping
156 * object should have the following properties:
158 * - generated: An object with the generated line and column positions.
159 * - original: An object with the original line and column positions.
160 * - source: The original source file (relative to the sourceRoot).
161 * - name: An optional original token name for this mapping.
163 SourceMapGenerator.prototype.addMapping =
164 function SourceMapGenerator_addMapping(aArgs) {
165 var generated = util.getArg(aArgs, 'generated');
166 var original = util.getArg(aArgs, 'original', null);
167 var source = util.getArg(aArgs, 'source', null);
168 var name = util.getArg(aArgs, 'name', null);
170 if (!this._skipValidation) {
171 this._validateMapping(generated, original, source, name);
174 if (source != null) {
175 source = String(source);
176 if (!this._sources.has(source)) {
177 this._sources.add(source);
183 if (!this._names.has(name)) {
184 this._names.add(name);
189 generatedLine: generated.line,
190 generatedColumn: generated.column,
191 originalLine: original != null && original.line,
192 originalColumn: original != null && original.column,
199 * Set the source content for a source file.
201 SourceMapGenerator.prototype.setSourceContent =
202 function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
203 var source = aSourceFile;
204 if (this._sourceRoot != null) {
205 source = util.relative(this._sourceRoot, source);
208 if (aSourceContent != null) {
209 // Add the source content to the _sourcesContents map.
210 // Create a new _sourcesContents map if the property is null.
211 if (!this._sourcesContents) {
212 this._sourcesContents = Object.create(null);
214 this._sourcesContents[util.toSetString(source)] = aSourceContent;
215 } else if (this._sourcesContents) {
216 // Remove the source file from the _sourcesContents map.
217 // If the _sourcesContents map is empty, set the property to null.
218 delete this._sourcesContents[util.toSetString(source)];
219 if (Object.keys(this._sourcesContents).length === 0) {
220 this._sourcesContents = null;
226 * Applies the mappings of a sub-source-map for a specific source file to the
227 * source map being generated. Each mapping to the supplied source file is
228 * rewritten using the supplied source map. Note: The resolution for the
229 * resulting mappings is the minimium of this map and the supplied map.
231 * @param aSourceMapConsumer The source map to be applied.
232 * @param aSourceFile Optional. The filename of the source file.
233 * If omitted, SourceMapConsumer's file property will be used.
234 * @param aSourceMapPath Optional. The dirname of the path to the source map
235 * to be applied. If relative, it is relative to the SourceMapConsumer.
236 * This parameter is needed when the two source maps aren't in the same
237 * directory, and the source map to be applied contains relative source
238 * paths. If so, those relative source paths need to be rewritten
239 * relative to the SourceMapGenerator.
241 SourceMapGenerator.prototype.applySourceMap =
242 function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
243 var sourceFile = aSourceFile;
244 // If aSourceFile is omitted, we will use the file property of the SourceMap
245 if (aSourceFile == null) {
246 if (aSourceMapConsumer.file == null) {
248 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
249 'or the source map\'s "file" property. Both were omitted.'
252 sourceFile = aSourceMapConsumer.file;
254 var sourceRoot = this._sourceRoot;
255 // Make "sourceFile" relative if an absolute Url is passed.
256 if (sourceRoot != null) {
257 sourceFile = util.relative(sourceRoot, sourceFile);
259 // Applying the SourceMap can add and remove items from the sources and
261 var newSources = new ArraySet();
262 var newNames = new ArraySet();
264 // Find mappings for the "sourceFile"
265 this._mappings.unsortedForEach(function (mapping) {
266 if (mapping.source === sourceFile && mapping.originalLine != null) {
267 // Check if it can be mapped by the source map, then update the mapping.
268 var original = aSourceMapConsumer.originalPositionFor({
269 line: mapping.originalLine,
270 column: mapping.originalColumn
272 if (original.source != null) {
274 mapping.source = original.source;
275 if (aSourceMapPath != null) {
276 mapping.source = util.join(aSourceMapPath, mapping.source)
278 if (sourceRoot != null) {
279 mapping.source = util.relative(sourceRoot, mapping.source);
281 mapping.originalLine = original.line;
282 mapping.originalColumn = original.column;
283 if (original.name != null) {
284 mapping.name = original.name;
289 var source = mapping.source;
290 if (source != null && !newSources.has(source)) {
291 newSources.add(source);
294 var name = mapping.name;
295 if (name != null && !newNames.has(name)) {
300 this._sources = newSources;
301 this._names = newNames;
303 // Copy sourcesContents of applied map.
304 aSourceMapConsumer.sources.forEach(function (sourceFile) {
305 var content = aSourceMapConsumer.sourceContentFor(sourceFile);
306 if (content != null) {
307 if (aSourceMapPath != null) {
308 sourceFile = util.join(aSourceMapPath, sourceFile);
310 if (sourceRoot != null) {
311 sourceFile = util.relative(sourceRoot, sourceFile);
313 this.setSourceContent(sourceFile, content);
319 * A mapping can have one of the three levels of data:
321 * 1. Just the generated position.
322 * 2. The Generated position, original position, and original source.
323 * 3. Generated and original position, original source, as well as a name
326 * To maintain consistency, we validate that any new mapping being added falls
327 * in to one of these categories.
329 SourceMapGenerator.prototype._validateMapping =
330 function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
332 if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
333 && aGenerated.line > 0 && aGenerated.column >= 0
334 && !aOriginal && !aSource && !aName) {
338 else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
339 && aOriginal && 'line' in aOriginal && 'column' in aOriginal
340 && aGenerated.line > 0 && aGenerated.column >= 0
341 && aOriginal.line > 0 && aOriginal.column >= 0
347 throw new Error('Invalid mapping: ' + JSON.stringify({
348 generated: aGenerated,
357 * Serialize the accumulated mappings in to the stream of base 64 VLQs
358 * specified by the source map format.
360 SourceMapGenerator.prototype._serializeMappings =
361 function SourceMapGenerator_serializeMappings() {
362 var previousGeneratedColumn = 0;
363 var previousGeneratedLine = 1;
364 var previousOriginalColumn = 0;
365 var previousOriginalLine = 0;
366 var previousName = 0;
367 var previousSource = 0;
374 var mappings = this._mappings.toArray();
375 for (var i = 0, len = mappings.length; i < len; i++) {
376 mapping = mappings[i];
379 if (mapping.generatedLine !== previousGeneratedLine) {
380 previousGeneratedColumn = 0;
381 while (mapping.generatedLine !== previousGeneratedLine) {
383 previousGeneratedLine++;
388 if (!util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
395 next += base64VLQ.encode(mapping.generatedColumn
396 - previousGeneratedColumn);
397 previousGeneratedColumn = mapping.generatedColumn;
399 if (mapping.source != null) {
400 sourceIdx = this._sources.indexOf(mapping.source);
401 next += base64VLQ.encode(sourceIdx - previousSource);
402 previousSource = sourceIdx;
404 // lines are stored 0-based in SourceMap spec version 3
405 next += base64VLQ.encode(mapping.originalLine - 1
406 - previousOriginalLine);
407 previousOriginalLine = mapping.originalLine - 1;
409 next += base64VLQ.encode(mapping.originalColumn
410 - previousOriginalColumn);
411 previousOriginalColumn = mapping.originalColumn;
413 if (mapping.name != null) {
414 nameIdx = this._names.indexOf(mapping.name);
415 next += base64VLQ.encode(nameIdx - previousName);
416 previousName = nameIdx;
426 SourceMapGenerator.prototype._generateSourcesContent =
427 function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
428 return aSources.map(function (source) {
429 if (!this._sourcesContents) {
432 if (aSourceRoot != null) {
433 source = util.relative(aSourceRoot, source);
435 var key = util.toSetString(source);
436 return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
437 ? this._sourcesContents[key]
443 * Externalize the source map.
445 SourceMapGenerator.prototype.toJSON =
446 function SourceMapGenerator_toJSON() {
448 version: this._version,
449 sources: this._sources.toArray(),
450 names: this._names.toArray(),
451 mappings: this._serializeMappings()
453 if (this._file != null) {
454 map.file = this._file;
456 if (this._sourceRoot != null) {
457 map.sourceRoot = this._sourceRoot;
459 if (this._sourcesContents) {
460 map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
467 * Render the source map being generated to a string.
469 SourceMapGenerator.prototype.toString =
470 function SourceMapGenerator_toString() {
471 return JSON.stringify(this.toJSON());
474 exports.SourceMapGenerator = SourceMapGenerator;
479 /***/ function(module, exports, __webpack_require__) {
481 /* -*- Mode: js; js-indent-level: 2; -*- */
483 * Copyright 2011 Mozilla Foundation and contributors
484 * Licensed under the New BSD license. See LICENSE or:
485 * http://opensource.org/licenses/BSD-3-Clause
487 * Based on the Base 64 VLQ implementation in Closure Compiler:
488 * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
490 * Copyright 2011 The Closure Compiler Authors. All rights reserved.
491 * Redistribution and use in source and binary forms, with or without
492 * modification, are permitted provided that the following conditions are
495 * * Redistributions of source code must retain the above copyright
496 * notice, this list of conditions and the following disclaimer.
497 * * Redistributions in binary form must reproduce the above
498 * copyright notice, this list of conditions and the following
499 * disclaimer in the documentation and/or other materials provided
500 * with the distribution.
501 * * Neither the name of Google Inc. nor the names of its
502 * contributors may be used to endorse or promote products derived
503 * from this software without specific prior written permission.
505 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
506 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
507 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
508 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
509 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
510 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
511 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
512 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
513 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
514 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
515 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
518 var base64 = __webpack_require__(3);
520 // A single base 64 digit can contain 6 bits of data. For the base 64 variable
521 // length quantities we use in the source map spec, the first bit is the sign,
522 // the next four bits are the actual value, and the 6th bit is the
523 // continuation bit. The continuation bit tells us whether there are more
524 // digits in this value following this digit.
532 var VLQ_BASE_SHIFT = 5;
535 var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
538 var VLQ_BASE_MASK = VLQ_BASE - 1;
541 var VLQ_CONTINUATION_BIT = VLQ_BASE;
544 * Converts from a two-complement value to a value where the sign bit is
545 * placed in the least significant bit. For example, as decimals:
546 * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
547 * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
549 function toVLQSigned(aValue) {
551 ? ((-aValue) << 1) + 1
556 * Converts to a two-complement value from a value where the sign bit is
557 * placed in the least significant bit. For example, as decimals:
558 * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
559 * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
561 function fromVLQSigned(aValue) {
562 var isNegative = (aValue & 1) === 1;
563 var shifted = aValue >> 1;
570 * Returns the base 64 VLQ encoded value.
572 exports.encode = function base64VLQ_encode(aValue) {
576 var vlq = toVLQSigned(aValue);
579 digit = vlq & VLQ_BASE_MASK;
580 vlq >>>= VLQ_BASE_SHIFT;
582 // There are still more digits in this value, so we must make sure the
583 // continuation bit is marked.
584 digit |= VLQ_CONTINUATION_BIT;
586 encoded += base64.encode(digit);
593 * Decodes the next base 64 VLQ value from the given string and returns the
594 * value and the rest of the string via the out parameter.
596 exports.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
597 var strLen = aStr.length;
600 var continuation, digit;
603 if (aIndex >= strLen) {
604 throw new Error("Expected more digits in base 64 VLQ value.");
607 digit = base64.decode(aStr.charCodeAt(aIndex++));
609 throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
612 continuation = !!(digit & VLQ_CONTINUATION_BIT);
613 digit &= VLQ_BASE_MASK;
614 result = result + (digit << shift);
615 shift += VLQ_BASE_SHIFT;
616 } while (continuation);
618 aOutParam.value = fromVLQSigned(result);
619 aOutParam.rest = aIndex;
625 /***/ function(module, exports) {
627 /* -*- Mode: js; js-indent-level: 2; -*- */
629 * Copyright 2011 Mozilla Foundation and contributors
630 * Licensed under the New BSD license. See LICENSE or:
631 * http://opensource.org/licenses/BSD-3-Clause
634 var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
637 * Encode an integer in the range of 0 to 63 to a single base 64 digit.
639 exports.encode = function (number) {
640 if (0 <= number && number < intToCharMap.length) {
641 return intToCharMap[number];
643 throw new TypeError("Must be between 0 and 63: " + number);
647 * Decode a single base 64 character code digit to an integer. Returns -1 on
650 exports.decode = function (charCode) {
651 var bigA = 65; // 'A'
652 var bigZ = 90; // 'Z'
654 var littleA = 97; // 'a'
655 var littleZ = 122; // 'z'
657 var zero = 48; // '0'
658 var nine = 57; // '9'
660 var plus = 43; // '+'
661 var slash = 47; // '/'
663 var littleOffset = 26;
664 var numberOffset = 52;
666 // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
667 if (bigA <= charCode && charCode <= bigZ) {
668 return (charCode - bigA);
671 // 26 - 51: abcdefghijklmnopqrstuvwxyz
672 if (littleA <= charCode && charCode <= littleZ) {
673 return (charCode - littleA + littleOffset);
676 // 52 - 61: 0123456789
677 if (zero <= charCode && charCode <= nine) {
678 return (charCode - zero + numberOffset);
682 if (charCode == plus) {
687 if (charCode == slash) {
691 // Invalid base64 digit.
698 /***/ function(module, exports) {
700 /* -*- Mode: js; js-indent-level: 2; -*- */
702 * Copyright 2011 Mozilla Foundation and contributors
703 * Licensed under the New BSD license. See LICENSE or:
704 * http://opensource.org/licenses/BSD-3-Clause
708 * This is a helper function for getting values from parameter/options
711 * @param args The object we are extracting values from
712 * @param name The name of the property we are getting.
713 * @param defaultValue An optional value to return if the property is missing
714 * from the object. If this is not specified and the property is missing, an
715 * error will be thrown.
717 function getArg(aArgs, aName, aDefaultValue) {
718 if (aName in aArgs) {
720 } else if (arguments.length === 3) {
721 return aDefaultValue;
723 throw new Error('"' + aName + '" is a required argument.');
726 exports.getArg = getArg;
728 var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.]*)(?::(\d+))?(\S*)$/;
729 var dataUrlRegexp = /^data:.+\,.+$/;
731 function urlParse(aUrl) {
732 var match = aUrl.match(urlRegexp);
744 exports.urlParse = urlParse;
746 function urlGenerate(aParsedUrl) {
748 if (aParsedUrl.scheme) {
749 url += aParsedUrl.scheme + ':';
752 if (aParsedUrl.auth) {
753 url += aParsedUrl.auth + '@';
755 if (aParsedUrl.host) {
756 url += aParsedUrl.host;
758 if (aParsedUrl.port) {
759 url += ":" + aParsedUrl.port
761 if (aParsedUrl.path) {
762 url += aParsedUrl.path;
766 exports.urlGenerate = urlGenerate;
769 * Normalizes a path, or the path portion of a URL:
771 * - Replaces consequtive slashes with one slash.
772 * - Removes unnecessary '.' parts.
773 * - Removes unnecessary '<dir>/..' parts.
775 * Based on code in the Node.js 'path' core module.
777 * @param aPath The path or url to normalize.
779 function normalize(aPath) {
781 var url = urlParse(aPath);
788 var isAbsolute = exports.isAbsolute(path);
790 var parts = path.split(/\/+/);
791 for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
795 } else if (part === '..') {
799 // The first part is blank if the path is absolute. Trying to go
800 // above the root is a no-op. Therefore we can remove all '..' parts
801 // directly after the root.
802 parts.splice(i + 1, up);
810 path = parts.join('/');
813 path = isAbsolute ? '/' : '.';
818 return urlGenerate(url);
822 exports.normalize = normalize;
825 * Joins two paths/URLs.
827 * @param aRoot The root path or URL.
828 * @param aPath The path or URL to be joined with the root.
830 * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
831 * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
833 * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
834 * is updated with the result and aRoot is returned. Otherwise the result
836 * - If aPath is absolute, the result is aPath.
837 * - Otherwise the two paths are joined with a slash.
838 * - Joining for example 'http://' and 'www.example.com' is also supported.
840 function join(aRoot, aPath) {
847 var aPathUrl = urlParse(aPath);
848 var aRootUrl = urlParse(aRoot);
850 aRoot = aRootUrl.path || '/';
853 // `join(foo, '//www.example.org')`
854 if (aPathUrl && !aPathUrl.scheme) {
856 aPathUrl.scheme = aRootUrl.scheme;
858 return urlGenerate(aPathUrl);
861 if (aPathUrl || aPath.match(dataUrlRegexp)) {
865 // `join('http://', 'www.example.com')`
866 if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
867 aRootUrl.host = aPath;
868 return urlGenerate(aRootUrl);
871 var joined = aPath.charAt(0) === '/'
873 : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
876 aRootUrl.path = joined;
877 return urlGenerate(aRootUrl);
883 exports.isAbsolute = function (aPath) {
884 return aPath.charAt(0) === '/' || !!aPath.match(urlRegexp);
888 * Make a path relative to a URL or another path.
890 * @param aRoot The root path or URL.
891 * @param aPath The path or URL to be made relative to aRoot.
893 function relative(aRoot, aPath) {
898 aRoot = aRoot.replace(/\/$/, '');
900 // It is possible for the path to be above the root. In this case, simply
901 // checking whether the root is a prefix of the path won't work. Instead, we
902 // need to remove components from the root one by one, until either we find
903 // a prefix that fits, or we run out of components to remove.
905 while (aPath.indexOf(aRoot + '/') !== 0) {
906 var index = aRoot.lastIndexOf("/");
911 // If the only part of the root that is left is the scheme (i.e. http://,
912 // file:///, etc.), one or more slashes (/), or simply nothing at all, we
913 // have exhausted all components, so the path is not relative to the root.
914 aRoot = aRoot.slice(0, index);
915 if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
922 // Make sure we add a "../" for each component we removed from the root.
923 return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
925 exports.relative = relative;
927 var supportsNullProto = (function () {
928 var obj = Object.create(null);
929 return !('__proto__' in obj);
932 function identity (s) {
937 * Because behavior goes wacky when you set `__proto__` on objects, we
938 * have to prefix all the strings in our set with an arbitrary character.
940 * See https://github.com/mozilla/source-map/pull/31 and
941 * https://github.com/mozilla/source-map/issues/30
945 function toSetString(aStr) {
946 if (isProtoString(aStr)) {
952 exports.toSetString = supportsNullProto ? identity : toSetString;
954 function fromSetString(aStr) {
955 if (isProtoString(aStr)) {
956 return aStr.slice(1);
961 exports.fromSetString = supportsNullProto ? identity : fromSetString;
963 function isProtoString(s) {
968 var length = s.length;
970 if (length < 9 /* "__proto__".length */) {
974 if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
975 s.charCodeAt(length - 2) !== 95 /* '_' */ ||
976 s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
977 s.charCodeAt(length - 4) !== 116 /* 't' */ ||
978 s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
979 s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
980 s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
981 s.charCodeAt(length - 8) !== 95 /* '_' */ ||
982 s.charCodeAt(length - 9) !== 95 /* '_' */) {
986 for (var i = length - 10; i >= 0; i--) {
987 if (s.charCodeAt(i) !== 36 /* '$' */) {
996 * Comparator between two mappings where the original positions are compared.
998 * Optionally pass in `true` as `onlyCompareGenerated` to consider two
999 * mappings with the same original source/line/column, but different generated
1000 * line and column the same. Useful when searching for a mapping with a
1001 * stubbed out mapping.
1003 function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
1004 var cmp = mappingA.source - mappingB.source;
1009 cmp = mappingA.originalLine - mappingB.originalLine;
1014 cmp = mappingA.originalColumn - mappingB.originalColumn;
1015 if (cmp !== 0 || onlyCompareOriginal) {
1019 cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1024 cmp = mappingA.generatedLine - mappingB.generatedLine;
1029 return mappingA.name - mappingB.name;
1031 exports.compareByOriginalPositions = compareByOriginalPositions;
1034 * Comparator between two mappings with deflated source and name indices where
1035 * the generated positions are compared.
1037 * Optionally pass in `true` as `onlyCompareGenerated` to consider two
1038 * mappings with the same generated line and column, but different
1039 * source/name/original line and column the same. Useful when searching for a
1040 * mapping with a stubbed out mapping.
1042 function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
1043 var cmp = mappingA.generatedLine - mappingB.generatedLine;
1048 cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1049 if (cmp !== 0 || onlyCompareGenerated) {
1053 cmp = mappingA.source - mappingB.source;
1058 cmp = mappingA.originalLine - mappingB.originalLine;
1063 cmp = mappingA.originalColumn - mappingB.originalColumn;
1068 return mappingA.name - mappingB.name;
1070 exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
1072 function strcmp(aStr1, aStr2) {
1073 if (aStr1 === aStr2) {
1077 if (aStr1 > aStr2) {
1085 * Comparator between two mappings with inflated source and name strings where
1086 * the generated positions are compared.
1088 function compareByGeneratedPositionsInflated(mappingA, mappingB) {
1089 var cmp = mappingA.generatedLine - mappingB.generatedLine;
1094 cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1099 cmp = strcmp(mappingA.source, mappingB.source);
1104 cmp = mappingA.originalLine - mappingB.originalLine;
1109 cmp = mappingA.originalColumn - mappingB.originalColumn;
1114 return strcmp(mappingA.name, mappingB.name);
1116 exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
1121 /***/ function(module, exports, __webpack_require__) {
1123 /* -*- Mode: js; js-indent-level: 2; -*- */
1125 * Copyright 2011 Mozilla Foundation and contributors
1126 * Licensed under the New BSD license. See LICENSE or:
1127 * http://opensource.org/licenses/BSD-3-Clause
1130 var util = __webpack_require__(4);
1131 var has = Object.prototype.hasOwnProperty;
1134 * A data structure which is a combination of an array and a set. Adding a new
1135 * member is O(1), testing for membership is O(1), and finding the index of an
1136 * element is O(1). Removing elements from the set is not supported. Only
1137 * strings are supported for membership.
1139 function ArraySet() {
1141 this._set = Object.create(null);
1145 * Static method for creating ArraySet instances from an existing array.
1147 ArraySet.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
1148 var set = new ArraySet();
1149 for (var i = 0, len = aArray.length; i < len; i++) {
1150 set.add(aArray[i], aAllowDuplicates);
1156 * Return how many unique items are in this ArraySet. If duplicates have been
1157 * added, than those do not count towards the size.
1161 ArraySet.prototype.size = function ArraySet_size() {
1162 return Object.getOwnPropertyNames(this._set).length;
1166 * Add the given string to this set.
1168 * @param String aStr
1170 ArraySet.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
1171 var sStr = util.toSetString(aStr);
1172 var isDuplicate = has.call(this._set, sStr);
1173 var idx = this._array.length;
1174 if (!isDuplicate || aAllowDuplicates) {
1175 this._array.push(aStr);
1178 this._set[sStr] = idx;
1183 * Is the given string a member of this set?
1185 * @param String aStr
1187 ArraySet.prototype.has = function ArraySet_has(aStr) {
1188 var sStr = util.toSetString(aStr);
1189 return has.call(this._set, sStr);
1193 * What is the index of the given string in the array?
1195 * @param String aStr
1197 ArraySet.prototype.indexOf = function ArraySet_indexOf(aStr) {
1198 var sStr = util.toSetString(aStr);
1199 if (has.call(this._set, sStr)) {
1200 return this._set[sStr];
1202 throw new Error('"' + aStr + '" is not in the set.');
1206 * What is the element at the given index?
1208 * @param Number aIdx
1210 ArraySet.prototype.at = function ArraySet_at(aIdx) {
1211 if (aIdx >= 0 && aIdx < this._array.length) {
1212 return this._array[aIdx];
1214 throw new Error('No element indexed by ' + aIdx);
1218 * Returns the array representation of this set (which has the proper indices
1219 * indicated by indexOf). Note that this is a copy of the internal array used
1220 * for storing the members so that no one can mess with internal state.
1222 ArraySet.prototype.toArray = function ArraySet_toArray() {
1223 return this._array.slice();
1226 exports.ArraySet = ArraySet;
1231 /***/ function(module, exports, __webpack_require__) {
1233 /* -*- Mode: js; js-indent-level: 2; -*- */
1235 * Copyright 2014 Mozilla Foundation and contributors
1236 * Licensed under the New BSD license. See LICENSE or:
1237 * http://opensource.org/licenses/BSD-3-Clause
1240 var util = __webpack_require__(4);
1243 * Determine whether mappingB is after mappingA with respect to generated
1246 function generatedPositionAfter(mappingA, mappingB) {
1247 // Optimized for most common case
1248 var lineA = mappingA.generatedLine;
1249 var lineB = mappingB.generatedLine;
1250 var columnA = mappingA.generatedColumn;
1251 var columnB = mappingB.generatedColumn;
1252 return lineB > lineA || lineB == lineA && columnB >= columnA ||
1253 util.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
1257 * A data structure to provide a sorted view of accumulated mappings in a
1258 * performance conscious manner. It trades a neglibable overhead in general
1259 * case for a large speedup in case of mappings being added in order.
1261 function MappingList() {
1263 this._sorted = true;
1264 // Serves as infimum
1265 this._last = {generatedLine: -1, generatedColumn: 0};
1269 * Iterate through internal items. This method takes the same arguments that
1270 * `Array.prototype.forEach` takes.
1272 * NOTE: The order of the mappings is NOT guaranteed.
1274 MappingList.prototype.unsortedForEach =
1275 function MappingList_forEach(aCallback, aThisArg) {
1276 this._array.forEach(aCallback, aThisArg);
1280 * Add the given source mapping.
1282 * @param Object aMapping
1284 MappingList.prototype.add = function MappingList_add(aMapping) {
1285 if (generatedPositionAfter(this._last, aMapping)) {
1286 this._last = aMapping;
1287 this._array.push(aMapping);
1289 this._sorted = false;
1290 this._array.push(aMapping);
1295 * Returns the flat, sorted array of mappings. The mappings are sorted by
1296 * generated position.
1298 * WARNING: This method returns internal data without copying, for
1299 * performance. The return value must NOT be mutated, and should be treated as
1300 * an immutable borrow. If you want to take ownership, you must make your own
1303 MappingList.prototype.toArray = function MappingList_toArray() {
1304 if (!this._sorted) {
1305 this._array.sort(util.compareByGeneratedPositionsInflated);
1306 this._sorted = true;
1311 exports.MappingList = MappingList;
1316 /***/ function(module, exports, __webpack_require__) {
1318 /* -*- Mode: js; js-indent-level: 2; -*- */
1320 * Copyright 2011 Mozilla Foundation and contributors
1321 * Licensed under the New BSD license. See LICENSE or:
1322 * http://opensource.org/licenses/BSD-3-Clause
1325 var util = __webpack_require__(4);
1326 var binarySearch = __webpack_require__(8);
1327 var ArraySet = __webpack_require__(5).ArraySet;
1328 var base64VLQ = __webpack_require__(2);
1329 var quickSort = __webpack_require__(9).quickSort;
1331 function SourceMapConsumer(aSourceMap) {
1332 var sourceMap = aSourceMap;
1333 if (typeof aSourceMap === 'string') {
1334 sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
1337 return sourceMap.sections != null
1338 ? new IndexedSourceMapConsumer(sourceMap)
1339 : new BasicSourceMapConsumer(sourceMap);
1342 SourceMapConsumer.fromSourceMap = function(aSourceMap) {
1343 return BasicSourceMapConsumer.fromSourceMap(aSourceMap);
1347 * The version of the source mapping spec that we are consuming.
1349 SourceMapConsumer.prototype._version = 3;
1351 // `__generatedMappings` and `__originalMappings` are arrays that hold the
1352 // parsed mapping coordinates from the source map's "mappings" attribute. They
1353 // are lazily instantiated, accessed via the `_generatedMappings` and
1354 // `_originalMappings` getters respectively, and we only parse the mappings
1355 // and create these arrays once queried for a source location. We jump through
1356 // these hoops because there can be many thousands of mappings, and parsing
1357 // them is expensive, so we only want to do it if we must.
1359 // Each object in the arrays is of the form:
1362 // generatedLine: The line number in the generated code,
1363 // generatedColumn: The column number in the generated code,
1364 // source: The path to the original source file that generated this
1366 // originalLine: The line number in the original source that
1367 // corresponds to this chunk of generated code,
1368 // originalColumn: The column number in the original source that
1369 // corresponds to this chunk of generated code,
1370 // name: The name of the original symbol which generated this chunk of
1374 // All properties except for `generatedLine` and `generatedColumn` can be
1377 // `_generatedMappings` is ordered by the generated positions.
1379 // `_originalMappings` is ordered by the original positions.
1381 SourceMapConsumer.prototype.__generatedMappings = null;
1382 Object.defineProperty(SourceMapConsumer.prototype, '_generatedMappings', {
1384 if (!this.__generatedMappings) {
1385 this._parseMappings(this._mappings, this.sourceRoot);
1388 return this.__generatedMappings;
1392 SourceMapConsumer.prototype.__originalMappings = null;
1393 Object.defineProperty(SourceMapConsumer.prototype, '_originalMappings', {
1395 if (!this.__originalMappings) {
1396 this._parseMappings(this._mappings, this.sourceRoot);
1399 return this.__originalMappings;
1403 SourceMapConsumer.prototype._charIsMappingSeparator =
1404 function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
1405 var c = aStr.charAt(index);
1406 return c === ";" || c === ",";
1410 * Parse the mappings in a string in to a data structure which we can easily
1411 * query (the ordered arrays in the `this.__generatedMappings` and
1412 * `this.__originalMappings` properties).
1414 SourceMapConsumer.prototype._parseMappings =
1415 function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
1416 throw new Error("Subclasses must implement _parseMappings");
1419 SourceMapConsumer.GENERATED_ORDER = 1;
1420 SourceMapConsumer.ORIGINAL_ORDER = 2;
1422 SourceMapConsumer.GREATEST_LOWER_BOUND = 1;
1423 SourceMapConsumer.LEAST_UPPER_BOUND = 2;
1426 * Iterate over each mapping between an original source/line/column and a
1427 * generated line/column in this source map.
1429 * @param Function aCallback
1430 * The function that is called with each mapping.
1431 * @param Object aContext
1432 * Optional. If specified, this object will be the value of `this` every
1433 * time that `aCallback` is called.
1435 * Either `SourceMapConsumer.GENERATED_ORDER` or
1436 * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
1437 * iterate over the mappings sorted by the generated file's line/column
1438 * order or the original's source/line/column order, respectively. Defaults to
1439 * `SourceMapConsumer.GENERATED_ORDER`.
1441 SourceMapConsumer.prototype.eachMapping =
1442 function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
1443 var context = aContext || null;
1444 var order = aOrder || SourceMapConsumer.GENERATED_ORDER;
1448 case SourceMapConsumer.GENERATED_ORDER:
1449 mappings = this._generatedMappings;
1451 case SourceMapConsumer.ORIGINAL_ORDER:
1452 mappings = this._originalMappings;
1455 throw new Error("Unknown order of iteration.");
1458 var sourceRoot = this.sourceRoot;
1459 mappings.map(function (mapping) {
1460 var source = mapping.source === null ? null : this._sources.at(mapping.source);
1461 if (source != null && sourceRoot != null) {
1462 source = util.join(sourceRoot, source);
1466 generatedLine: mapping.generatedLine,
1467 generatedColumn: mapping.generatedColumn,
1468 originalLine: mapping.originalLine,
1469 originalColumn: mapping.originalColumn,
1470 name: mapping.name === null ? null : this._names.at(mapping.name)
1472 }, this).forEach(aCallback, context);
1476 * Returns all generated line and column information for the original source,
1477 * line, and column provided. If no column is provided, returns all mappings
1478 * corresponding to a either the line we are searching for or the next
1479 * closest line that has any mappings. Otherwise, returns all mappings
1480 * corresponding to the given line and either the column we are searching for
1481 * or the next closest column that has any offsets.
1483 * The only argument is an object with the following properties:
1485 * - source: The filename of the original source.
1486 * - line: The line number in the original source.
1487 * - column: Optional. the column number in the original source.
1489 * and an array of objects is returned, each with the following properties:
1491 * - line: The line number in the generated source, or null.
1492 * - column: The column number in the generated source, or null.
1494 SourceMapConsumer.prototype.allGeneratedPositionsFor =
1495 function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
1496 var line = util.getArg(aArgs, 'line');
1498 // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
1499 // returns the index of the closest mapping less than the needle. By
1500 // setting needle.originalColumn to 0, we thus find the last mapping for
1501 // the given line, provided such a mapping exists.
1503 source: util.getArg(aArgs, 'source'),
1505 originalColumn: util.getArg(aArgs, 'column', 0)
1508 if (this.sourceRoot != null) {
1509 needle.source = util.relative(this.sourceRoot, needle.source);
1511 if (!this._sources.has(needle.source)) {
1514 needle.source = this._sources.indexOf(needle.source);
1518 var index = this._findMapping(needle,
1519 this._originalMappings,
1522 util.compareByOriginalPositions,
1523 binarySearch.LEAST_UPPER_BOUND);
1525 var mapping = this._originalMappings[index];
1527 if (aArgs.column === undefined) {
1528 var originalLine = mapping.originalLine;
1530 // Iterate until either we run out of mappings, or we run into
1531 // a mapping for a different line than the one we found. Since
1532 // mappings are sorted, this is guaranteed to find all mappings for
1533 // the line we found.
1534 while (mapping && mapping.originalLine === originalLine) {
1536 line: util.getArg(mapping, 'generatedLine', null),
1537 column: util.getArg(mapping, 'generatedColumn', null),
1538 lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
1541 mapping = this._originalMappings[++index];
1544 var originalColumn = mapping.originalColumn;
1546 // Iterate until either we run out of mappings, or we run into
1547 // a mapping for a different line than the one we were searching for.
1548 // Since mappings are sorted, this is guaranteed to find all mappings for
1549 // the line we are searching for.
1551 mapping.originalLine === line &&
1552 mapping.originalColumn == originalColumn) {
1554 line: util.getArg(mapping, 'generatedLine', null),
1555 column: util.getArg(mapping, 'generatedColumn', null),
1556 lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
1559 mapping = this._originalMappings[++index];
1567 exports.SourceMapConsumer = SourceMapConsumer;
1570 * A BasicSourceMapConsumer instance represents a parsed source map which we can
1571 * query for information about the original file positions by giving it a file
1572 * position in the generated source.
1574 * The only parameter is the raw source map (either as a JSON string, or
1575 * already parsed to an object). According to the spec, source maps have the
1576 * following attributes:
1578 * - version: Which version of the source map spec this map is following.
1579 * - sources: An array of URLs to the original source files.
1580 * - names: An array of identifiers which can be referrenced by individual mappings.
1581 * - sourceRoot: Optional. The URL root from which all sources are relative.
1582 * - sourcesContent: Optional. An array of contents of the original source files.
1583 * - mappings: A string of base64 VLQs which contain the actual mappings.
1584 * - file: Optional. The generated file this source map is associated with.
1586 * Here is an example source map, taken from the source map spec[0]:
1592 * sources: ["foo.js", "bar.js"],
1593 * names: ["src", "maps", "are", "fun"],
1594 * mappings: "AA,AB;;ABCDE;"
1597 * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
1599 function BasicSourceMapConsumer(aSourceMap) {
1600 var sourceMap = aSourceMap;
1601 if (typeof aSourceMap === 'string') {
1602 sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
1605 var version = util.getArg(sourceMap, 'version');
1606 var sources = util.getArg(sourceMap, 'sources');
1607 // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
1608 // requires the array) to play nice here.
1609 var names = util.getArg(sourceMap, 'names', []);
1610 var sourceRoot = util.getArg(sourceMap, 'sourceRoot', null);
1611 var sourcesContent = util.getArg(sourceMap, 'sourcesContent', null);
1612 var mappings = util.getArg(sourceMap, 'mappings');
1613 var file = util.getArg(sourceMap, 'file', null);
1615 // Once again, Sass deviates from the spec and supplies the version as a
1616 // string rather than a number, so we use loose equality checking here.
1617 if (version != this._version) {
1618 throw new Error('Unsupported version: ' + version);
1623 // Some source maps produce relative source paths like "./foo.js" instead of
1624 // "foo.js". Normalize these first so that future comparisons will succeed.
1625 // See bugzil.la/1090768.
1626 .map(util.normalize)
1627 // Always ensure that absolute sources are internally stored relative to
1628 // the source root, if the source root is absolute. Not doing this would
1629 // be particularly problematic when the source root is a prefix of the
1630 // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
1631 .map(function (source) {
1632 return sourceRoot && util.isAbsolute(sourceRoot) && util.isAbsolute(source)
1633 ? util.relative(sourceRoot, source)
1637 // Pass `true` below to allow duplicate names and sources. While source maps
1638 // are intended to be compressed and deduplicated, the TypeScript compiler
1639 // sometimes generates source maps with duplicates in them. See Github issue
1640 // #72 and bugzil.la/889492.
1641 this._names = ArraySet.fromArray(names.map(String), true);
1642 this._sources = ArraySet.fromArray(sources, true);
1644 this.sourceRoot = sourceRoot;
1645 this.sourcesContent = sourcesContent;
1646 this._mappings = mappings;
1650 BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
1651 BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer;
1654 * Create a BasicSourceMapConsumer from a SourceMapGenerator.
1656 * @param SourceMapGenerator aSourceMap
1657 * The source map that will be consumed.
1658 * @returns BasicSourceMapConsumer
1660 BasicSourceMapConsumer.fromSourceMap =
1661 function SourceMapConsumer_fromSourceMap(aSourceMap) {
1662 var smc = Object.create(BasicSourceMapConsumer.prototype);
1664 var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
1665 var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
1666 smc.sourceRoot = aSourceMap._sourceRoot;
1667 smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
1669 smc.file = aSourceMap._file;
1671 // Because we are modifying the entries (by converting string sources and
1672 // names to indices into the sources and names ArraySets), we have to make
1673 // a copy of the entry or else bad things happen. Shared mutable state
1674 // strikes again! See github issue #191.
1676 var generatedMappings = aSourceMap._mappings.toArray().slice();
1677 var destGeneratedMappings = smc.__generatedMappings = [];
1678 var destOriginalMappings = smc.__originalMappings = [];
1680 for (var i = 0, length = generatedMappings.length; i < length; i++) {
1681 var srcMapping = generatedMappings[i];
1682 var destMapping = new Mapping;
1683 destMapping.generatedLine = srcMapping.generatedLine;
1684 destMapping.generatedColumn = srcMapping.generatedColumn;
1686 if (srcMapping.source) {
1687 destMapping.source = sources.indexOf(srcMapping.source);
1688 destMapping.originalLine = srcMapping.originalLine;
1689 destMapping.originalColumn = srcMapping.originalColumn;
1691 if (srcMapping.name) {
1692 destMapping.name = names.indexOf(srcMapping.name);
1695 destOriginalMappings.push(destMapping);
1698 destGeneratedMappings.push(destMapping);
1701 quickSort(smc.__originalMappings, util.compareByOriginalPositions);
1707 * The version of the source mapping spec that we are consuming.
1709 BasicSourceMapConsumer.prototype._version = 3;
1712 * The list of original sources.
1714 Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
1716 return this._sources.toArray().map(function (s) {
1717 return this.sourceRoot != null ? util.join(this.sourceRoot, s) : s;
1723 * Provide the JIT with a nice shape / hidden class.
1725 function Mapping() {
1726 this.generatedLine = 0;
1727 this.generatedColumn = 0;
1729 this.originalLine = null;
1730 this.originalColumn = null;
1735 * Parse the mappings in a string in to a data structure which we can easily
1736 * query (the ordered arrays in the `this.__generatedMappings` and
1737 * `this.__originalMappings` properties).
1739 BasicSourceMapConsumer.prototype._parseMappings =
1740 function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
1741 var generatedLine = 1;
1742 var previousGeneratedColumn = 0;
1743 var previousOriginalLine = 0;
1744 var previousOriginalColumn = 0;
1745 var previousSource = 0;
1746 var previousName = 0;
1747 var length = aStr.length;
1749 var cachedSegments = {};
1751 var originalMappings = [];
1752 var generatedMappings = [];
1753 var mapping, str, segment, end, value;
1755 while (index < length) {
1756 if (aStr.charAt(index) === ';') {
1759 previousGeneratedColumn = 0;
1761 else if (aStr.charAt(index) === ',') {
1765 mapping = new Mapping();
1766 mapping.generatedLine = generatedLine;
1768 // Because each offset is encoded relative to the previous one,
1769 // many segments often have the same encoding. We can exploit this
1770 // fact by caching the parsed variable length fields of each segment,
1771 // allowing us to avoid a second parse if we encounter the same
1773 for (end = index; end < length; end++) {
1774 if (this._charIsMappingSeparator(aStr, end)) {
1778 str = aStr.slice(index, end);
1780 segment = cachedSegments[str];
1782 index += str.length;
1785 while (index < end) {
1786 base64VLQ.decode(aStr, index, temp);
1789 segment.push(value);
1792 if (segment.length === 2) {
1793 throw new Error('Found a source, but no line and column');
1796 if (segment.length === 3) {
1797 throw new Error('Found a source and line, but no column');
1800 cachedSegments[str] = segment;
1803 // Generated column.
1804 mapping.generatedColumn = previousGeneratedColumn + segment[0];
1805 previousGeneratedColumn = mapping.generatedColumn;
1807 if (segment.length > 1) {
1809 mapping.source = previousSource + segment[1];
1810 previousSource += segment[1];
1813 mapping.originalLine = previousOriginalLine + segment[2];
1814 previousOriginalLine = mapping.originalLine;
1815 // Lines are stored 0-based
1816 mapping.originalLine += 1;
1819 mapping.originalColumn = previousOriginalColumn + segment[3];
1820 previousOriginalColumn = mapping.originalColumn;
1822 if (segment.length > 4) {
1824 mapping.name = previousName + segment[4];
1825 previousName += segment[4];
1829 generatedMappings.push(mapping);
1830 if (typeof mapping.originalLine === 'number') {
1831 originalMappings.push(mapping);
1836 quickSort(generatedMappings, util.compareByGeneratedPositionsDeflated);
1837 this.__generatedMappings = generatedMappings;
1839 quickSort(originalMappings, util.compareByOriginalPositions);
1840 this.__originalMappings = originalMappings;
1844 * Find the mapping that best matches the hypothetical "needle" mapping that
1845 * we are searching for in the given "haystack" of mappings.
1847 BasicSourceMapConsumer.prototype._findMapping =
1848 function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
1849 aColumnName, aComparator, aBias) {
1850 // To return the position we are searching for, we must first find the
1851 // mapping for the given position and then return the opposite position it
1852 // points to. Because the mappings are sorted, we can use binary search to
1853 // find the best mapping.
1855 if (aNeedle[aLineName] <= 0) {
1856 throw new TypeError('Line must be greater than or equal to 1, got '
1857 + aNeedle[aLineName]);
1859 if (aNeedle[aColumnName] < 0) {
1860 throw new TypeError('Column must be greater than or equal to 0, got '
1861 + aNeedle[aColumnName]);
1864 return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
1868 * Compute the last column for each generated mapping. The last column is
1871 BasicSourceMapConsumer.prototype.computeColumnSpans =
1872 function SourceMapConsumer_computeColumnSpans() {
1873 for (var index = 0; index < this._generatedMappings.length; ++index) {
1874 var mapping = this._generatedMappings[index];
1876 // Mappings do not contain a field for the last generated columnt. We
1877 // can come up with an optimistic estimate, however, by assuming that
1878 // mappings are contiguous (i.e. given two consecutive mappings, the
1879 // first mapping ends where the second one starts).
1880 if (index + 1 < this._generatedMappings.length) {
1881 var nextMapping = this._generatedMappings[index + 1];
1883 if (mapping.generatedLine === nextMapping.generatedLine) {
1884 mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
1889 // The last mapping for each line spans the entire line.
1890 mapping.lastGeneratedColumn = Infinity;
1895 * Returns the original source, line, and column information for the generated
1896 * source's line and column positions provided. The only argument is an object
1897 * with the following properties:
1899 * - line: The line number in the generated source.
1900 * - column: The column number in the generated source.
1901 * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
1902 * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
1903 * closest element that is smaller than or greater than the one we are
1904 * searching for, respectively, if the exact element cannot be found.
1905 * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
1907 * and an object is returned with the following properties:
1909 * - source: The original source file, or null.
1910 * - line: The line number in the original source, or null.
1911 * - column: The column number in the original source, or null.
1912 * - name: The original identifier, or null.
1914 BasicSourceMapConsumer.prototype.originalPositionFor =
1915 function SourceMapConsumer_originalPositionFor(aArgs) {
1917 generatedLine: util.getArg(aArgs, 'line'),
1918 generatedColumn: util.getArg(aArgs, 'column')
1921 var index = this._findMapping(
1923 this._generatedMappings,
1926 util.compareByGeneratedPositionsDeflated,
1927 util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
1931 var mapping = this._generatedMappings[index];
1933 if (mapping.generatedLine === needle.generatedLine) {
1934 var source = util.getArg(mapping, 'source', null);
1935 if (source !== null) {
1936 source = this._sources.at(source);
1937 if (this.sourceRoot != null) {
1938 source = util.join(this.sourceRoot, source);
1941 var name = util.getArg(mapping, 'name', null);
1942 if (name !== null) {
1943 name = this._names.at(name);
1947 line: util.getArg(mapping, 'originalLine', null),
1948 column: util.getArg(mapping, 'originalColumn', null),
1963 * Return true if we have the source content for every source in the source
1964 * map, false otherwise.
1966 BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
1967 function BasicSourceMapConsumer_hasContentsOfAllSources() {
1968 if (!this.sourcesContent) {
1971 return this.sourcesContent.length >= this._sources.size() &&
1972 !this.sourcesContent.some(function (sc) { return sc == null; });
1976 * Returns the original source content. The only argument is the url of the
1977 * original source file. Returns null if no original source content is
1980 BasicSourceMapConsumer.prototype.sourceContentFor =
1981 function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
1982 if (!this.sourcesContent) {
1986 if (this.sourceRoot != null) {
1987 aSource = util.relative(this.sourceRoot, aSource);
1990 if (this._sources.has(aSource)) {
1991 return this.sourcesContent[this._sources.indexOf(aSource)];
1995 if (this.sourceRoot != null
1996 && (url = util.urlParse(this.sourceRoot))) {
1997 // XXX: file:// URIs and absolute paths lead to unexpected behavior for
1998 // many users. We can help them out when they expect file:// URIs to
1999 // behave like it would if they were running a local HTTP server. See
2000 // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
2001 var fileUriAbsPath = aSource.replace(/^file:\/\//, "");
2002 if (url.scheme == "file"
2003 && this._sources.has(fileUriAbsPath)) {
2004 return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
2007 if ((!url.path || url.path == "/")
2008 && this._sources.has("/" + aSource)) {
2009 return this.sourcesContent[this._sources.indexOf("/" + aSource)];
2013 // This function is used recursively from
2014 // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
2015 // don't want to throw if we can't find the source - we just want to
2016 // return null, so we provide a flag to exit gracefully.
2017 if (nullOnMissing) {
2021 throw new Error('"' + aSource + '" is not in the SourceMap.');
2026 * Returns the generated line and column information for the original source,
2027 * line, and column positions provided. The only argument is an object with
2028 * the following properties:
2030 * - source: The filename of the original source.
2031 * - line: The line number in the original source.
2032 * - column: The column number in the original source.
2033 * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
2034 * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
2035 * closest element that is smaller than or greater than the one we are
2036 * searching for, respectively, if the exact element cannot be found.
2037 * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
2039 * and an object is returned with the following properties:
2041 * - line: The line number in the generated source, or null.
2042 * - column: The column number in the generated source, or null.
2044 BasicSourceMapConsumer.prototype.generatedPositionFor =
2045 function SourceMapConsumer_generatedPositionFor(aArgs) {
2046 var source = util.getArg(aArgs, 'source');
2047 if (this.sourceRoot != null) {
2048 source = util.relative(this.sourceRoot, source);
2050 if (!this._sources.has(source)) {
2057 source = this._sources.indexOf(source);
2061 originalLine: util.getArg(aArgs, 'line'),
2062 originalColumn: util.getArg(aArgs, 'column')
2065 var index = this._findMapping(
2067 this._originalMappings,
2070 util.compareByOriginalPositions,
2071 util.getArg(aArgs, 'bias', SourceMapConsumer.GREATEST_LOWER_BOUND)
2075 var mapping = this._originalMappings[index];
2077 if (mapping.source === needle.source) {
2079 line: util.getArg(mapping, 'generatedLine', null),
2080 column: util.getArg(mapping, 'generatedColumn', null),
2081 lastColumn: util.getArg(mapping, 'lastGeneratedColumn', null)
2093 exports.BasicSourceMapConsumer = BasicSourceMapConsumer;
2096 * An IndexedSourceMapConsumer instance represents a parsed source map which
2097 * we can query for information. It differs from BasicSourceMapConsumer in
2098 * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
2101 * The only parameter is a raw source map (either as a JSON string, or already
2102 * parsed to an object). According to the spec for indexed source maps, they
2103 * have the following attributes:
2105 * - version: Which version of the source map spec this map is following.
2106 * - file: Optional. The generated file this source map is associated with.
2107 * - sections: A list of section definitions.
2109 * Each value under the "sections" field has two fields:
2110 * - offset: The offset into the original specified at which this section
2111 * begins to apply, defined as an object with a "line" and "column"
2113 * - map: A source map definition. This source map could also be indexed,
2114 * but doesn't have to be.
2116 * Instead of the "map" field, it's also possible to have a "url" field
2117 * specifying a URL to retrieve a source map from, but that's currently
2120 * Here's an example source map, taken from the source map spec[0], but
2121 * modified to omit a section which uses the "url" field.
2127 * offset: {line:100, column:10},
2130 * file: "section.js",
2131 * sources: ["foo.js", "bar.js"],
2132 * names: ["src", "maps", "are", "fun"],
2133 * mappings: "AAAA,E;;ABCDE;"
2138 * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
2140 function IndexedSourceMapConsumer(aSourceMap) {
2141 var sourceMap = aSourceMap;
2142 if (typeof aSourceMap === 'string') {
2143 sourceMap = JSON.parse(aSourceMap.replace(/^\)\]\}'/, ''));
2146 var version = util.getArg(sourceMap, 'version');
2147 var sections = util.getArg(sourceMap, 'sections');
2149 if (version != this._version) {
2150 throw new Error('Unsupported version: ' + version);
2153 this._sources = new ArraySet();
2154 this._names = new ArraySet();
2160 this._sections = sections.map(function (s) {
2162 // The url field will require support for asynchronicity.
2163 // See https://github.com/mozilla/source-map/issues/16
2164 throw new Error('Support for url field in sections not implemented.');
2166 var offset = util.getArg(s, 'offset');
2167 var offsetLine = util.getArg(offset, 'line');
2168 var offsetColumn = util.getArg(offset, 'column');
2170 if (offsetLine < lastOffset.line ||
2171 (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
2172 throw new Error('Section offsets must be ordered and non-overlapping.');
2174 lastOffset = offset;
2178 // The offset fields are 0-based, but we use 1-based indices when
2179 // encoding/decoding from VLQ.
2180 generatedLine: offsetLine + 1,
2181 generatedColumn: offsetColumn + 1
2183 consumer: new SourceMapConsumer(util.getArg(s, 'map'))
2188 IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer.prototype);
2189 IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer;
2192 * The version of the source mapping spec that we are consuming.
2194 IndexedSourceMapConsumer.prototype._version = 3;
2197 * The list of original sources.
2199 Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
2202 for (var i = 0; i < this._sections.length; i++) {
2203 for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
2204 sources.push(this._sections[i].consumer.sources[j]);
2212 * Returns the original source, line, and column information for the generated
2213 * source's line and column positions provided. The only argument is an object
2214 * with the following properties:
2216 * - line: The line number in the generated source.
2217 * - column: The column number in the generated source.
2219 * and an object is returned with the following properties:
2221 * - source: The original source file, or null.
2222 * - line: The line number in the original source, or null.
2223 * - column: The column number in the original source, or null.
2224 * - name: The original identifier, or null.
2226 IndexedSourceMapConsumer.prototype.originalPositionFor =
2227 function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
2229 generatedLine: util.getArg(aArgs, 'line'),
2230 generatedColumn: util.getArg(aArgs, 'column')
2233 // Find the section containing the generated position we're trying to map
2234 // to an original position.
2235 var sectionIndex = binarySearch.search(needle, this._sections,
2236 function(needle, section) {
2237 var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
2242 return (needle.generatedColumn -
2243 section.generatedOffset.generatedColumn);
2245 var section = this._sections[sectionIndex];
2256 return section.consumer.originalPositionFor({
2257 line: needle.generatedLine -
2258 (section.generatedOffset.generatedLine - 1),
2259 column: needle.generatedColumn -
2260 (section.generatedOffset.generatedLine === needle.generatedLine
2261 ? section.generatedOffset.generatedColumn - 1
2268 * Return true if we have the source content for every source in the source
2269 * map, false otherwise.
2271 IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
2272 function IndexedSourceMapConsumer_hasContentsOfAllSources() {
2273 return this._sections.every(function (s) {
2274 return s.consumer.hasContentsOfAllSources();
2279 * Returns the original source content. The only argument is the url of the
2280 * original source file. Returns null if no original source content is
2283 IndexedSourceMapConsumer.prototype.sourceContentFor =
2284 function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
2285 for (var i = 0; i < this._sections.length; i++) {
2286 var section = this._sections[i];
2288 var content = section.consumer.sourceContentFor(aSource, true);
2293 if (nullOnMissing) {
2297 throw new Error('"' + aSource + '" is not in the SourceMap.');
2302 * Returns the generated line and column information for the original source,
2303 * line, and column positions provided. The only argument is an object with
2304 * the following properties:
2306 * - source: The filename of the original source.
2307 * - line: The line number in the original source.
2308 * - column: The column number in the original source.
2310 * and an object is returned with the following properties:
2312 * - line: The line number in the generated source, or null.
2313 * - column: The column number in the generated source, or null.
2315 IndexedSourceMapConsumer.prototype.generatedPositionFor =
2316 function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
2317 for (var i = 0; i < this._sections.length; i++) {
2318 var section = this._sections[i];
2320 // Only consider this section if the requested source is in the list of
2321 // sources of the consumer.
2322 if (section.consumer.sources.indexOf(util.getArg(aArgs, 'source')) === -1) {
2325 var generatedPosition = section.consumer.generatedPositionFor(aArgs);
2326 if (generatedPosition) {
2328 line: generatedPosition.line +
2329 (section.generatedOffset.generatedLine - 1),
2330 column: generatedPosition.column +
2331 (section.generatedOffset.generatedLine === generatedPosition.line
2332 ? section.generatedOffset.generatedColumn - 1
2346 * Parse the mappings in a string in to a data structure which we can easily
2347 * query (the ordered arrays in the `this.__generatedMappings` and
2348 * `this.__originalMappings` properties).
2350 IndexedSourceMapConsumer.prototype._parseMappings =
2351 function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
2352 this.__generatedMappings = [];
2353 this.__originalMappings = [];
2354 for (var i = 0; i < this._sections.length; i++) {
2355 var section = this._sections[i];
2356 var sectionMappings = section.consumer._generatedMappings;
2357 for (var j = 0; j < sectionMappings.length; j++) {
2358 var mapping = sectionMappings[j];
2360 var source = section.consumer._sources.at(mapping.source);
2361 if (section.consumer.sourceRoot !== null) {
2362 source = util.join(section.consumer.sourceRoot, source);
2364 this._sources.add(source);
2365 source = this._sources.indexOf(source);
2367 var name = section.consumer._names.at(mapping.name);
2368 this._names.add(name);
2369 name = this._names.indexOf(name);
2371 // The mappings coming from the consumer for the section have
2372 // generated positions relative to the start of the section, so we
2373 // need to offset them to be relative to the start of the concatenated
2375 var adjustedMapping = {
2377 generatedLine: mapping.generatedLine +
2378 (section.generatedOffset.generatedLine - 1),
2379 generatedColumn: mapping.generatedColumn +
2380 (section.generatedOffset.generatedLine === mapping.generatedLine
2381 ? section.generatedOffset.generatedColumn - 1
2383 originalLine: mapping.originalLine,
2384 originalColumn: mapping.originalColumn,
2388 this.__generatedMappings.push(adjustedMapping);
2389 if (typeof adjustedMapping.originalLine === 'number') {
2390 this.__originalMappings.push(adjustedMapping);
2395 quickSort(this.__generatedMappings, util.compareByGeneratedPositionsDeflated);
2396 quickSort(this.__originalMappings, util.compareByOriginalPositions);
2399 exports.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
2404 /***/ function(module, exports) {
2406 /* -*- Mode: js; js-indent-level: 2; -*- */
2408 * Copyright 2011 Mozilla Foundation and contributors
2409 * Licensed under the New BSD license. See LICENSE or:
2410 * http://opensource.org/licenses/BSD-3-Clause
2413 exports.GREATEST_LOWER_BOUND = 1;
2414 exports.LEAST_UPPER_BOUND = 2;
2417 * Recursive implementation of binary search.
2419 * @param aLow Indices here and lower do not contain the needle.
2420 * @param aHigh Indices here and higher do not contain the needle.
2421 * @param aNeedle The element being searched for.
2422 * @param aHaystack The non-empty array being searched.
2423 * @param aCompare Function which takes two elements and returns -1, 0, or 1.
2424 * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
2425 * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
2426 * closest element that is smaller than or greater than the one we are
2427 * searching for, respectively, if the exact element cannot be found.
2429 function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
2430 // This function terminates when one of the following is true:
2432 // 1. We find the exact element we are looking for.
2434 // 2. We did not find the exact element, but we can return the index of
2435 // the next-closest element.
2437 // 3. We did not find the exact element, and there is no next-closest
2438 // element than the one we are searching for, so we return -1.
2439 var mid = Math.floor((aHigh - aLow) / 2) + aLow;
2440 var cmp = aCompare(aNeedle, aHaystack[mid], true);
2442 // Found the element we are looking for.
2446 // Our needle is greater than aHaystack[mid].
2447 if (aHigh - mid > 1) {
2448 // The element is in the upper half.
2449 return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
2452 // The exact needle element was not found in this haystack. Determine if
2453 // we are in termination case (3) or (2) and return the appropriate thing.
2454 if (aBias == exports.LEAST_UPPER_BOUND) {
2455 return aHigh < aHaystack.length ? aHigh : -1;
2461 // Our needle is less than aHaystack[mid].
2462 if (mid - aLow > 1) {
2463 // The element is in the lower half.
2464 return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
2467 // we are in termination case (3) or (2) and return the appropriate thing.
2468 if (aBias == exports.LEAST_UPPER_BOUND) {
2471 return aLow < 0 ? -1 : aLow;
2477 * This is an implementation of binary search which will always try and return
2478 * the index of the closest element if there is no exact hit. This is because
2479 * mappings between original and generated line/col pairs are single points,
2480 * and there is an implicit region between each of them, so a miss just means
2481 * that you aren't on the very start of a region.
2483 * @param aNeedle The element you are looking for.
2484 * @param aHaystack The array that is being searched.
2485 * @param aCompare A function which takes the needle and an element in the
2486 * array and returns -1, 0, or 1 depending on whether the needle is less
2487 * than, equal to, or greater than the element, respectively.
2488 * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
2489 * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
2490 * closest element that is smaller than or greater than the one we are
2491 * searching for, respectively, if the exact element cannot be found.
2492 * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
2494 exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
2495 if (aHaystack.length === 0) {
2499 var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
2500 aCompare, aBias || exports.GREATEST_LOWER_BOUND);
2505 // We have found either the exact element, or the next-closest element than
2506 // the one we are searching for. However, there may be more than one such
2507 // element. Make sure we always return the smallest of these.
2508 while (index - 1 >= 0) {
2509 if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
2521 /***/ function(module, exports) {
2523 /* -*- Mode: js; js-indent-level: 2; -*- */
2525 * Copyright 2011 Mozilla Foundation and contributors
2526 * Licensed under the New BSD license. See LICENSE or:
2527 * http://opensource.org/licenses/BSD-3-Clause
2530 // It turns out that some (most?) JavaScript engines don't self-host
2531 // `Array.prototype.sort`. This makes sense because C++ will likely remain
2532 // faster than JS when doing raw CPU-intensive sorting. However, when using a
2533 // custom comparator function, calling back and forth between the VM's C++ and
2534 // JIT'd JS is rather slow *and* loses JIT type information, resulting in
2535 // worse generated code for the comparator function than would be optimal. In
2536 // fact, when sorting with a comparator, these costs outweigh the benefits of
2537 // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
2538 // a ~3500ms mean speed-up in `bench/bench.html`.
2541 * Swap the elements indexed by `x` and `y` in the array `ary`.
2543 * @param {Array} ary
2546 * The index of the first item.
2548 * The index of the second item.
2550 function swap(ary, x, y) {
2557 * Returns a random integer within the range `low .. high` inclusive.
2559 * @param {Number} low
2560 * The lower bound on the range.
2561 * @param {Number} high
2562 * The upper bound on the range.
2564 function randomIntInRange(low, high) {
2565 return Math.round(low + (Math.random() * (high - low)));
2569 * The Quick Sort algorithm.
2571 * @param {Array} ary
2573 * @param {function} comparator
2574 * Function to use to compare two items.
2576 * Start index of the array
2578 * End index of the array
2580 function doQuickSort(ary, comparator, p, r) {
2581 // If our lower bound is less than our upper bound, we (1) partition the
2582 // array into two pieces and (2) recurse on each half. If it is not, this is
2583 // the empty array and our base case.
2586 // (1) Partitioning.
2588 // The partitioning chooses a pivot between `p` and `r` and moves all
2589 // elements that are less than or equal to the pivot to the before it, and
2590 // all the elements that are greater than it after it. The effect is that
2591 // once partition is done, the pivot is in the exact place it will be when
2592 // the array is put in sorted order, and it will not need to be moved
2593 // again. This runs in O(n) time.
2595 // Always choose a random pivot so that an input array which is reverse
2596 // sorted does not cause O(n^2) running time.
2597 var pivotIndex = randomIntInRange(p, r);
2600 swap(ary, pivotIndex, r);
2603 // Immediately after `j` is incremented in this loop, the following hold
2606 // * Every element in `ary[p .. i]` is less than or equal to the pivot.
2608 // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
2609 for (var j = p; j < r; j++) {
2610 if (comparator(ary[j], pivot) <= 0) {
2616 swap(ary, i + 1, j);
2619 // (2) Recurse on each half.
2621 doQuickSort(ary, comparator, p, q - 1);
2622 doQuickSort(ary, comparator, q + 1, r);
2627 * Sort the given array in-place with the given comparator function.
2629 * @param {Array} ary
2631 * @param {function} comparator
2632 * Function to use to compare two items.
2634 exports.quickSort = function (ary, comparator) {
2635 doQuickSort(ary, comparator, 0, ary.length - 1);
2641 /***/ function(module, exports, __webpack_require__) {
2643 /* -*- Mode: js; js-indent-level: 2; -*- */
2645 * Copyright 2011 Mozilla Foundation and contributors
2646 * Licensed under the New BSD license. See LICENSE or:
2647 * http://opensource.org/licenses/BSD-3-Clause
2650 var SourceMapGenerator = __webpack_require__(1).SourceMapGenerator;
2651 var util = __webpack_require__(4);
2653 // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
2654 // operating systems these days (capturing the result).
2655 var REGEX_NEWLINE = /(\r?\n)/;
2657 // Newline character code for charCodeAt() comparisons
2658 var NEWLINE_CODE = 10;
2660 // Private symbol for identifying `SourceNode`s when multiple versions of
2661 // the source-map library are loaded. This MUST NOT CHANGE across
2663 var isSourceNode = "$$$isSourceNode$$$";
2666 * SourceNodes provide a way to abstract over interpolating/concatenating
2667 * snippets of generated JavaScript source code while maintaining the line and
2668 * column information associated with the original source code.
2670 * @param aLine The original line number.
2671 * @param aColumn The original column number.
2672 * @param aSource The original source's filename.
2673 * @param aChunks Optional. An array of strings which are snippets of
2674 * generated JS, or other SourceNodes.
2675 * @param aName The original identifier.
2677 function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
2679 this.sourceContents = {};
2680 this.line = aLine == null ? null : aLine;
2681 this.column = aColumn == null ? null : aColumn;
2682 this.source = aSource == null ? null : aSource;
2683 this.name = aName == null ? null : aName;
2684 this[isSourceNode] = true;
2685 if (aChunks != null) this.add(aChunks);
2689 * Creates a SourceNode from generated code and a SourceMapConsumer.
2691 * @param aGeneratedCode The generated code
2692 * @param aSourceMapConsumer The SourceMap for the generated code
2693 * @param aRelativePath Optional. The path that relative sources in the
2694 * SourceMapConsumer should be relative to.
2696 SourceNode.fromStringWithSourceMap =
2697 function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
2698 // The SourceNode we want to fill with the generated code
2699 // and the SourceMap
2700 var node = new SourceNode();
2702 // All even indices of this array are one line of the generated code,
2703 // while all odd indices are the newlines between two adjacent lines
2704 // (since `REGEX_NEWLINE` captures its match).
2705 // Processed fragments are removed from this array, by calling `shiftNextLine`.
2706 var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
2707 var shiftNextLine = function() {
2708 var lineContents = remainingLines.shift();
2709 // The last line of a file might not have a newline.
2710 var newLine = remainingLines.shift() || "";
2711 return lineContents + newLine;
2714 // We need to remember the position of "remainingLines"
2715 var lastGeneratedLine = 1, lastGeneratedColumn = 0;
2717 // The generate SourceNodes we need a code range.
2718 // To extract it current and last mapping is used.
2719 // Here we store the last mapping.
2720 var lastMapping = null;
2722 aSourceMapConsumer.eachMapping(function (mapping) {
2723 if (lastMapping !== null) {
2724 // We add the code from "lastMapping" to "mapping":
2725 // First check if there is a new line in between.
2726 if (lastGeneratedLine < mapping.generatedLine) {
2727 // Associate first line with "lastMapping"
2728 addMappingWithCode(lastMapping, shiftNextLine());
2729 lastGeneratedLine++;
2730 lastGeneratedColumn = 0;
2731 // The remaining code is added without mapping
2733 // There is no new line in between.
2734 // Associate the code between "lastGeneratedColumn" and
2735 // "mapping.generatedColumn" with "lastMapping"
2736 var nextLine = remainingLines[0];
2737 var code = nextLine.substr(0, mapping.generatedColumn -
2738 lastGeneratedColumn);
2739 remainingLines[0] = nextLine.substr(mapping.generatedColumn -
2740 lastGeneratedColumn);
2741 lastGeneratedColumn = mapping.generatedColumn;
2742 addMappingWithCode(lastMapping, code);
2743 // No more remaining code, continue
2744 lastMapping = mapping;
2748 // We add the generated code until the first mapping
2749 // to the SourceNode without any mapping.
2750 // Each line is added as separate string.
2751 while (lastGeneratedLine < mapping.generatedLine) {
2752 node.add(shiftNextLine());
2753 lastGeneratedLine++;
2755 if (lastGeneratedColumn < mapping.generatedColumn) {
2756 var nextLine = remainingLines[0];
2757 node.add(nextLine.substr(0, mapping.generatedColumn));
2758 remainingLines[0] = nextLine.substr(mapping.generatedColumn);
2759 lastGeneratedColumn = mapping.generatedColumn;
2761 lastMapping = mapping;
2763 // We have processed all mappings.
2764 if (remainingLines.length > 0) {
2766 // Associate the remaining code in the current line with "lastMapping"
2767 addMappingWithCode(lastMapping, shiftNextLine());
2769 // and add the remaining lines without any mapping
2770 node.add(remainingLines.join(""));
2773 // Copy sourcesContent into SourceNode
2774 aSourceMapConsumer.sources.forEach(function (sourceFile) {
2775 var content = aSourceMapConsumer.sourceContentFor(sourceFile);
2776 if (content != null) {
2777 if (aRelativePath != null) {
2778 sourceFile = util.join(aRelativePath, sourceFile);
2780 node.setSourceContent(sourceFile, content);
2786 function addMappingWithCode(mapping, code) {
2787 if (mapping === null || mapping.source === undefined) {
2790 var source = aRelativePath
2791 ? util.join(aRelativePath, mapping.source)
2793 node.add(new SourceNode(mapping.originalLine,
2794 mapping.originalColumn,
2803 * Add a chunk of generated JS to this source node.
2805 * @param aChunk A string snippet of generated JS code, another instance of
2806 * SourceNode, or an array where each member is one of those things.
2808 SourceNode.prototype.add = function SourceNode_add(aChunk) {
2809 if (Array.isArray(aChunk)) {
2810 aChunk.forEach(function (chunk) {
2814 else if (aChunk[isSourceNode] || typeof aChunk === "string") {
2816 this.children.push(aChunk);
2820 throw new TypeError(
2821 "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
2828 * Add a chunk of generated JS to the beginning of this source node.
2830 * @param aChunk A string snippet of generated JS code, another instance of
2831 * SourceNode, or an array where each member is one of those things.
2833 SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
2834 if (Array.isArray(aChunk)) {
2835 for (var i = aChunk.length-1; i >= 0; i--) {
2836 this.prepend(aChunk[i]);
2839 else if (aChunk[isSourceNode] || typeof aChunk === "string") {
2840 this.children.unshift(aChunk);
2843 throw new TypeError(
2844 "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
2851 * Walk over the tree of JS snippets in this node and its children. The
2852 * walking function is called once for each snippet of JS and is passed that
2853 * snippet and the its original associated source's line/column location.
2855 * @param aFn The traversal function.
2857 SourceNode.prototype.walk = function SourceNode_walk(aFn) {
2859 for (var i = 0, len = this.children.length; i < len; i++) {
2860 chunk = this.children[i];
2861 if (chunk[isSourceNode]) {
2866 aFn(chunk, { source: this.source,
2868 column: this.column,
2876 * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
2877 * each of `this.children`.
2879 * @param aSep The separator.
2881 SourceNode.prototype.join = function SourceNode_join(aSep) {
2884 var len = this.children.length;
2887 for (i = 0; i < len-1; i++) {
2888 newChildren.push(this.children[i]);
2889 newChildren.push(aSep);
2891 newChildren.push(this.children[i]);
2892 this.children = newChildren;
2898 * Call String.prototype.replace on the very right-most source snippet. Useful
2899 * for trimming whitespace from the end of a source node, etc.
2901 * @param aPattern The pattern to replace.
2902 * @param aReplacement The thing to replace the pattern with.
2904 SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
2905 var lastChild = this.children[this.children.length - 1];
2906 if (lastChild[isSourceNode]) {
2907 lastChild.replaceRight(aPattern, aReplacement);
2909 else if (typeof lastChild === 'string') {
2910 this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
2913 this.children.push(''.replace(aPattern, aReplacement));
2919 * Set the source content for a source file. This will be added to the SourceMapGenerator
2920 * in the sourcesContent field.
2922 * @param aSourceFile The filename of the source file
2923 * @param aSourceContent The content of the source file
2925 SourceNode.prototype.setSourceContent =
2926 function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
2927 this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
2931 * Walk over the tree of SourceNodes. The walking function is called for each
2932 * source file content and is passed the filename and source content.
2934 * @param aFn The traversal function.
2936 SourceNode.prototype.walkSourceContents =
2937 function SourceNode_walkSourceContents(aFn) {
2938 for (var i = 0, len = this.children.length; i < len; i++) {
2939 if (this.children[i][isSourceNode]) {
2940 this.children[i].walkSourceContents(aFn);
2944 var sources = Object.keys(this.sourceContents);
2945 for (var i = 0, len = sources.length; i < len; i++) {
2946 aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
2951 * Return the string representation of this source node. Walks over the tree
2952 * and concatenates all the various snippets together to one string.
2954 SourceNode.prototype.toString = function SourceNode_toString() {
2956 this.walk(function (chunk) {
2963 * Returns the string representation of this source node along with a source
2966 SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
2972 var map = new SourceMapGenerator(aArgs);
2973 var sourceMappingActive = false;
2974 var lastOriginalSource = null;
2975 var lastOriginalLine = null;
2976 var lastOriginalColumn = null;
2977 var lastOriginalName = null;
2978 this.walk(function (chunk, original) {
2979 generated.code += chunk;
2980 if (original.source !== null
2981 && original.line !== null
2982 && original.column !== null) {
2983 if(lastOriginalSource !== original.source
2984 || lastOriginalLine !== original.line
2985 || lastOriginalColumn !== original.column
2986 || lastOriginalName !== original.name) {
2988 source: original.source,
2990 line: original.line,
2991 column: original.column
2994 line: generated.line,
2995 column: generated.column
3000 lastOriginalSource = original.source;
3001 lastOriginalLine = original.line;
3002 lastOriginalColumn = original.column;
3003 lastOriginalName = original.name;
3004 sourceMappingActive = true;
3005 } else if (sourceMappingActive) {
3008 line: generated.line,
3009 column: generated.column
3012 lastOriginalSource = null;
3013 sourceMappingActive = false;
3015 for (var idx = 0, length = chunk.length; idx < length; idx++) {
3016 if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
3018 generated.column = 0;
3019 // Mappings end at eol
3020 if (idx + 1 === length) {
3021 lastOriginalSource = null;
3022 sourceMappingActive = false;
3023 } else if (sourceMappingActive) {
3025 source: original.source,
3027 line: original.line,
3028 column: original.column
3031 line: generated.line,
3032 column: generated.column
3042 this.walkSourceContents(function (sourceFile, sourceContent) {
3043 map.setSourceContent(sourceFile, sourceContent);
3046 return { code: generated.code, map: map };
3049 exports.SourceNode = SourceNode;