vitest 0.24.4 → 0.24.5

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