@dcloudio/uni-stacktracey 3.0.0-alpha-3050220220719002 → 3.0.0-alpha-3050320220727002

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