source: trip-planner-front/node_modules/source-map/dist/source-map.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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