vitest 0.0.98 → 0.0.99

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.
@@ -0,0 +1,4739 @@
1
+ import { existsSync, promises } from 'fs';
2
+ import { format } from 'util';
3
+ import { k as notNullish, c, r as relative } from './utils-b780070b.js';
4
+
5
+ function Diff() {}
6
+ Diff.prototype = {
7
+ diff: function diff(oldString, newString) {
8
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
9
+ var callback = options.callback;
10
+
11
+ if (typeof options === 'function') {
12
+ callback = options;
13
+ options = {};
14
+ }
15
+
16
+ this.options = options;
17
+ var self = this;
18
+
19
+ function done(value) {
20
+ if (callback) {
21
+ setTimeout(function () {
22
+ callback(undefined, value);
23
+ }, 0);
24
+ return true;
25
+ } else {
26
+ return value;
27
+ }
28
+ } // Allow subclasses to massage the input prior to running
29
+
30
+
31
+ oldString = this.castInput(oldString);
32
+ newString = this.castInput(newString);
33
+ oldString = this.removeEmpty(this.tokenize(oldString));
34
+ newString = this.removeEmpty(this.tokenize(newString));
35
+ var newLen = newString.length,
36
+ oldLen = oldString.length;
37
+ var editLength = 1;
38
+ var maxEditLength = newLen + oldLen;
39
+ var bestPath = [{
40
+ newPos: -1,
41
+ components: []
42
+ }]; // Seed editLength = 0, i.e. the content starts with the same values
43
+
44
+ var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
45
+
46
+ if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
47
+ // Identity per the equality and tokenizer
48
+ return done([{
49
+ value: this.join(newString),
50
+ count: newString.length
51
+ }]);
52
+ } // Main worker method. checks all permutations of a given edit length for acceptance.
53
+
54
+
55
+ function execEditLength() {
56
+ for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
57
+ var basePath = void 0;
58
+
59
+ var addPath = bestPath[diagonalPath - 1],
60
+ removePath = bestPath[diagonalPath + 1],
61
+ _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
62
+
63
+ if (addPath) {
64
+ // No one else is going to attempt to use this value, clear it
65
+ bestPath[diagonalPath - 1] = undefined;
66
+ }
67
+
68
+ var canAdd = addPath && addPath.newPos + 1 < newLen,
69
+ canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
70
+
71
+ if (!canAdd && !canRemove) {
72
+ // If this path is a terminal then prune
73
+ bestPath[diagonalPath] = undefined;
74
+ continue;
75
+ } // Select the diagonal that we want to branch from. We select the prior
76
+ // path whose position in the new string is the farthest from the origin
77
+ // and does not pass the bounds of the diff graph
78
+
79
+
80
+ if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
81
+ basePath = clonePath(removePath);
82
+ self.pushComponent(basePath.components, undefined, true);
83
+ } else {
84
+ basePath = addPath; // No need to clone, we've pulled it from the list
85
+
86
+ basePath.newPos++;
87
+ self.pushComponent(basePath.components, true, undefined);
88
+ }
89
+
90
+ _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
91
+
92
+ if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
93
+ return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
94
+ } else {
95
+ // Otherwise track this path as a potential candidate and continue.
96
+ bestPath[diagonalPath] = basePath;
97
+ }
98
+ }
99
+
100
+ editLength++;
101
+ } // Performs the length of edit iteration. Is a bit fugly as this has to support the
102
+ // sync and async mode which is never fun. Loops over execEditLength until a value
103
+ // is produced.
104
+
105
+
106
+ if (callback) {
107
+ (function exec() {
108
+ setTimeout(function () {
109
+ // This should not happen, but we want to be safe.
110
+
111
+ /* istanbul ignore next */
112
+ if (editLength > maxEditLength) {
113
+ return callback();
114
+ }
115
+
116
+ if (!execEditLength()) {
117
+ exec();
118
+ }
119
+ }, 0);
120
+ })();
121
+ } else {
122
+ while (editLength <= maxEditLength) {
123
+ var ret = execEditLength();
124
+
125
+ if (ret) {
126
+ return ret;
127
+ }
128
+ }
129
+ }
130
+ },
131
+ pushComponent: function pushComponent(components, added, removed) {
132
+ var last = components[components.length - 1];
133
+
134
+ if (last && last.added === added && last.removed === removed) {
135
+ // We need to clone here as the component clone operation is just
136
+ // as shallow array clone
137
+ components[components.length - 1] = {
138
+ count: last.count + 1,
139
+ added: added,
140
+ removed: removed
141
+ };
142
+ } else {
143
+ components.push({
144
+ count: 1,
145
+ added: added,
146
+ removed: removed
147
+ });
148
+ }
149
+ },
150
+ extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
151
+ var newLen = newString.length,
152
+ oldLen = oldString.length,
153
+ newPos = basePath.newPos,
154
+ oldPos = newPos - diagonalPath,
155
+ commonCount = 0;
156
+
157
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
158
+ newPos++;
159
+ oldPos++;
160
+ commonCount++;
161
+ }
162
+
163
+ if (commonCount) {
164
+ basePath.components.push({
165
+ count: commonCount
166
+ });
167
+ }
168
+
169
+ basePath.newPos = newPos;
170
+ return oldPos;
171
+ },
172
+ equals: function equals(left, right) {
173
+ if (this.options.comparator) {
174
+ return this.options.comparator(left, right);
175
+ } else {
176
+ return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
177
+ }
178
+ },
179
+ removeEmpty: function removeEmpty(array) {
180
+ var ret = [];
181
+
182
+ for (var i = 0; i < array.length; i++) {
183
+ if (array[i]) {
184
+ ret.push(array[i]);
185
+ }
186
+ }
187
+
188
+ return ret;
189
+ },
190
+ castInput: function castInput(value) {
191
+ return value;
192
+ },
193
+ tokenize: function tokenize(value) {
194
+ return value.split('');
195
+ },
196
+ join: function join(chars) {
197
+ return chars.join('');
198
+ }
199
+ };
200
+
201
+ function buildValues(diff, components, newString, oldString, useLongestToken) {
202
+ var componentPos = 0,
203
+ componentLen = components.length,
204
+ newPos = 0,
205
+ oldPos = 0;
206
+
207
+ for (; componentPos < componentLen; componentPos++) {
208
+ var component = components[componentPos];
209
+
210
+ if (!component.removed) {
211
+ if (!component.added && useLongestToken) {
212
+ var value = newString.slice(newPos, newPos + component.count);
213
+ value = value.map(function (value, i) {
214
+ var oldValue = oldString[oldPos + i];
215
+ return oldValue.length > value.length ? oldValue : value;
216
+ });
217
+ component.value = diff.join(value);
218
+ } else {
219
+ component.value = diff.join(newString.slice(newPos, newPos + component.count));
220
+ }
221
+
222
+ newPos += component.count; // Common case
223
+
224
+ if (!component.added) {
225
+ oldPos += component.count;
226
+ }
227
+ } else {
228
+ component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
229
+ oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
230
+ // The diffing algorithm is tied to add then remove output and this is the simplest
231
+ // route to get the desired output with minimal overhead.
232
+
233
+ if (componentPos && components[componentPos - 1].added) {
234
+ var tmp = components[componentPos - 1];
235
+ components[componentPos - 1] = components[componentPos];
236
+ components[componentPos] = tmp;
237
+ }
238
+ }
239
+ } // Special case handle for when one terminal is ignored (i.e. whitespace).
240
+ // For this case we merge the terminal into the prior string and drop the change.
241
+ // This is only available for string mode.
242
+
243
+
244
+ var lastComponent = components[componentLen - 1];
245
+
246
+ if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
247
+ components[componentLen - 2].value += lastComponent.value;
248
+ components.pop();
249
+ }
250
+
251
+ return components;
252
+ }
253
+
254
+ function clonePath(path) {
255
+ return {
256
+ newPos: path.newPos,
257
+ components: path.components.slice(0)
258
+ };
259
+ }
260
+
261
+ //
262
+ // Ranges and exceptions:
263
+ // Latin-1 Supplement, 0080–00FF
264
+ // - U+00D7 × Multiplication sign
265
+ // - U+00F7 ÷ Division sign
266
+ // Latin Extended-A, 0100–017F
267
+ // Latin Extended-B, 0180–024F
268
+ // IPA Extensions, 0250–02AF
269
+ // Spacing Modifier Letters, 02B0–02FF
270
+ // - U+02C7 ˇ &#711; Caron
271
+ // - U+02D8 ˘ &#728; Breve
272
+ // - U+02D9 ˙ &#729; Dot Above
273
+ // - U+02DA ˚ &#730; Ring Above
274
+ // - U+02DB ˛ &#731; Ogonek
275
+ // - U+02DC ˜ &#732; Small Tilde
276
+ // - U+02DD ˝ &#733; Double Acute Accent
277
+ // Latin Extended Additional, 1E00–1EFF
278
+
279
+ var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
280
+ var reWhitespace = /\S/;
281
+ var wordDiff = new Diff();
282
+
283
+ wordDiff.equals = function (left, right) {
284
+ if (this.options.ignoreCase) {
285
+ left = left.toLowerCase();
286
+ right = right.toLowerCase();
287
+ }
288
+
289
+ return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
290
+ };
291
+
292
+ wordDiff.tokenize = function (value) {
293
+ // All whitespace symbols except newline group into one token, each newline - in separate token
294
+ var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
295
+
296
+ for (var i = 0; i < tokens.length - 1; i++) {
297
+ // If we have an empty string in the next field and we have only word chars before and after, merge
298
+ if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
299
+ tokens[i] += tokens[i + 2];
300
+ tokens.splice(i + 1, 2);
301
+ i--;
302
+ }
303
+ }
304
+
305
+ return tokens;
306
+ };
307
+
308
+ var lineDiff = new Diff();
309
+
310
+ lineDiff.tokenize = function (value) {
311
+ var retLines = [],
312
+ linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
313
+
314
+ if (!linesAndNewlines[linesAndNewlines.length - 1]) {
315
+ linesAndNewlines.pop();
316
+ } // Merge the content and line separators into single tokens
317
+
318
+
319
+ for (var i = 0; i < linesAndNewlines.length; i++) {
320
+ var line = linesAndNewlines[i];
321
+
322
+ if (i % 2 && !this.options.newlineIsToken) {
323
+ retLines[retLines.length - 1] += line;
324
+ } else {
325
+ if (this.options.ignoreWhitespace) {
326
+ line = line.trim();
327
+ }
328
+
329
+ retLines.push(line);
330
+ }
331
+ }
332
+
333
+ return retLines;
334
+ };
335
+
336
+ function diffLines(oldStr, newStr, callback) {
337
+ return lineDiff.diff(oldStr, newStr, callback);
338
+ }
339
+
340
+ var sentenceDiff = new Diff();
341
+
342
+ sentenceDiff.tokenize = function (value) {
343
+ return value.split(/(\S.+?[.!?])(?=\s+|$)/);
344
+ };
345
+
346
+ var cssDiff = new Diff();
347
+
348
+ cssDiff.tokenize = function (value) {
349
+ return value.split(/([{}:;,]|\s+)/);
350
+ };
351
+
352
+ function _typeof(obj) {
353
+ "@babel/helpers - typeof";
354
+
355
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
356
+ _typeof = function (obj) {
357
+ return typeof obj;
358
+ };
359
+ } else {
360
+ _typeof = function (obj) {
361
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
362
+ };
363
+ }
364
+
365
+ return _typeof(obj);
366
+ }
367
+
368
+ function _toConsumableArray(arr) {
369
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
370
+ }
371
+
372
+ function _arrayWithoutHoles(arr) {
373
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
374
+ }
375
+
376
+ function _iterableToArray(iter) {
377
+ if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
378
+ }
379
+
380
+ function _unsupportedIterableToArray(o, minLen) {
381
+ if (!o) return;
382
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
383
+ var n = Object.prototype.toString.call(o).slice(8, -1);
384
+ if (n === "Object" && o.constructor) n = o.constructor.name;
385
+ if (n === "Map" || n === "Set") return Array.from(o);
386
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
387
+ }
388
+
389
+ function _arrayLikeToArray(arr, len) {
390
+ if (len == null || len > arr.length) len = arr.length;
391
+
392
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
393
+
394
+ return arr2;
395
+ }
396
+
397
+ function _nonIterableSpread() {
398
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
399
+ }
400
+
401
+ var objectPrototypeToString = Object.prototype.toString;
402
+ var jsonDiff = new Diff(); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
403
+ // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
404
+
405
+ jsonDiff.useLongestToken = true;
406
+ jsonDiff.tokenize = lineDiff.tokenize;
407
+
408
+ jsonDiff.castInput = function (value) {
409
+ var _this$options = this.options,
410
+ undefinedReplacement = _this$options.undefinedReplacement,
411
+ _this$options$stringi = _this$options.stringifyReplacer,
412
+ stringifyReplacer = _this$options$stringi === void 0 ? function (k, v) {
413
+ return typeof v === 'undefined' ? undefinedReplacement : v;
414
+ } : _this$options$stringi;
415
+ return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
416
+ };
417
+
418
+ jsonDiff.equals = function (left, right) {
419
+ return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'));
420
+ };
421
+ // object that is already on the "stack" of items being processed. Accepts an optional replacer
422
+
423
+ function canonicalize(obj, stack, replacementStack, replacer, key) {
424
+ stack = stack || [];
425
+ replacementStack = replacementStack || [];
426
+
427
+ if (replacer) {
428
+ obj = replacer(key, obj);
429
+ }
430
+
431
+ var i;
432
+
433
+ for (i = 0; i < stack.length; i += 1) {
434
+ if (stack[i] === obj) {
435
+ return replacementStack[i];
436
+ }
437
+ }
438
+
439
+ var canonicalizedObj;
440
+
441
+ if ('[object Array]' === objectPrototypeToString.call(obj)) {
442
+ stack.push(obj);
443
+ canonicalizedObj = new Array(obj.length);
444
+ replacementStack.push(canonicalizedObj);
445
+
446
+ for (i = 0; i < obj.length; i += 1) {
447
+ canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
448
+ }
449
+
450
+ stack.pop();
451
+ replacementStack.pop();
452
+ return canonicalizedObj;
453
+ }
454
+
455
+ if (obj && obj.toJSON) {
456
+ obj = obj.toJSON();
457
+ }
458
+
459
+ if (_typeof(obj) === 'object' && obj !== null) {
460
+ stack.push(obj);
461
+ canonicalizedObj = {};
462
+ replacementStack.push(canonicalizedObj);
463
+
464
+ var sortedKeys = [],
465
+ _key;
466
+
467
+ for (_key in obj) {
468
+ /* istanbul ignore else */
469
+ if (obj.hasOwnProperty(_key)) {
470
+ sortedKeys.push(_key);
471
+ }
472
+ }
473
+
474
+ sortedKeys.sort();
475
+
476
+ for (i = 0; i < sortedKeys.length; i += 1) {
477
+ _key = sortedKeys[i];
478
+ canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
479
+ }
480
+
481
+ stack.pop();
482
+ replacementStack.pop();
483
+ } else {
484
+ canonicalizedObj = obj;
485
+ }
486
+
487
+ return canonicalizedObj;
488
+ }
489
+
490
+ var arrayDiff = new Diff();
491
+
492
+ arrayDiff.tokenize = function (value) {
493
+ return value.slice();
494
+ };
495
+
496
+ arrayDiff.join = arrayDiff.removeEmpty = function (value) {
497
+ return value;
498
+ };
499
+
500
+ function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
501
+ if (!options) {
502
+ options = {};
503
+ }
504
+
505
+ if (typeof options.context === 'undefined') {
506
+ options.context = 4;
507
+ }
508
+
509
+ var diff = diffLines(oldStr, newStr, options);
510
+ diff.push({
511
+ value: '',
512
+ lines: []
513
+ }); // Append an empty value to make cleanup easier
514
+
515
+ function contextLines(lines) {
516
+ return lines.map(function (entry) {
517
+ return ' ' + entry;
518
+ });
519
+ }
520
+
521
+ var hunks = [];
522
+ var oldRangeStart = 0,
523
+ newRangeStart = 0,
524
+ curRange = [],
525
+ oldLine = 1,
526
+ newLine = 1;
527
+
528
+ var _loop = function _loop(i) {
529
+ var current = diff[i],
530
+ lines = current.lines || current.value.replace(/\n$/, '').split('\n');
531
+ current.lines = lines;
532
+
533
+ if (current.added || current.removed) {
534
+ var _curRange;
535
+
536
+ // If we have previous context, start with that
537
+ if (!oldRangeStart) {
538
+ var prev = diff[i - 1];
539
+ oldRangeStart = oldLine;
540
+ newRangeStart = newLine;
541
+
542
+ if (prev) {
543
+ curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
544
+ oldRangeStart -= curRange.length;
545
+ newRangeStart -= curRange.length;
546
+ }
547
+ } // Output our changes
548
+
549
+
550
+ (_curRange = curRange).push.apply(_curRange, _toConsumableArray(lines.map(function (entry) {
551
+ return (current.added ? '+' : '-') + entry;
552
+ }))); // Track the updated file position
553
+
554
+
555
+ if (current.added) {
556
+ newLine += lines.length;
557
+ } else {
558
+ oldLine += lines.length;
559
+ }
560
+ } else {
561
+ // Identical context lines. Track line changes
562
+ if (oldRangeStart) {
563
+ // Close out any changes that have been output (or join overlapping)
564
+ if (lines.length <= options.context * 2 && i < diff.length - 2) {
565
+ var _curRange2;
566
+
567
+ // Overlapping
568
+ (_curRange2 = curRange).push.apply(_curRange2, _toConsumableArray(contextLines(lines)));
569
+ } else {
570
+ var _curRange3;
571
+
572
+ // end the range and output
573
+ var contextSize = Math.min(lines.length, options.context);
574
+
575
+ (_curRange3 = curRange).push.apply(_curRange3, _toConsumableArray(contextLines(lines.slice(0, contextSize))));
576
+
577
+ var hunk = {
578
+ oldStart: oldRangeStart,
579
+ oldLines: oldLine - oldRangeStart + contextSize,
580
+ newStart: newRangeStart,
581
+ newLines: newLine - newRangeStart + contextSize,
582
+ lines: curRange
583
+ };
584
+
585
+ if (i >= diff.length - 2 && lines.length <= options.context) {
586
+ // EOF is inside this hunk
587
+ var oldEOFNewline = /\n$/.test(oldStr);
588
+ var newEOFNewline = /\n$/.test(newStr);
589
+ var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
590
+
591
+ if (!oldEOFNewline && noNlBeforeAdds && oldStr.length > 0) {
592
+ // special case: old has no eol and no trailing context; no-nl can end up before adds
593
+ // however, if the old file is empty, do not output the no-nl line
594
+ curRange.splice(hunk.oldLines, 0, '\');
595
+ }
596
+
597
+ if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
598
+ curRange.push('\');
599
+ }
600
+ }
601
+
602
+ hunks.push(hunk);
603
+ oldRangeStart = 0;
604
+ newRangeStart = 0;
605
+ curRange = [];
606
+ }
607
+ }
608
+
609
+ oldLine += lines.length;
610
+ newLine += lines.length;
611
+ }
612
+ };
613
+
614
+ for (var i = 0; i < diff.length; i++) {
615
+ _loop(i);
616
+ }
617
+
618
+ return {
619
+ oldFileName: oldFileName,
620
+ newFileName: newFileName,
621
+ oldHeader: oldHeader,
622
+ newHeader: newHeader,
623
+ hunks: hunks
624
+ };
625
+ }
626
+ function formatPatch(diff) {
627
+ var ret = [];
628
+
629
+ if (diff.oldFileName == diff.newFileName) {
630
+ ret.push('Index: ' + diff.oldFileName);
631
+ }
632
+
633
+ ret.push('===================================================================');
634
+ ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
635
+ ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
636
+
637
+ for (var i = 0; i < diff.hunks.length; i++) {
638
+ var hunk = diff.hunks[i]; // Unified Diff Format quirk: If the chunk size is 0,
639
+ // the first number is one lower than one would expect.
640
+ // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
641
+
642
+ if (hunk.oldLines === 0) {
643
+ hunk.oldStart -= 1;
644
+ }
645
+
646
+ if (hunk.newLines === 0) {
647
+ hunk.newStart -= 1;
648
+ }
649
+
650
+ ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
651
+ ret.push.apply(ret, hunk.lines);
652
+ }
653
+
654
+ return ret.join('\n') + '\n';
655
+ }
656
+ function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
657
+ return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
658
+ }
659
+ function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
660
+ return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
661
+ }
662
+
663
+ var sourceMapGenerator = {};
664
+
665
+ var base64Vlq = {};
666
+
667
+ var base64$1 = {};
668
+
669
+ /* -*- Mode: js; js-indent-level: 2; -*- */
670
+
671
+ /*
672
+ * Copyright 2011 Mozilla Foundation and contributors
673
+ * Licensed under the New BSD license. See LICENSE or:
674
+ * http://opensource.org/licenses/BSD-3-Clause
675
+ */
676
+
677
+ var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
678
+
679
+ /**
680
+ * Encode an integer in the range of 0 to 63 to a single base 64 digit.
681
+ */
682
+ base64$1.encode = function (number) {
683
+ if (0 <= number && number < intToCharMap.length) {
684
+ return intToCharMap[number];
685
+ }
686
+ throw new TypeError("Must be between 0 and 63: " + number);
687
+ };
688
+
689
+ /**
690
+ * Decode a single base 64 character code digit to an integer. Returns -1 on
691
+ * failure.
692
+ */
693
+ base64$1.decode = function (charCode) {
694
+ var bigA = 65; // 'A'
695
+ var bigZ = 90; // 'Z'
696
+
697
+ var littleA = 97; // 'a'
698
+ var littleZ = 122; // 'z'
699
+
700
+ var zero = 48; // '0'
701
+ var nine = 57; // '9'
702
+
703
+ var plus = 43; // '+'
704
+ var slash = 47; // '/'
705
+
706
+ var littleOffset = 26;
707
+ var numberOffset = 52;
708
+
709
+ // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
710
+ if (bigA <= charCode && charCode <= bigZ) {
711
+ return (charCode - bigA);
712
+ }
713
+
714
+ // 26 - 51: abcdefghijklmnopqrstuvwxyz
715
+ if (littleA <= charCode && charCode <= littleZ) {
716
+ return (charCode - littleA + littleOffset);
717
+ }
718
+
719
+ // 52 - 61: 0123456789
720
+ if (zero <= charCode && charCode <= nine) {
721
+ return (charCode - zero + numberOffset);
722
+ }
723
+
724
+ // 62: +
725
+ if (charCode == plus) {
726
+ return 62;
727
+ }
728
+
729
+ // 63: /
730
+ if (charCode == slash) {
731
+ return 63;
732
+ }
733
+
734
+ // Invalid base64 digit.
735
+ return -1;
736
+ };
737
+
738
+ /* -*- Mode: js; js-indent-level: 2; -*- */
739
+
740
+ /*
741
+ * Copyright 2011 Mozilla Foundation and contributors
742
+ * Licensed under the New BSD license. See LICENSE or:
743
+ * http://opensource.org/licenses/BSD-3-Clause
744
+ *
745
+ * Based on the Base 64 VLQ implementation in Closure Compiler:
746
+ * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
747
+ *
748
+ * Copyright 2011 The Closure Compiler Authors. All rights reserved.
749
+ * Redistribution and use in source and binary forms, with or without
750
+ * modification, are permitted provided that the following conditions are
751
+ * met:
752
+ *
753
+ * * Redistributions of source code must retain the above copyright
754
+ * notice, this list of conditions and the following disclaimer.
755
+ * * Redistributions in binary form must reproduce the above
756
+ * copyright notice, this list of conditions and the following
757
+ * disclaimer in the documentation and/or other materials provided
758
+ * with the distribution.
759
+ * * Neither the name of Google Inc. nor the names of its
760
+ * contributors may be used to endorse or promote products derived
761
+ * from this software without specific prior written permission.
762
+ *
763
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
764
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
765
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
766
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
767
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
768
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
769
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
770
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
771
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
772
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
773
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
774
+ */
775
+
776
+ var base64 = base64$1;
777
+
778
+ // A single base 64 digit can contain 6 bits of data. For the base 64 variable
779
+ // length quantities we use in the source map spec, the first bit is the sign,
780
+ // the next four bits are the actual value, and the 6th bit is the
781
+ // continuation bit. The continuation bit tells us whether there are more
782
+ // digits in this value following this digit.
783
+ //
784
+ // Continuation
785
+ // | Sign
786
+ // | |
787
+ // V V
788
+ // 101011
789
+
790
+ var VLQ_BASE_SHIFT = 5;
791
+
792
+ // binary: 100000
793
+ var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
794
+
795
+ // binary: 011111
796
+ var VLQ_BASE_MASK = VLQ_BASE - 1;
797
+
798
+ // binary: 100000
799
+ var VLQ_CONTINUATION_BIT = VLQ_BASE;
800
+
801
+ /**
802
+ * Converts from a two-complement value to a value where the sign bit is
803
+ * placed in the least significant bit. For example, as decimals:
804
+ * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
805
+ * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
806
+ */
807
+ function toVLQSigned(aValue) {
808
+ return aValue < 0
809
+ ? ((-aValue) << 1) + 1
810
+ : (aValue << 1) + 0;
811
+ }
812
+
813
+ /**
814
+ * Converts to a two-complement value from a value where the sign bit is
815
+ * placed in the least significant bit. For example, as decimals:
816
+ * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
817
+ * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
818
+ */
819
+ function fromVLQSigned(aValue) {
820
+ var isNegative = (aValue & 1) === 1;
821
+ var shifted = aValue >> 1;
822
+ return isNegative
823
+ ? -shifted
824
+ : shifted;
825
+ }
826
+
827
+ /**
828
+ * Returns the base 64 VLQ encoded value.
829
+ */
830
+ base64Vlq.encode = function base64VLQ_encode(aValue) {
831
+ var encoded = "";
832
+ var digit;
833
+
834
+ var vlq = toVLQSigned(aValue);
835
+
836
+ do {
837
+ digit = vlq & VLQ_BASE_MASK;
838
+ vlq >>>= VLQ_BASE_SHIFT;
839
+ if (vlq > 0) {
840
+ // There are still more digits in this value, so we must make sure the
841
+ // continuation bit is marked.
842
+ digit |= VLQ_CONTINUATION_BIT;
843
+ }
844
+ encoded += base64.encode(digit);
845
+ } while (vlq > 0);
846
+
847
+ return encoded;
848
+ };
849
+
850
+ /**
851
+ * Decodes the next base 64 VLQ value from the given string and returns the
852
+ * value and the rest of the string via the out parameter.
853
+ */
854
+ base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
855
+ var strLen = aStr.length;
856
+ var result = 0;
857
+ var shift = 0;
858
+ var continuation, digit;
859
+
860
+ do {
861
+ if (aIndex >= strLen) {
862
+ throw new Error("Expected more digits in base 64 VLQ value.");
863
+ }
864
+
865
+ digit = base64.decode(aStr.charCodeAt(aIndex++));
866
+ if (digit === -1) {
867
+ throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
868
+ }
869
+
870
+ continuation = !!(digit & VLQ_CONTINUATION_BIT);
871
+ digit &= VLQ_BASE_MASK;
872
+ result = result + (digit << shift);
873
+ shift += VLQ_BASE_SHIFT;
874
+ } while (continuation);
875
+
876
+ aOutParam.value = fromVLQSigned(result);
877
+ aOutParam.rest = aIndex;
878
+ };
879
+
880
+ var util$5 = {};
881
+
882
+ /* -*- Mode: js; js-indent-level: 2; -*- */
883
+
884
+ (function (exports) {
885
+ /*
886
+ * Copyright 2011 Mozilla Foundation and contributors
887
+ * Licensed under the New BSD license. See LICENSE or:
888
+ * http://opensource.org/licenses/BSD-3-Clause
889
+ */
890
+
891
+ /**
892
+ * This is a helper function for getting values from parameter/options
893
+ * objects.
894
+ *
895
+ * @param args The object we are extracting values from
896
+ * @param name The name of the property we are getting.
897
+ * @param defaultValue An optional value to return if the property is missing
898
+ * from the object. If this is not specified and the property is missing, an
899
+ * error will be thrown.
900
+ */
901
+ function getArg(aArgs, aName, aDefaultValue) {
902
+ if (aName in aArgs) {
903
+ return aArgs[aName];
904
+ } else if (arguments.length === 3) {
905
+ return aDefaultValue;
906
+ } else {
907
+ throw new Error('"' + aName + '" is a required argument.');
908
+ }
909
+ }
910
+ exports.getArg = getArg;
911
+
912
+ var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
913
+ var dataUrlRegexp = /^data:.+\,.+$/;
914
+
915
+ function urlParse(aUrl) {
916
+ var match = aUrl.match(urlRegexp);
917
+ if (!match) {
918
+ return null;
919
+ }
920
+ return {
921
+ scheme: match[1],
922
+ auth: match[2],
923
+ host: match[3],
924
+ port: match[4],
925
+ path: match[5]
926
+ };
927
+ }
928
+ exports.urlParse = urlParse;
929
+
930
+ function urlGenerate(aParsedUrl) {
931
+ var url = '';
932
+ if (aParsedUrl.scheme) {
933
+ url += aParsedUrl.scheme + ':';
934
+ }
935
+ url += '//';
936
+ if (aParsedUrl.auth) {
937
+ url += aParsedUrl.auth + '@';
938
+ }
939
+ if (aParsedUrl.host) {
940
+ url += aParsedUrl.host;
941
+ }
942
+ if (aParsedUrl.port) {
943
+ url += ":" + aParsedUrl.port;
944
+ }
945
+ if (aParsedUrl.path) {
946
+ url += aParsedUrl.path;
947
+ }
948
+ return url;
949
+ }
950
+ exports.urlGenerate = urlGenerate;
951
+
952
+ var MAX_CACHED_INPUTS = 32;
953
+
954
+ /**
955
+ * Takes some function `f(input) -> result` and returns a memoized version of
956
+ * `f`.
957
+ *
958
+ * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
959
+ * memoization is a dumb-simple, linear least-recently-used cache.
960
+ */
961
+ function lruMemoize(f) {
962
+ var cache = [];
963
+
964
+ return function(input) {
965
+ for (var i = 0; i < cache.length; i++) {
966
+ if (cache[i].input === input) {
967
+ var temp = cache[0];
968
+ cache[0] = cache[i];
969
+ cache[i] = temp;
970
+ return cache[0].result;
971
+ }
972
+ }
973
+
974
+ var result = f(input);
975
+
976
+ cache.unshift({
977
+ input,
978
+ result,
979
+ });
980
+
981
+ if (cache.length > MAX_CACHED_INPUTS) {
982
+ cache.pop();
983
+ }
984
+
985
+ return result;
986
+ };
987
+ }
988
+
989
+ /**
990
+ * Normalizes a path, or the path portion of a URL:
991
+ *
992
+ * - Replaces consecutive slashes with one slash.
993
+ * - Removes unnecessary '.' parts.
994
+ * - Removes unnecessary '<dir>/..' parts.
995
+ *
996
+ * Based on code in the Node.js 'path' core module.
997
+ *
998
+ * @param aPath The path or url to normalize.
999
+ */
1000
+ var normalize = lruMemoize(function normalize(aPath) {
1001
+ var path = aPath;
1002
+ var url = urlParse(aPath);
1003
+ if (url) {
1004
+ if (!url.path) {
1005
+ return aPath;
1006
+ }
1007
+ path = url.path;
1008
+ }
1009
+ var isAbsolute = exports.isAbsolute(path);
1010
+ // Split the path into parts between `/` characters. This is much faster than
1011
+ // using `.split(/\/+/g)`.
1012
+ var parts = [];
1013
+ var start = 0;
1014
+ var i = 0;
1015
+ while (true) {
1016
+ start = i;
1017
+ i = path.indexOf("/", start);
1018
+ if (i === -1) {
1019
+ parts.push(path.slice(start));
1020
+ break;
1021
+ } else {
1022
+ parts.push(path.slice(start, i));
1023
+ while (i < path.length && path[i] === "/") {
1024
+ i++;
1025
+ }
1026
+ }
1027
+ }
1028
+
1029
+ for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
1030
+ part = parts[i];
1031
+ if (part === '.') {
1032
+ parts.splice(i, 1);
1033
+ } else if (part === '..') {
1034
+ up++;
1035
+ } else if (up > 0) {
1036
+ if (part === '') {
1037
+ // The first part is blank if the path is absolute. Trying to go
1038
+ // above the root is a no-op. Therefore we can remove all '..' parts
1039
+ // directly after the root.
1040
+ parts.splice(i + 1, up);
1041
+ up = 0;
1042
+ } else {
1043
+ parts.splice(i, 2);
1044
+ up--;
1045
+ }
1046
+ }
1047
+ }
1048
+ path = parts.join('/');
1049
+
1050
+ if (path === '') {
1051
+ path = isAbsolute ? '/' : '.';
1052
+ }
1053
+
1054
+ if (url) {
1055
+ url.path = path;
1056
+ return urlGenerate(url);
1057
+ }
1058
+ return path;
1059
+ });
1060
+ exports.normalize = normalize;
1061
+
1062
+ /**
1063
+ * Joins two paths/URLs.
1064
+ *
1065
+ * @param aRoot The root path or URL.
1066
+ * @param aPath The path or URL to be joined with the root.
1067
+ *
1068
+ * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
1069
+ * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
1070
+ * first.
1071
+ * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
1072
+ * is updated with the result and aRoot is returned. Otherwise the result
1073
+ * is returned.
1074
+ * - If aPath is absolute, the result is aPath.
1075
+ * - Otherwise the two paths are joined with a slash.
1076
+ * - Joining for example 'http://' and 'www.example.com' is also supported.
1077
+ */
1078
+ function join(aRoot, aPath) {
1079
+ if (aRoot === "") {
1080
+ aRoot = ".";
1081
+ }
1082
+ if (aPath === "") {
1083
+ aPath = ".";
1084
+ }
1085
+ var aPathUrl = urlParse(aPath);
1086
+ var aRootUrl = urlParse(aRoot);
1087
+ if (aRootUrl) {
1088
+ aRoot = aRootUrl.path || '/';
1089
+ }
1090
+
1091
+ // `join(foo, '//www.example.org')`
1092
+ if (aPathUrl && !aPathUrl.scheme) {
1093
+ if (aRootUrl) {
1094
+ aPathUrl.scheme = aRootUrl.scheme;
1095
+ }
1096
+ return urlGenerate(aPathUrl);
1097
+ }
1098
+
1099
+ if (aPathUrl || aPath.match(dataUrlRegexp)) {
1100
+ return aPath;
1101
+ }
1102
+
1103
+ // `join('http://', 'www.example.com')`
1104
+ if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
1105
+ aRootUrl.host = aPath;
1106
+ return urlGenerate(aRootUrl);
1107
+ }
1108
+
1109
+ var joined = aPath.charAt(0) === '/'
1110
+ ? aPath
1111
+ : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
1112
+
1113
+ if (aRootUrl) {
1114
+ aRootUrl.path = joined;
1115
+ return urlGenerate(aRootUrl);
1116
+ }
1117
+ return joined;
1118
+ }
1119
+ exports.join = join;
1120
+
1121
+ exports.isAbsolute = function (aPath) {
1122
+ return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
1123
+ };
1124
+
1125
+ /**
1126
+ * Make a path relative to a URL or another path.
1127
+ *
1128
+ * @param aRoot The root path or URL.
1129
+ * @param aPath The path or URL to be made relative to aRoot.
1130
+ */
1131
+ function relative(aRoot, aPath) {
1132
+ if (aRoot === "") {
1133
+ aRoot = ".";
1134
+ }
1135
+
1136
+ aRoot = aRoot.replace(/\/$/, '');
1137
+
1138
+ // It is possible for the path to be above the root. In this case, simply
1139
+ // checking whether the root is a prefix of the path won't work. Instead, we
1140
+ // need to remove components from the root one by one, until either we find
1141
+ // a prefix that fits, or we run out of components to remove.
1142
+ var level = 0;
1143
+ while (aPath.indexOf(aRoot + '/') !== 0) {
1144
+ var index = aRoot.lastIndexOf("/");
1145
+ if (index < 0) {
1146
+ return aPath;
1147
+ }
1148
+
1149
+ // If the only part of the root that is left is the scheme (i.e. http://,
1150
+ // file:///, etc.), one or more slashes (/), or simply nothing at all, we
1151
+ // have exhausted all components, so the path is not relative to the root.
1152
+ aRoot = aRoot.slice(0, index);
1153
+ if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
1154
+ return aPath;
1155
+ }
1156
+
1157
+ ++level;
1158
+ }
1159
+
1160
+ // Make sure we add a "../" for each component we removed from the root.
1161
+ return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
1162
+ }
1163
+ exports.relative = relative;
1164
+
1165
+ var supportsNullProto = (function () {
1166
+ var obj = Object.create(null);
1167
+ return !('__proto__' in obj);
1168
+ }());
1169
+
1170
+ function identity (s) {
1171
+ return s;
1172
+ }
1173
+
1174
+ /**
1175
+ * Because behavior goes wacky when you set `__proto__` on objects, we
1176
+ * have to prefix all the strings in our set with an arbitrary character.
1177
+ *
1178
+ * See https://github.com/mozilla/source-map/pull/31 and
1179
+ * https://github.com/mozilla/source-map/issues/30
1180
+ *
1181
+ * @param String aStr
1182
+ */
1183
+ function toSetString(aStr) {
1184
+ if (isProtoString(aStr)) {
1185
+ return '$' + aStr;
1186
+ }
1187
+
1188
+ return aStr;
1189
+ }
1190
+ exports.toSetString = supportsNullProto ? identity : toSetString;
1191
+
1192
+ function fromSetString(aStr) {
1193
+ if (isProtoString(aStr)) {
1194
+ return aStr.slice(1);
1195
+ }
1196
+
1197
+ return aStr;
1198
+ }
1199
+ exports.fromSetString = supportsNullProto ? identity : fromSetString;
1200
+
1201
+ function isProtoString(s) {
1202
+ if (!s) {
1203
+ return false;
1204
+ }
1205
+
1206
+ var length = s.length;
1207
+
1208
+ if (length < 9 /* "__proto__".length */) {
1209
+ return false;
1210
+ }
1211
+
1212
+ if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
1213
+ s.charCodeAt(length - 2) !== 95 /* '_' */ ||
1214
+ s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
1215
+ s.charCodeAt(length - 4) !== 116 /* 't' */ ||
1216
+ s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
1217
+ s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
1218
+ s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
1219
+ s.charCodeAt(length - 8) !== 95 /* '_' */ ||
1220
+ s.charCodeAt(length - 9) !== 95 /* '_' */) {
1221
+ return false;
1222
+ }
1223
+
1224
+ for (var i = length - 10; i >= 0; i--) {
1225
+ if (s.charCodeAt(i) !== 36 /* '$' */) {
1226
+ return false;
1227
+ }
1228
+ }
1229
+
1230
+ return true;
1231
+ }
1232
+
1233
+ /**
1234
+ * Comparator between two mappings where the original positions are compared.
1235
+ *
1236
+ * Optionally pass in `true` as `onlyCompareGenerated` to consider two
1237
+ * mappings with the same original source/line/column, but different generated
1238
+ * line and column the same. Useful when searching for a mapping with a
1239
+ * stubbed out mapping.
1240
+ */
1241
+ function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
1242
+ var cmp = strcmp(mappingA.source, mappingB.source);
1243
+ if (cmp !== 0) {
1244
+ return cmp;
1245
+ }
1246
+
1247
+ cmp = mappingA.originalLine - mappingB.originalLine;
1248
+ if (cmp !== 0) {
1249
+ return cmp;
1250
+ }
1251
+
1252
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
1253
+ if (cmp !== 0 || onlyCompareOriginal) {
1254
+ return cmp;
1255
+ }
1256
+
1257
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1258
+ if (cmp !== 0) {
1259
+ return cmp;
1260
+ }
1261
+
1262
+ cmp = mappingA.generatedLine - mappingB.generatedLine;
1263
+ if (cmp !== 0) {
1264
+ return cmp;
1265
+ }
1266
+
1267
+ return strcmp(mappingA.name, mappingB.name);
1268
+ }
1269
+ exports.compareByOriginalPositions = compareByOriginalPositions;
1270
+
1271
+ function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) {
1272
+ var cmp;
1273
+
1274
+ cmp = mappingA.originalLine - mappingB.originalLine;
1275
+ if (cmp !== 0) {
1276
+ return cmp;
1277
+ }
1278
+
1279
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
1280
+ if (cmp !== 0 || onlyCompareOriginal) {
1281
+ return cmp;
1282
+ }
1283
+
1284
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1285
+ if (cmp !== 0) {
1286
+ return cmp;
1287
+ }
1288
+
1289
+ cmp = mappingA.generatedLine - mappingB.generatedLine;
1290
+ if (cmp !== 0) {
1291
+ return cmp;
1292
+ }
1293
+
1294
+ return strcmp(mappingA.name, mappingB.name);
1295
+ }
1296
+ exports.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource;
1297
+
1298
+ /**
1299
+ * Comparator between two mappings with deflated source and name indices where
1300
+ * the generated positions are compared.
1301
+ *
1302
+ * Optionally pass in `true` as `onlyCompareGenerated` to consider two
1303
+ * mappings with the same generated line and column, but different
1304
+ * source/name/original line and column the same. Useful when searching for a
1305
+ * mapping with a stubbed out mapping.
1306
+ */
1307
+ function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
1308
+ var cmp = mappingA.generatedLine - mappingB.generatedLine;
1309
+ if (cmp !== 0) {
1310
+ return cmp;
1311
+ }
1312
+
1313
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1314
+ if (cmp !== 0 || onlyCompareGenerated) {
1315
+ return cmp;
1316
+ }
1317
+
1318
+ cmp = strcmp(mappingA.source, mappingB.source);
1319
+ if (cmp !== 0) {
1320
+ return cmp;
1321
+ }
1322
+
1323
+ cmp = mappingA.originalLine - mappingB.originalLine;
1324
+ if (cmp !== 0) {
1325
+ return cmp;
1326
+ }
1327
+
1328
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
1329
+ if (cmp !== 0) {
1330
+ return cmp;
1331
+ }
1332
+
1333
+ return strcmp(mappingA.name, mappingB.name);
1334
+ }
1335
+ exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
1336
+
1337
+ function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) {
1338
+ var cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1339
+ if (cmp !== 0 || onlyCompareGenerated) {
1340
+ return cmp;
1341
+ }
1342
+
1343
+ cmp = strcmp(mappingA.source, mappingB.source);
1344
+ if (cmp !== 0) {
1345
+ return cmp;
1346
+ }
1347
+
1348
+ cmp = mappingA.originalLine - mappingB.originalLine;
1349
+ if (cmp !== 0) {
1350
+ return cmp;
1351
+ }
1352
+
1353
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
1354
+ if (cmp !== 0) {
1355
+ return cmp;
1356
+ }
1357
+
1358
+ return strcmp(mappingA.name, mappingB.name);
1359
+ }
1360
+ exports.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine;
1361
+
1362
+ function strcmp(aStr1, aStr2) {
1363
+ if (aStr1 === aStr2) {
1364
+ return 0;
1365
+ }
1366
+
1367
+ if (aStr1 === null) {
1368
+ return 1; // aStr2 !== null
1369
+ }
1370
+
1371
+ if (aStr2 === null) {
1372
+ return -1; // aStr1 !== null
1373
+ }
1374
+
1375
+ if (aStr1 > aStr2) {
1376
+ return 1;
1377
+ }
1378
+
1379
+ return -1;
1380
+ }
1381
+
1382
+ /**
1383
+ * Comparator between two mappings with inflated source and name strings where
1384
+ * the generated positions are compared.
1385
+ */
1386
+ function compareByGeneratedPositionsInflated(mappingA, mappingB) {
1387
+ var cmp = mappingA.generatedLine - mappingB.generatedLine;
1388
+ if (cmp !== 0) {
1389
+ return cmp;
1390
+ }
1391
+
1392
+ cmp = mappingA.generatedColumn - mappingB.generatedColumn;
1393
+ if (cmp !== 0) {
1394
+ return cmp;
1395
+ }
1396
+
1397
+ cmp = strcmp(mappingA.source, mappingB.source);
1398
+ if (cmp !== 0) {
1399
+ return cmp;
1400
+ }
1401
+
1402
+ cmp = mappingA.originalLine - mappingB.originalLine;
1403
+ if (cmp !== 0) {
1404
+ return cmp;
1405
+ }
1406
+
1407
+ cmp = mappingA.originalColumn - mappingB.originalColumn;
1408
+ if (cmp !== 0) {
1409
+ return cmp;
1410
+ }
1411
+
1412
+ return strcmp(mappingA.name, mappingB.name);
1413
+ }
1414
+ exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
1415
+
1416
+ /**
1417
+ * Strip any JSON XSSI avoidance prefix from the string (as documented
1418
+ * in the source maps specification), and then parse the string as
1419
+ * JSON.
1420
+ */
1421
+ function parseSourceMapInput(str) {
1422
+ return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
1423
+ }
1424
+ exports.parseSourceMapInput = parseSourceMapInput;
1425
+
1426
+ /**
1427
+ * Compute the URL of a source given the the source root, the source's
1428
+ * URL, and the source map's URL.
1429
+ */
1430
+ function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
1431
+ sourceURL = sourceURL || '';
1432
+
1433
+ if (sourceRoot) {
1434
+ // This follows what Chrome does.
1435
+ if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
1436
+ sourceRoot += '/';
1437
+ }
1438
+ // The spec says:
1439
+ // Line 4: An optional source root, useful for relocating source
1440
+ // files on a server or removing repeated values in the
1441
+ // “sources” entry. This value is prepended to the individual
1442
+ // entries in the “source” field.
1443
+ sourceURL = sourceRoot + sourceURL;
1444
+ }
1445
+
1446
+ // Historically, SourceMapConsumer did not take the sourceMapURL as
1447
+ // a parameter. This mode is still somewhat supported, which is why
1448
+ // this code block is conditional. However, it's preferable to pass
1449
+ // the source map URL to SourceMapConsumer, so that this function
1450
+ // can implement the source URL resolution algorithm as outlined in
1451
+ // the spec. This block is basically the equivalent of:
1452
+ // new URL(sourceURL, sourceMapURL).toString()
1453
+ // ... except it avoids using URL, which wasn't available in the
1454
+ // older releases of node still supported by this library.
1455
+ //
1456
+ // The spec says:
1457
+ // If the sources are not absolute URLs after prepending of the
1458
+ // “sourceRoot”, the sources are resolved relative to the
1459
+ // SourceMap (like resolving script src in a html document).
1460
+ if (sourceMapURL) {
1461
+ var parsed = urlParse(sourceMapURL);
1462
+ if (!parsed) {
1463
+ throw new Error("sourceMapURL could not be parsed");
1464
+ }
1465
+ if (parsed.path) {
1466
+ // Strip the last path component, but keep the "/".
1467
+ var index = parsed.path.lastIndexOf('/');
1468
+ if (index >= 0) {
1469
+ parsed.path = parsed.path.substring(0, index + 1);
1470
+ }
1471
+ }
1472
+ sourceURL = join(urlGenerate(parsed), sourceURL);
1473
+ }
1474
+
1475
+ return normalize(sourceURL);
1476
+ }
1477
+ exports.computeSourceURL = computeSourceURL;
1478
+ }(util$5));
1479
+
1480
+ var arraySet = {};
1481
+
1482
+ /* -*- Mode: js; js-indent-level: 2; -*- */
1483
+
1484
+ /*
1485
+ * Copyright 2011 Mozilla Foundation and contributors
1486
+ * Licensed under the New BSD license. See LICENSE or:
1487
+ * http://opensource.org/licenses/BSD-3-Clause
1488
+ */
1489
+
1490
+ var util$4 = util$5;
1491
+ var has = Object.prototype.hasOwnProperty;
1492
+ var hasNativeMap = typeof Map !== "undefined";
1493
+
1494
+ /**
1495
+ * A data structure which is a combination of an array and a set. Adding a new
1496
+ * member is O(1), testing for membership is O(1), and finding the index of an
1497
+ * element is O(1). Removing elements from the set is not supported. Only
1498
+ * strings are supported for membership.
1499
+ */
1500
+ function ArraySet$2() {
1501
+ this._array = [];
1502
+ this._set = hasNativeMap ? new Map() : Object.create(null);
1503
+ }
1504
+
1505
+ /**
1506
+ * Static method for creating ArraySet instances from an existing array.
1507
+ */
1508
+ ArraySet$2.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
1509
+ var set = new ArraySet$2();
1510
+ for (var i = 0, len = aArray.length; i < len; i++) {
1511
+ set.add(aArray[i], aAllowDuplicates);
1512
+ }
1513
+ return set;
1514
+ };
1515
+
1516
+ /**
1517
+ * Return how many unique items are in this ArraySet. If duplicates have been
1518
+ * added, than those do not count towards the size.
1519
+ *
1520
+ * @returns Number
1521
+ */
1522
+ ArraySet$2.prototype.size = function ArraySet_size() {
1523
+ return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
1524
+ };
1525
+
1526
+ /**
1527
+ * Add the given string to this set.
1528
+ *
1529
+ * @param String aStr
1530
+ */
1531
+ ArraySet$2.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
1532
+ var sStr = hasNativeMap ? aStr : util$4.toSetString(aStr);
1533
+ var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
1534
+ var idx = this._array.length;
1535
+ if (!isDuplicate || aAllowDuplicates) {
1536
+ this._array.push(aStr);
1537
+ }
1538
+ if (!isDuplicate) {
1539
+ if (hasNativeMap) {
1540
+ this._set.set(aStr, idx);
1541
+ } else {
1542
+ this._set[sStr] = idx;
1543
+ }
1544
+ }
1545
+ };
1546
+
1547
+ /**
1548
+ * Is the given string a member of this set?
1549
+ *
1550
+ * @param String aStr
1551
+ */
1552
+ ArraySet$2.prototype.has = function ArraySet_has(aStr) {
1553
+ if (hasNativeMap) {
1554
+ return this._set.has(aStr);
1555
+ } else {
1556
+ var sStr = util$4.toSetString(aStr);
1557
+ return has.call(this._set, sStr);
1558
+ }
1559
+ };
1560
+
1561
+ /**
1562
+ * What is the index of the given string in the array?
1563
+ *
1564
+ * @param String aStr
1565
+ */
1566
+ ArraySet$2.prototype.indexOf = function ArraySet_indexOf(aStr) {
1567
+ if (hasNativeMap) {
1568
+ var idx = this._set.get(aStr);
1569
+ if (idx >= 0) {
1570
+ return idx;
1571
+ }
1572
+ } else {
1573
+ var sStr = util$4.toSetString(aStr);
1574
+ if (has.call(this._set, sStr)) {
1575
+ return this._set[sStr];
1576
+ }
1577
+ }
1578
+
1579
+ throw new Error('"' + aStr + '" is not in the set.');
1580
+ };
1581
+
1582
+ /**
1583
+ * What is the element at the given index?
1584
+ *
1585
+ * @param Number aIdx
1586
+ */
1587
+ ArraySet$2.prototype.at = function ArraySet_at(aIdx) {
1588
+ if (aIdx >= 0 && aIdx < this._array.length) {
1589
+ return this._array[aIdx];
1590
+ }
1591
+ throw new Error('No element indexed by ' + aIdx);
1592
+ };
1593
+
1594
+ /**
1595
+ * Returns the array representation of this set (which has the proper indices
1596
+ * indicated by indexOf). Note that this is a copy of the internal array used
1597
+ * for storing the members so that no one can mess with internal state.
1598
+ */
1599
+ ArraySet$2.prototype.toArray = function ArraySet_toArray() {
1600
+ return this._array.slice();
1601
+ };
1602
+
1603
+ arraySet.ArraySet = ArraySet$2;
1604
+
1605
+ var mappingList = {};
1606
+
1607
+ /* -*- Mode: js; js-indent-level: 2; -*- */
1608
+
1609
+ /*
1610
+ * Copyright 2014 Mozilla Foundation and contributors
1611
+ * Licensed under the New BSD license. See LICENSE or:
1612
+ * http://opensource.org/licenses/BSD-3-Clause
1613
+ */
1614
+
1615
+ var util$3 = util$5;
1616
+
1617
+ /**
1618
+ * Determine whether mappingB is after mappingA with respect to generated
1619
+ * position.
1620
+ */
1621
+ function generatedPositionAfter(mappingA, mappingB) {
1622
+ // Optimized for most common case
1623
+ var lineA = mappingA.generatedLine;
1624
+ var lineB = mappingB.generatedLine;
1625
+ var columnA = mappingA.generatedColumn;
1626
+ var columnB = mappingB.generatedColumn;
1627
+ return lineB > lineA || lineB == lineA && columnB >= columnA ||
1628
+ util$3.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
1629
+ }
1630
+
1631
+ /**
1632
+ * A data structure to provide a sorted view of accumulated mappings in a
1633
+ * performance conscious manner. It trades a neglibable overhead in general
1634
+ * case for a large speedup in case of mappings being added in order.
1635
+ */
1636
+ function MappingList$1() {
1637
+ this._array = [];
1638
+ this._sorted = true;
1639
+ // Serves as infimum
1640
+ this._last = {generatedLine: -1, generatedColumn: 0};
1641
+ }
1642
+
1643
+ /**
1644
+ * Iterate through internal items. This method takes the same arguments that
1645
+ * `Array.prototype.forEach` takes.
1646
+ *
1647
+ * NOTE: The order of the mappings is NOT guaranteed.
1648
+ */
1649
+ MappingList$1.prototype.unsortedForEach =
1650
+ function MappingList_forEach(aCallback, aThisArg) {
1651
+ this._array.forEach(aCallback, aThisArg);
1652
+ };
1653
+
1654
+ /**
1655
+ * Add the given source mapping.
1656
+ *
1657
+ * @param Object aMapping
1658
+ */
1659
+ MappingList$1.prototype.add = function MappingList_add(aMapping) {
1660
+ if (generatedPositionAfter(this._last, aMapping)) {
1661
+ this._last = aMapping;
1662
+ this._array.push(aMapping);
1663
+ } else {
1664
+ this._sorted = false;
1665
+ this._array.push(aMapping);
1666
+ }
1667
+ };
1668
+
1669
+ /**
1670
+ * Returns the flat, sorted array of mappings. The mappings are sorted by
1671
+ * generated position.
1672
+ *
1673
+ * WARNING: This method returns internal data without copying, for
1674
+ * performance. The return value must NOT be mutated, and should be treated as
1675
+ * an immutable borrow. If you want to take ownership, you must make your own
1676
+ * copy.
1677
+ */
1678
+ MappingList$1.prototype.toArray = function MappingList_toArray() {
1679
+ if (!this._sorted) {
1680
+ this._array.sort(util$3.compareByGeneratedPositionsInflated);
1681
+ this._sorted = true;
1682
+ }
1683
+ return this._array;
1684
+ };
1685
+
1686
+ mappingList.MappingList = MappingList$1;
1687
+
1688
+ /* -*- Mode: js; js-indent-level: 2; -*- */
1689
+
1690
+ /*
1691
+ * Copyright 2011 Mozilla Foundation and contributors
1692
+ * Licensed under the New BSD license. See LICENSE or:
1693
+ * http://opensource.org/licenses/BSD-3-Clause
1694
+ */
1695
+
1696
+ var base64VLQ$1 = base64Vlq;
1697
+ var util$2 = util$5;
1698
+ var ArraySet$1 = arraySet.ArraySet;
1699
+ var MappingList = mappingList.MappingList;
1700
+
1701
+ /**
1702
+ * An instance of the SourceMapGenerator represents a source map which is
1703
+ * being built incrementally. You may pass an object with the following
1704
+ * properties:
1705
+ *
1706
+ * - file: The filename of the generated source.
1707
+ * - sourceRoot: A root for all relative URLs in this source map.
1708
+ */
1709
+ function SourceMapGenerator$1(aArgs) {
1710
+ if (!aArgs) {
1711
+ aArgs = {};
1712
+ }
1713
+ this._file = util$2.getArg(aArgs, 'file', null);
1714
+ this._sourceRoot = util$2.getArg(aArgs, 'sourceRoot', null);
1715
+ this._skipValidation = util$2.getArg(aArgs, 'skipValidation', false);
1716
+ this._sources = new ArraySet$1();
1717
+ this._names = new ArraySet$1();
1718
+ this._mappings = new MappingList();
1719
+ this._sourcesContents = null;
1720
+ }
1721
+
1722
+ SourceMapGenerator$1.prototype._version = 3;
1723
+
1724
+ /**
1725
+ * Creates a new SourceMapGenerator based on a SourceMapConsumer
1726
+ *
1727
+ * @param aSourceMapConsumer The SourceMap.
1728
+ */
1729
+ SourceMapGenerator$1.fromSourceMap =
1730
+ function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
1731
+ var sourceRoot = aSourceMapConsumer.sourceRoot;
1732
+ var generator = new SourceMapGenerator$1({
1733
+ file: aSourceMapConsumer.file,
1734
+ sourceRoot: sourceRoot
1735
+ });
1736
+ aSourceMapConsumer.eachMapping(function (mapping) {
1737
+ var newMapping = {
1738
+ generated: {
1739
+ line: mapping.generatedLine,
1740
+ column: mapping.generatedColumn
1741
+ }
1742
+ };
1743
+
1744
+ if (mapping.source != null) {
1745
+ newMapping.source = mapping.source;
1746
+ if (sourceRoot != null) {
1747
+ newMapping.source = util$2.relative(sourceRoot, newMapping.source);
1748
+ }
1749
+
1750
+ newMapping.original = {
1751
+ line: mapping.originalLine,
1752
+ column: mapping.originalColumn
1753
+ };
1754
+
1755
+ if (mapping.name != null) {
1756
+ newMapping.name = mapping.name;
1757
+ }
1758
+ }
1759
+
1760
+ generator.addMapping(newMapping);
1761
+ });
1762
+ aSourceMapConsumer.sources.forEach(function (sourceFile) {
1763
+ var sourceRelative = sourceFile;
1764
+ if (sourceRoot !== null) {
1765
+ sourceRelative = util$2.relative(sourceRoot, sourceFile);
1766
+ }
1767
+
1768
+ if (!generator._sources.has(sourceRelative)) {
1769
+ generator._sources.add(sourceRelative);
1770
+ }
1771
+
1772
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile);
1773
+ if (content != null) {
1774
+ generator.setSourceContent(sourceFile, content);
1775
+ }
1776
+ });
1777
+ return generator;
1778
+ };
1779
+
1780
+ /**
1781
+ * Add a single mapping from original source line and column to the generated
1782
+ * source's line and column for this source map being created. The mapping
1783
+ * object should have the following properties:
1784
+ *
1785
+ * - generated: An object with the generated line and column positions.
1786
+ * - original: An object with the original line and column positions.
1787
+ * - source: The original source file (relative to the sourceRoot).
1788
+ * - name: An optional original token name for this mapping.
1789
+ */
1790
+ SourceMapGenerator$1.prototype.addMapping =
1791
+ function SourceMapGenerator_addMapping(aArgs) {
1792
+ var generated = util$2.getArg(aArgs, 'generated');
1793
+ var original = util$2.getArg(aArgs, 'original', null);
1794
+ var source = util$2.getArg(aArgs, 'source', null);
1795
+ var name = util$2.getArg(aArgs, 'name', null);
1796
+
1797
+ if (!this._skipValidation) {
1798
+ this._validateMapping(generated, original, source, name);
1799
+ }
1800
+
1801
+ if (source != null) {
1802
+ source = String(source);
1803
+ if (!this._sources.has(source)) {
1804
+ this._sources.add(source);
1805
+ }
1806
+ }
1807
+
1808
+ if (name != null) {
1809
+ name = String(name);
1810
+ if (!this._names.has(name)) {
1811
+ this._names.add(name);
1812
+ }
1813
+ }
1814
+
1815
+ this._mappings.add({
1816
+ generatedLine: generated.line,
1817
+ generatedColumn: generated.column,
1818
+ originalLine: original != null && original.line,
1819
+ originalColumn: original != null && original.column,
1820
+ source: source,
1821
+ name: name
1822
+ });
1823
+ };
1824
+
1825
+ /**
1826
+ * Set the source content for a source file.
1827
+ */
1828
+ SourceMapGenerator$1.prototype.setSourceContent =
1829
+ function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
1830
+ var source = aSourceFile;
1831
+ if (this._sourceRoot != null) {
1832
+ source = util$2.relative(this._sourceRoot, source);
1833
+ }
1834
+
1835
+ if (aSourceContent != null) {
1836
+ // Add the source content to the _sourcesContents map.
1837
+ // Create a new _sourcesContents map if the property is null.
1838
+ if (!this._sourcesContents) {
1839
+ this._sourcesContents = Object.create(null);
1840
+ }
1841
+ this._sourcesContents[util$2.toSetString(source)] = aSourceContent;
1842
+ } else if (this._sourcesContents) {
1843
+ // Remove the source file from the _sourcesContents map.
1844
+ // If the _sourcesContents map is empty, set the property to null.
1845
+ delete this._sourcesContents[util$2.toSetString(source)];
1846
+ if (Object.keys(this._sourcesContents).length === 0) {
1847
+ this._sourcesContents = null;
1848
+ }
1849
+ }
1850
+ };
1851
+
1852
+ /**
1853
+ * Applies the mappings of a sub-source-map for a specific source file to the
1854
+ * source map being generated. Each mapping to the supplied source file is
1855
+ * rewritten using the supplied source map. Note: The resolution for the
1856
+ * resulting mappings is the minimium of this map and the supplied map.
1857
+ *
1858
+ * @param aSourceMapConsumer The source map to be applied.
1859
+ * @param aSourceFile Optional. The filename of the source file.
1860
+ * If omitted, SourceMapConsumer's file property will be used.
1861
+ * @param aSourceMapPath Optional. The dirname of the path to the source map
1862
+ * to be applied. If relative, it is relative to the SourceMapConsumer.
1863
+ * This parameter is needed when the two source maps aren't in the same
1864
+ * directory, and the source map to be applied contains relative source
1865
+ * paths. If so, those relative source paths need to be rewritten
1866
+ * relative to the SourceMapGenerator.
1867
+ */
1868
+ SourceMapGenerator$1.prototype.applySourceMap =
1869
+ function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
1870
+ var sourceFile = aSourceFile;
1871
+ // If aSourceFile is omitted, we will use the file property of the SourceMap
1872
+ if (aSourceFile == null) {
1873
+ if (aSourceMapConsumer.file == null) {
1874
+ throw new Error(
1875
+ 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
1876
+ 'or the source map\'s "file" property. Both were omitted.'
1877
+ );
1878
+ }
1879
+ sourceFile = aSourceMapConsumer.file;
1880
+ }
1881
+ var sourceRoot = this._sourceRoot;
1882
+ // Make "sourceFile" relative if an absolute Url is passed.
1883
+ if (sourceRoot != null) {
1884
+ sourceFile = util$2.relative(sourceRoot, sourceFile);
1885
+ }
1886
+ // Applying the SourceMap can add and remove items from the sources and
1887
+ // the names array.
1888
+ var newSources = new ArraySet$1();
1889
+ var newNames = new ArraySet$1();
1890
+
1891
+ // Find mappings for the "sourceFile"
1892
+ this._mappings.unsortedForEach(function (mapping) {
1893
+ if (mapping.source === sourceFile && mapping.originalLine != null) {
1894
+ // Check if it can be mapped by the source map, then update the mapping.
1895
+ var original = aSourceMapConsumer.originalPositionFor({
1896
+ line: mapping.originalLine,
1897
+ column: mapping.originalColumn
1898
+ });
1899
+ if (original.source != null) {
1900
+ // Copy mapping
1901
+ mapping.source = original.source;
1902
+ if (aSourceMapPath != null) {
1903
+ mapping.source = util$2.join(aSourceMapPath, mapping.source);
1904
+ }
1905
+ if (sourceRoot != null) {
1906
+ mapping.source = util$2.relative(sourceRoot, mapping.source);
1907
+ }
1908
+ mapping.originalLine = original.line;
1909
+ mapping.originalColumn = original.column;
1910
+ if (original.name != null) {
1911
+ mapping.name = original.name;
1912
+ }
1913
+ }
1914
+ }
1915
+
1916
+ var source = mapping.source;
1917
+ if (source != null && !newSources.has(source)) {
1918
+ newSources.add(source);
1919
+ }
1920
+
1921
+ var name = mapping.name;
1922
+ if (name != null && !newNames.has(name)) {
1923
+ newNames.add(name);
1924
+ }
1925
+
1926
+ }, this);
1927
+ this._sources = newSources;
1928
+ this._names = newNames;
1929
+
1930
+ // Copy sourcesContents of applied map.
1931
+ aSourceMapConsumer.sources.forEach(function (sourceFile) {
1932
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile);
1933
+ if (content != null) {
1934
+ if (aSourceMapPath != null) {
1935
+ sourceFile = util$2.join(aSourceMapPath, sourceFile);
1936
+ }
1937
+ if (sourceRoot != null) {
1938
+ sourceFile = util$2.relative(sourceRoot, sourceFile);
1939
+ }
1940
+ this.setSourceContent(sourceFile, content);
1941
+ }
1942
+ }, this);
1943
+ };
1944
+
1945
+ /**
1946
+ * A mapping can have one of the three levels of data:
1947
+ *
1948
+ * 1. Just the generated position.
1949
+ * 2. The Generated position, original position, and original source.
1950
+ * 3. Generated and original position, original source, as well as a name
1951
+ * token.
1952
+ *
1953
+ * To maintain consistency, we validate that any new mapping being added falls
1954
+ * in to one of these categories.
1955
+ */
1956
+ SourceMapGenerator$1.prototype._validateMapping =
1957
+ function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
1958
+ aName) {
1959
+ // When aOriginal is truthy but has empty values for .line and .column,
1960
+ // it is most likely a programmer error. In this case we throw a very
1961
+ // specific error message to try to guide them the right way.
1962
+ // For example: https://github.com/Polymer/polymer-bundler/pull/519
1963
+ if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
1964
+ throw new Error(
1965
+ 'original.line and original.column are not numbers -- you probably meant to omit ' +
1966
+ 'the original mapping entirely and only map the generated position. If so, pass ' +
1967
+ 'null for the original mapping instead of an object with empty or null values.'
1968
+ );
1969
+ }
1970
+
1971
+ if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
1972
+ && aGenerated.line > 0 && aGenerated.column >= 0
1973
+ && !aOriginal && !aSource && !aName) {
1974
+ // Case 1.
1975
+ return;
1976
+ }
1977
+ else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
1978
+ && aOriginal && 'line' in aOriginal && 'column' in aOriginal
1979
+ && aGenerated.line > 0 && aGenerated.column >= 0
1980
+ && aOriginal.line > 0 && aOriginal.column >= 0
1981
+ && aSource) {
1982
+ // Cases 2 and 3.
1983
+ return;
1984
+ }
1985
+ else {
1986
+ throw new Error('Invalid mapping: ' + JSON.stringify({
1987
+ generated: aGenerated,
1988
+ source: aSource,
1989
+ original: aOriginal,
1990
+ name: aName
1991
+ }));
1992
+ }
1993
+ };
1994
+
1995
+ /**
1996
+ * Serialize the accumulated mappings in to the stream of base 64 VLQs
1997
+ * specified by the source map format.
1998
+ */
1999
+ SourceMapGenerator$1.prototype._serializeMappings =
2000
+ function SourceMapGenerator_serializeMappings() {
2001
+ var previousGeneratedColumn = 0;
2002
+ var previousGeneratedLine = 1;
2003
+ var previousOriginalColumn = 0;
2004
+ var previousOriginalLine = 0;
2005
+ var previousName = 0;
2006
+ var previousSource = 0;
2007
+ var result = '';
2008
+ var next;
2009
+ var mapping;
2010
+ var nameIdx;
2011
+ var sourceIdx;
2012
+
2013
+ var mappings = this._mappings.toArray();
2014
+ for (var i = 0, len = mappings.length; i < len; i++) {
2015
+ mapping = mappings[i];
2016
+ next = '';
2017
+
2018
+ if (mapping.generatedLine !== previousGeneratedLine) {
2019
+ previousGeneratedColumn = 0;
2020
+ while (mapping.generatedLine !== previousGeneratedLine) {
2021
+ next += ';';
2022
+ previousGeneratedLine++;
2023
+ }
2024
+ }
2025
+ else {
2026
+ if (i > 0) {
2027
+ if (!util$2.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
2028
+ continue;
2029
+ }
2030
+ next += ',';
2031
+ }
2032
+ }
2033
+
2034
+ next += base64VLQ$1.encode(mapping.generatedColumn
2035
+ - previousGeneratedColumn);
2036
+ previousGeneratedColumn = mapping.generatedColumn;
2037
+
2038
+ if (mapping.source != null) {
2039
+ sourceIdx = this._sources.indexOf(mapping.source);
2040
+ next += base64VLQ$1.encode(sourceIdx - previousSource);
2041
+ previousSource = sourceIdx;
2042
+
2043
+ // lines are stored 0-based in SourceMap spec version 3
2044
+ next += base64VLQ$1.encode(mapping.originalLine - 1
2045
+ - previousOriginalLine);
2046
+ previousOriginalLine = mapping.originalLine - 1;
2047
+
2048
+ next += base64VLQ$1.encode(mapping.originalColumn
2049
+ - previousOriginalColumn);
2050
+ previousOriginalColumn = mapping.originalColumn;
2051
+
2052
+ if (mapping.name != null) {
2053
+ nameIdx = this._names.indexOf(mapping.name);
2054
+ next += base64VLQ$1.encode(nameIdx - previousName);
2055
+ previousName = nameIdx;
2056
+ }
2057
+ }
2058
+
2059
+ result += next;
2060
+ }
2061
+
2062
+ return result;
2063
+ };
2064
+
2065
+ SourceMapGenerator$1.prototype._generateSourcesContent =
2066
+ function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
2067
+ return aSources.map(function (source) {
2068
+ if (!this._sourcesContents) {
2069
+ return null;
2070
+ }
2071
+ if (aSourceRoot != null) {
2072
+ source = util$2.relative(aSourceRoot, source);
2073
+ }
2074
+ var key = util$2.toSetString(source);
2075
+ return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
2076
+ ? this._sourcesContents[key]
2077
+ : null;
2078
+ }, this);
2079
+ };
2080
+
2081
+ /**
2082
+ * Externalize the source map.
2083
+ */
2084
+ SourceMapGenerator$1.prototype.toJSON =
2085
+ function SourceMapGenerator_toJSON() {
2086
+ var map = {
2087
+ version: this._version,
2088
+ sources: this._sources.toArray(),
2089
+ names: this._names.toArray(),
2090
+ mappings: this._serializeMappings()
2091
+ };
2092
+ if (this._file != null) {
2093
+ map.file = this._file;
2094
+ }
2095
+ if (this._sourceRoot != null) {
2096
+ map.sourceRoot = this._sourceRoot;
2097
+ }
2098
+ if (this._sourcesContents) {
2099
+ map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
2100
+ }
2101
+
2102
+ return map;
2103
+ };
2104
+
2105
+ /**
2106
+ * Render the source map being generated to a string.
2107
+ */
2108
+ SourceMapGenerator$1.prototype.toString =
2109
+ function SourceMapGenerator_toString() {
2110
+ return JSON.stringify(this.toJSON());
2111
+ };
2112
+
2113
+ sourceMapGenerator.SourceMapGenerator = SourceMapGenerator$1;
2114
+
2115
+ var sourceMapConsumer = {};
2116
+
2117
+ var binarySearch$1 = {};
2118
+
2119
+ /* -*- Mode: js; js-indent-level: 2; -*- */
2120
+
2121
+ (function (exports) {
2122
+ /*
2123
+ * Copyright 2011 Mozilla Foundation and contributors
2124
+ * Licensed under the New BSD license. See LICENSE or:
2125
+ * http://opensource.org/licenses/BSD-3-Clause
2126
+ */
2127
+
2128
+ exports.GREATEST_LOWER_BOUND = 1;
2129
+ exports.LEAST_UPPER_BOUND = 2;
2130
+
2131
+ /**
2132
+ * Recursive implementation of binary search.
2133
+ *
2134
+ * @param aLow Indices here and lower do not contain the needle.
2135
+ * @param aHigh Indices here and higher do not contain the needle.
2136
+ * @param aNeedle The element being searched for.
2137
+ * @param aHaystack The non-empty array being searched.
2138
+ * @param aCompare Function which takes two elements and returns -1, 0, or 1.
2139
+ * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
2140
+ * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
2141
+ * closest element that is smaller than or greater than the one we are
2142
+ * searching for, respectively, if the exact element cannot be found.
2143
+ */
2144
+ function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
2145
+ // This function terminates when one of the following is true:
2146
+ //
2147
+ // 1. We find the exact element we are looking for.
2148
+ //
2149
+ // 2. We did not find the exact element, but we can return the index of
2150
+ // the next-closest element.
2151
+ //
2152
+ // 3. We did not find the exact element, and there is no next-closest
2153
+ // element than the one we are searching for, so we return -1.
2154
+ var mid = Math.floor((aHigh - aLow) / 2) + aLow;
2155
+ var cmp = aCompare(aNeedle, aHaystack[mid], true);
2156
+ if (cmp === 0) {
2157
+ // Found the element we are looking for.
2158
+ return mid;
2159
+ }
2160
+ else if (cmp > 0) {
2161
+ // Our needle is greater than aHaystack[mid].
2162
+ if (aHigh - mid > 1) {
2163
+ // The element is in the upper half.
2164
+ return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
2165
+ }
2166
+
2167
+ // The exact needle element was not found in this haystack. Determine if
2168
+ // we are in termination case (3) or (2) and return the appropriate thing.
2169
+ if (aBias == exports.LEAST_UPPER_BOUND) {
2170
+ return aHigh < aHaystack.length ? aHigh : -1;
2171
+ } else {
2172
+ return mid;
2173
+ }
2174
+ }
2175
+ else {
2176
+ // Our needle is less than aHaystack[mid].
2177
+ if (mid - aLow > 1) {
2178
+ // The element is in the lower half.
2179
+ return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
2180
+ }
2181
+
2182
+ // we are in termination case (3) or (2) and return the appropriate thing.
2183
+ if (aBias == exports.LEAST_UPPER_BOUND) {
2184
+ return mid;
2185
+ } else {
2186
+ return aLow < 0 ? -1 : aLow;
2187
+ }
2188
+ }
2189
+ }
2190
+
2191
+ /**
2192
+ * This is an implementation of binary search which will always try and return
2193
+ * the index of the closest element if there is no exact hit. This is because
2194
+ * mappings between original and generated line/col pairs are single points,
2195
+ * and there is an implicit region between each of them, so a miss just means
2196
+ * that you aren't on the very start of a region.
2197
+ *
2198
+ * @param aNeedle The element you are looking for.
2199
+ * @param aHaystack The array that is being searched.
2200
+ * @param aCompare A function which takes the needle and an element in the
2201
+ * array and returns -1, 0, or 1 depending on whether the needle is less
2202
+ * than, equal to, or greater than the element, respectively.
2203
+ * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
2204
+ * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
2205
+ * closest element that is smaller than or greater than the one we are
2206
+ * searching for, respectively, if the exact element cannot be found.
2207
+ * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
2208
+ */
2209
+ exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
2210
+ if (aHaystack.length === 0) {
2211
+ return -1;
2212
+ }
2213
+
2214
+ var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
2215
+ aCompare, aBias || exports.GREATEST_LOWER_BOUND);
2216
+ if (index < 0) {
2217
+ return -1;
2218
+ }
2219
+
2220
+ // We have found either the exact element, or the next-closest element than
2221
+ // the one we are searching for. However, there may be more than one such
2222
+ // element. Make sure we always return the smallest of these.
2223
+ while (index - 1 >= 0) {
2224
+ if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
2225
+ break;
2226
+ }
2227
+ --index;
2228
+ }
2229
+
2230
+ return index;
2231
+ };
2232
+ }(binarySearch$1));
2233
+
2234
+ var quickSort$1 = {};
2235
+
2236
+ /* -*- Mode: js; js-indent-level: 2; -*- */
2237
+
2238
+ /*
2239
+ * Copyright 2011 Mozilla Foundation and contributors
2240
+ * Licensed under the New BSD license. See LICENSE or:
2241
+ * http://opensource.org/licenses/BSD-3-Clause
2242
+ */
2243
+
2244
+ // It turns out that some (most?) JavaScript engines don't self-host
2245
+ // `Array.prototype.sort`. This makes sense because C++ will likely remain
2246
+ // faster than JS when doing raw CPU-intensive sorting. However, when using a
2247
+ // custom comparator function, calling back and forth between the VM's C++ and
2248
+ // JIT'd JS is rather slow *and* loses JIT type information, resulting in
2249
+ // worse generated code for the comparator function than would be optimal. In
2250
+ // fact, when sorting with a comparator, these costs outweigh the benefits of
2251
+ // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
2252
+ // a ~3500ms mean speed-up in `bench/bench.html`.
2253
+
2254
+ function SortTemplate(comparator) {
2255
+
2256
+ /**
2257
+ * Swap the elements indexed by `x` and `y` in the array `ary`.
2258
+ *
2259
+ * @param {Array} ary
2260
+ * The array.
2261
+ * @param {Number} x
2262
+ * The index of the first item.
2263
+ * @param {Number} y
2264
+ * The index of the second item.
2265
+ */
2266
+ function swap(ary, x, y) {
2267
+ var temp = ary[x];
2268
+ ary[x] = ary[y];
2269
+ ary[y] = temp;
2270
+ }
2271
+
2272
+ /**
2273
+ * Returns a random integer within the range `low .. high` inclusive.
2274
+ *
2275
+ * @param {Number} low
2276
+ * The lower bound on the range.
2277
+ * @param {Number} high
2278
+ * The upper bound on the range.
2279
+ */
2280
+ function randomIntInRange(low, high) {
2281
+ return Math.round(low + (Math.random() * (high - low)));
2282
+ }
2283
+
2284
+ /**
2285
+ * The Quick Sort algorithm.
2286
+ *
2287
+ * @param {Array} ary
2288
+ * An array to sort.
2289
+ * @param {function} comparator
2290
+ * Function to use to compare two items.
2291
+ * @param {Number} p
2292
+ * Start index of the array
2293
+ * @param {Number} r
2294
+ * End index of the array
2295
+ */
2296
+ function doQuickSort(ary, comparator, p, r) {
2297
+ // If our lower bound is less than our upper bound, we (1) partition the
2298
+ // array into two pieces and (2) recurse on each half. If it is not, this is
2299
+ // the empty array and our base case.
2300
+
2301
+ if (p < r) {
2302
+ // (1) Partitioning.
2303
+ //
2304
+ // The partitioning chooses a pivot between `p` and `r` and moves all
2305
+ // elements that are less than or equal to the pivot to the before it, and
2306
+ // all the elements that are greater than it after it. The effect is that
2307
+ // once partition is done, the pivot is in the exact place it will be when
2308
+ // the array is put in sorted order, and it will not need to be moved
2309
+ // again. This runs in O(n) time.
2310
+
2311
+ // Always choose a random pivot so that an input array which is reverse
2312
+ // sorted does not cause O(n^2) running time.
2313
+ var pivotIndex = randomIntInRange(p, r);
2314
+ var i = p - 1;
2315
+
2316
+ swap(ary, pivotIndex, r);
2317
+ var pivot = ary[r];
2318
+
2319
+ // Immediately after `j` is incremented in this loop, the following hold
2320
+ // true:
2321
+ //
2322
+ // * Every element in `ary[p .. i]` is less than or equal to the pivot.
2323
+ //
2324
+ // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
2325
+ for (var j = p; j < r; j++) {
2326
+ if (comparator(ary[j], pivot, false) <= 0) {
2327
+ i += 1;
2328
+ swap(ary, i, j);
2329
+ }
2330
+ }
2331
+
2332
+ swap(ary, i + 1, j);
2333
+ var q = i + 1;
2334
+
2335
+ // (2) Recurse on each half.
2336
+
2337
+ doQuickSort(ary, comparator, p, q - 1);
2338
+ doQuickSort(ary, comparator, q + 1, r);
2339
+ }
2340
+ }
2341
+
2342
+ return doQuickSort;
2343
+ }
2344
+
2345
+ function cloneSort(comparator) {
2346
+ let template = SortTemplate.toString();
2347
+ let templateFn = new Function(`return ${template}`)();
2348
+ return templateFn(comparator);
2349
+ }
2350
+
2351
+ /**
2352
+ * Sort the given array in-place with the given comparator function.
2353
+ *
2354
+ * @param {Array} ary
2355
+ * An array to sort.
2356
+ * @param {function} comparator
2357
+ * Function to use to compare two items.
2358
+ */
2359
+
2360
+ let sortCache = new WeakMap();
2361
+ quickSort$1.quickSort = function (ary, comparator, start = 0) {
2362
+ let doQuickSort = sortCache.get(comparator);
2363
+ if (doQuickSort === void 0) {
2364
+ doQuickSort = cloneSort(comparator);
2365
+ sortCache.set(comparator, doQuickSort);
2366
+ }
2367
+ doQuickSort(ary, comparator, start, ary.length - 1);
2368
+ };
2369
+
2370
+ /* -*- Mode: js; js-indent-level: 2; -*- */
2371
+
2372
+ /*
2373
+ * Copyright 2011 Mozilla Foundation and contributors
2374
+ * Licensed under the New BSD license. See LICENSE or:
2375
+ * http://opensource.org/licenses/BSD-3-Clause
2376
+ */
2377
+
2378
+ var util$1 = util$5;
2379
+ var binarySearch = binarySearch$1;
2380
+ var ArraySet = arraySet.ArraySet;
2381
+ var base64VLQ = base64Vlq;
2382
+ var quickSort = quickSort$1.quickSort;
2383
+
2384
+ function SourceMapConsumer$1(aSourceMap, aSourceMapURL) {
2385
+ var sourceMap = aSourceMap;
2386
+ if (typeof aSourceMap === 'string') {
2387
+ sourceMap = util$1.parseSourceMapInput(aSourceMap);
2388
+ }
2389
+
2390
+ return sourceMap.sections != null
2391
+ ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
2392
+ : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
2393
+ }
2394
+
2395
+ SourceMapConsumer$1.fromSourceMap = function(aSourceMap, aSourceMapURL) {
2396
+ return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
2397
+ };
2398
+
2399
+ /**
2400
+ * The version of the source mapping spec that we are consuming.
2401
+ */
2402
+ SourceMapConsumer$1.prototype._version = 3;
2403
+
2404
+ // `__generatedMappings` and `__originalMappings` are arrays that hold the
2405
+ // parsed mapping coordinates from the source map's "mappings" attribute. They
2406
+ // are lazily instantiated, accessed via the `_generatedMappings` and
2407
+ // `_originalMappings` getters respectively, and we only parse the mappings
2408
+ // and create these arrays once queried for a source location. We jump through
2409
+ // these hoops because there can be many thousands of mappings, and parsing
2410
+ // them is expensive, so we only want to do it if we must.
2411
+ //
2412
+ // Each object in the arrays is of the form:
2413
+ //
2414
+ // {
2415
+ // generatedLine: The line number in the generated code,
2416
+ // generatedColumn: The column number in the generated code,
2417
+ // source: The path to the original source file that generated this
2418
+ // chunk of code,
2419
+ // originalLine: The line number in the original source that
2420
+ // corresponds to this chunk of generated code,
2421
+ // originalColumn: The column number in the original source that
2422
+ // corresponds to this chunk of generated code,
2423
+ // name: The name of the original symbol which generated this chunk of
2424
+ // code.
2425
+ // }
2426
+ //
2427
+ // All properties except for `generatedLine` and `generatedColumn` can be
2428
+ // `null`.
2429
+ //
2430
+ // `_generatedMappings` is ordered by the generated positions.
2431
+ //
2432
+ // `_originalMappings` is ordered by the original positions.
2433
+
2434
+ SourceMapConsumer$1.prototype.__generatedMappings = null;
2435
+ Object.defineProperty(SourceMapConsumer$1.prototype, '_generatedMappings', {
2436
+ configurable: true,
2437
+ enumerable: true,
2438
+ get: function () {
2439
+ if (!this.__generatedMappings) {
2440
+ this._parseMappings(this._mappings, this.sourceRoot);
2441
+ }
2442
+
2443
+ return this.__generatedMappings;
2444
+ }
2445
+ });
2446
+
2447
+ SourceMapConsumer$1.prototype.__originalMappings = null;
2448
+ Object.defineProperty(SourceMapConsumer$1.prototype, '_originalMappings', {
2449
+ configurable: true,
2450
+ enumerable: true,
2451
+ get: function () {
2452
+ if (!this.__originalMappings) {
2453
+ this._parseMappings(this._mappings, this.sourceRoot);
2454
+ }
2455
+
2456
+ return this.__originalMappings;
2457
+ }
2458
+ });
2459
+
2460
+ SourceMapConsumer$1.prototype._charIsMappingSeparator =
2461
+ function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
2462
+ var c = aStr.charAt(index);
2463
+ return c === ";" || c === ",";
2464
+ };
2465
+
2466
+ /**
2467
+ * Parse the mappings in a string in to a data structure which we can easily
2468
+ * query (the ordered arrays in the `this.__generatedMappings` and
2469
+ * `this.__originalMappings` properties).
2470
+ */
2471
+ SourceMapConsumer$1.prototype._parseMappings =
2472
+ function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
2473
+ throw new Error("Subclasses must implement _parseMappings");
2474
+ };
2475
+
2476
+ SourceMapConsumer$1.GENERATED_ORDER = 1;
2477
+ SourceMapConsumer$1.ORIGINAL_ORDER = 2;
2478
+
2479
+ SourceMapConsumer$1.GREATEST_LOWER_BOUND = 1;
2480
+ SourceMapConsumer$1.LEAST_UPPER_BOUND = 2;
2481
+
2482
+ /**
2483
+ * Iterate over each mapping between an original source/line/column and a
2484
+ * generated line/column in this source map.
2485
+ *
2486
+ * @param Function aCallback
2487
+ * The function that is called with each mapping.
2488
+ * @param Object aContext
2489
+ * Optional. If specified, this object will be the value of `this` every
2490
+ * time that `aCallback` is called.
2491
+ * @param aOrder
2492
+ * Either `SourceMapConsumer.GENERATED_ORDER` or
2493
+ * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
2494
+ * iterate over the mappings sorted by the generated file's line/column
2495
+ * order or the original's source/line/column order, respectively. Defaults to
2496
+ * `SourceMapConsumer.GENERATED_ORDER`.
2497
+ */
2498
+ SourceMapConsumer$1.prototype.eachMapping =
2499
+ function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
2500
+ var context = aContext || null;
2501
+ var order = aOrder || SourceMapConsumer$1.GENERATED_ORDER;
2502
+
2503
+ var mappings;
2504
+ switch (order) {
2505
+ case SourceMapConsumer$1.GENERATED_ORDER:
2506
+ mappings = this._generatedMappings;
2507
+ break;
2508
+ case SourceMapConsumer$1.ORIGINAL_ORDER:
2509
+ mappings = this._originalMappings;
2510
+ break;
2511
+ default:
2512
+ throw new Error("Unknown order of iteration.");
2513
+ }
2514
+
2515
+ var sourceRoot = this.sourceRoot;
2516
+ var boundCallback = aCallback.bind(context);
2517
+ var names = this._names;
2518
+ var sources = this._sources;
2519
+ var sourceMapURL = this._sourceMapURL;
2520
+
2521
+ for (var i = 0, n = mappings.length; i < n; i++) {
2522
+ var mapping = mappings[i];
2523
+ var source = mapping.source === null ? null : sources.at(mapping.source);
2524
+ source = util$1.computeSourceURL(sourceRoot, source, sourceMapURL);
2525
+ boundCallback({
2526
+ source: source,
2527
+ generatedLine: mapping.generatedLine,
2528
+ generatedColumn: mapping.generatedColumn,
2529
+ originalLine: mapping.originalLine,
2530
+ originalColumn: mapping.originalColumn,
2531
+ name: mapping.name === null ? null : names.at(mapping.name)
2532
+ });
2533
+ }
2534
+ };
2535
+
2536
+ /**
2537
+ * Returns all generated line and column information for the original source,
2538
+ * line, and column provided. If no column is provided, returns all mappings
2539
+ * corresponding to a either the line we are searching for or the next
2540
+ * closest line that has any mappings. Otherwise, returns all mappings
2541
+ * corresponding to the given line and either the column we are searching for
2542
+ * or the next closest column that has any offsets.
2543
+ *
2544
+ * The only argument is an object with the following properties:
2545
+ *
2546
+ * - source: The filename of the original source.
2547
+ * - line: The line number in the original source. The line number is 1-based.
2548
+ * - column: Optional. the column number in the original source.
2549
+ * The column number is 0-based.
2550
+ *
2551
+ * and an array of objects is returned, each with the following properties:
2552
+ *
2553
+ * - line: The line number in the generated source, or null. The
2554
+ * line number is 1-based.
2555
+ * - column: The column number in the generated source, or null.
2556
+ * The column number is 0-based.
2557
+ */
2558
+ SourceMapConsumer$1.prototype.allGeneratedPositionsFor =
2559
+ function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
2560
+ var line = util$1.getArg(aArgs, 'line');
2561
+
2562
+ // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
2563
+ // returns the index of the closest mapping less than the needle. By
2564
+ // setting needle.originalColumn to 0, we thus find the last mapping for
2565
+ // the given line, provided such a mapping exists.
2566
+ var needle = {
2567
+ source: util$1.getArg(aArgs, 'source'),
2568
+ originalLine: line,
2569
+ originalColumn: util$1.getArg(aArgs, 'column', 0)
2570
+ };
2571
+
2572
+ needle.source = this._findSourceIndex(needle.source);
2573
+ if (needle.source < 0) {
2574
+ return [];
2575
+ }
2576
+
2577
+ var mappings = [];
2578
+
2579
+ var index = this._findMapping(needle,
2580
+ this._originalMappings,
2581
+ "originalLine",
2582
+ "originalColumn",
2583
+ util$1.compareByOriginalPositions,
2584
+ binarySearch.LEAST_UPPER_BOUND);
2585
+ if (index >= 0) {
2586
+ var mapping = this._originalMappings[index];
2587
+
2588
+ if (aArgs.column === undefined) {
2589
+ var originalLine = mapping.originalLine;
2590
+
2591
+ // Iterate until either we run out of mappings, or we run into
2592
+ // a mapping for a different line than the one we found. Since
2593
+ // mappings are sorted, this is guaranteed to find all mappings for
2594
+ // the line we found.
2595
+ while (mapping && mapping.originalLine === originalLine) {
2596
+ mappings.push({
2597
+ line: util$1.getArg(mapping, 'generatedLine', null),
2598
+ column: util$1.getArg(mapping, 'generatedColumn', null),
2599
+ lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
2600
+ });
2601
+
2602
+ mapping = this._originalMappings[++index];
2603
+ }
2604
+ } else {
2605
+ var originalColumn = mapping.originalColumn;
2606
+
2607
+ // Iterate until either we run out of mappings, or we run into
2608
+ // a mapping for a different line than the one we were searching for.
2609
+ // Since mappings are sorted, this is guaranteed to find all mappings for
2610
+ // the line we are searching for.
2611
+ while (mapping &&
2612
+ mapping.originalLine === line &&
2613
+ mapping.originalColumn == originalColumn) {
2614
+ mappings.push({
2615
+ line: util$1.getArg(mapping, 'generatedLine', null),
2616
+ column: util$1.getArg(mapping, 'generatedColumn', null),
2617
+ lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
2618
+ });
2619
+
2620
+ mapping = this._originalMappings[++index];
2621
+ }
2622
+ }
2623
+ }
2624
+
2625
+ return mappings;
2626
+ };
2627
+
2628
+ sourceMapConsumer.SourceMapConsumer = SourceMapConsumer$1;
2629
+
2630
+ /**
2631
+ * A BasicSourceMapConsumer instance represents a parsed source map which we can
2632
+ * query for information about the original file positions by giving it a file
2633
+ * position in the generated source.
2634
+ *
2635
+ * The first parameter is the raw source map (either as a JSON string, or
2636
+ * already parsed to an object). According to the spec, source maps have the
2637
+ * following attributes:
2638
+ *
2639
+ * - version: Which version of the source map spec this map is following.
2640
+ * - sources: An array of URLs to the original source files.
2641
+ * - names: An array of identifiers which can be referrenced by individual mappings.
2642
+ * - sourceRoot: Optional. The URL root from which all sources are relative.
2643
+ * - sourcesContent: Optional. An array of contents of the original source files.
2644
+ * - mappings: A string of base64 VLQs which contain the actual mappings.
2645
+ * - file: Optional. The generated file this source map is associated with.
2646
+ *
2647
+ * Here is an example source map, taken from the source map spec[0]:
2648
+ *
2649
+ * {
2650
+ * version : 3,
2651
+ * file: "out.js",
2652
+ * sourceRoot : "",
2653
+ * sources: ["foo.js", "bar.js"],
2654
+ * names: ["src", "maps", "are", "fun"],
2655
+ * mappings: "AA,AB;;ABCDE;"
2656
+ * }
2657
+ *
2658
+ * The second parameter, if given, is a string whose value is the URL
2659
+ * at which the source map was found. This URL is used to compute the
2660
+ * sources array.
2661
+ *
2662
+ * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
2663
+ */
2664
+ function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
2665
+ var sourceMap = aSourceMap;
2666
+ if (typeof aSourceMap === 'string') {
2667
+ sourceMap = util$1.parseSourceMapInput(aSourceMap);
2668
+ }
2669
+
2670
+ var version = util$1.getArg(sourceMap, 'version');
2671
+ var sources = util$1.getArg(sourceMap, 'sources');
2672
+ // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
2673
+ // requires the array) to play nice here.
2674
+ var names = util$1.getArg(sourceMap, 'names', []);
2675
+ var sourceRoot = util$1.getArg(sourceMap, 'sourceRoot', null);
2676
+ var sourcesContent = util$1.getArg(sourceMap, 'sourcesContent', null);
2677
+ var mappings = util$1.getArg(sourceMap, 'mappings');
2678
+ var file = util$1.getArg(sourceMap, 'file', null);
2679
+
2680
+ // Once again, Sass deviates from the spec and supplies the version as a
2681
+ // string rather than a number, so we use loose equality checking here.
2682
+ if (version != this._version) {
2683
+ throw new Error('Unsupported version: ' + version);
2684
+ }
2685
+
2686
+ if (sourceRoot) {
2687
+ sourceRoot = util$1.normalize(sourceRoot);
2688
+ }
2689
+
2690
+ sources = sources
2691
+ .map(String)
2692
+ // Some source maps produce relative source paths like "./foo.js" instead of
2693
+ // "foo.js". Normalize these first so that future comparisons will succeed.
2694
+ // See bugzil.la/1090768.
2695
+ .map(util$1.normalize)
2696
+ // Always ensure that absolute sources are internally stored relative to
2697
+ // the source root, if the source root is absolute. Not doing this would
2698
+ // be particularly problematic when the source root is a prefix of the
2699
+ // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
2700
+ .map(function (source) {
2701
+ return sourceRoot && util$1.isAbsolute(sourceRoot) && util$1.isAbsolute(source)
2702
+ ? util$1.relative(sourceRoot, source)
2703
+ : source;
2704
+ });
2705
+
2706
+ // Pass `true` below to allow duplicate names and sources. While source maps
2707
+ // are intended to be compressed and deduplicated, the TypeScript compiler
2708
+ // sometimes generates source maps with duplicates in them. See Github issue
2709
+ // #72 and bugzil.la/889492.
2710
+ this._names = ArraySet.fromArray(names.map(String), true);
2711
+ this._sources = ArraySet.fromArray(sources, true);
2712
+
2713
+ this._absoluteSources = this._sources.toArray().map(function (s) {
2714
+ return util$1.computeSourceURL(sourceRoot, s, aSourceMapURL);
2715
+ });
2716
+
2717
+ this.sourceRoot = sourceRoot;
2718
+ this.sourcesContent = sourcesContent;
2719
+ this._mappings = mappings;
2720
+ this._sourceMapURL = aSourceMapURL;
2721
+ this.file = file;
2722
+ }
2723
+
2724
+ BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer$1.prototype);
2725
+ BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer$1;
2726
+
2727
+ /**
2728
+ * Utility function to find the index of a source. Returns -1 if not
2729
+ * found.
2730
+ */
2731
+ BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
2732
+ var relativeSource = aSource;
2733
+ if (this.sourceRoot != null) {
2734
+ relativeSource = util$1.relative(this.sourceRoot, relativeSource);
2735
+ }
2736
+
2737
+ if (this._sources.has(relativeSource)) {
2738
+ return this._sources.indexOf(relativeSource);
2739
+ }
2740
+
2741
+ // Maybe aSource is an absolute URL as returned by |sources|. In
2742
+ // this case we can't simply undo the transform.
2743
+ var i;
2744
+ for (i = 0; i < this._absoluteSources.length; ++i) {
2745
+ if (this._absoluteSources[i] == aSource) {
2746
+ return i;
2747
+ }
2748
+ }
2749
+
2750
+ return -1;
2751
+ };
2752
+
2753
+ /**
2754
+ * Create a BasicSourceMapConsumer from a SourceMapGenerator.
2755
+ *
2756
+ * @param SourceMapGenerator aSourceMap
2757
+ * The source map that will be consumed.
2758
+ * @param String aSourceMapURL
2759
+ * The URL at which the source map can be found (optional)
2760
+ * @returns BasicSourceMapConsumer
2761
+ */
2762
+ BasicSourceMapConsumer.fromSourceMap =
2763
+ function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
2764
+ var smc = Object.create(BasicSourceMapConsumer.prototype);
2765
+
2766
+ var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
2767
+ var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
2768
+ smc.sourceRoot = aSourceMap._sourceRoot;
2769
+ smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
2770
+ smc.sourceRoot);
2771
+ smc.file = aSourceMap._file;
2772
+ smc._sourceMapURL = aSourceMapURL;
2773
+ smc._absoluteSources = smc._sources.toArray().map(function (s) {
2774
+ return util$1.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
2775
+ });
2776
+
2777
+ // Because we are modifying the entries (by converting string sources and
2778
+ // names to indices into the sources and names ArraySets), we have to make
2779
+ // a copy of the entry or else bad things happen. Shared mutable state
2780
+ // strikes again! See github issue #191.
2781
+
2782
+ var generatedMappings = aSourceMap._mappings.toArray().slice();
2783
+ var destGeneratedMappings = smc.__generatedMappings = [];
2784
+ var destOriginalMappings = smc.__originalMappings = [];
2785
+
2786
+ for (var i = 0, length = generatedMappings.length; i < length; i++) {
2787
+ var srcMapping = generatedMappings[i];
2788
+ var destMapping = new Mapping;
2789
+ destMapping.generatedLine = srcMapping.generatedLine;
2790
+ destMapping.generatedColumn = srcMapping.generatedColumn;
2791
+
2792
+ if (srcMapping.source) {
2793
+ destMapping.source = sources.indexOf(srcMapping.source);
2794
+ destMapping.originalLine = srcMapping.originalLine;
2795
+ destMapping.originalColumn = srcMapping.originalColumn;
2796
+
2797
+ if (srcMapping.name) {
2798
+ destMapping.name = names.indexOf(srcMapping.name);
2799
+ }
2800
+
2801
+ destOriginalMappings.push(destMapping);
2802
+ }
2803
+
2804
+ destGeneratedMappings.push(destMapping);
2805
+ }
2806
+
2807
+ quickSort(smc.__originalMappings, util$1.compareByOriginalPositions);
2808
+
2809
+ return smc;
2810
+ };
2811
+
2812
+ /**
2813
+ * The version of the source mapping spec that we are consuming.
2814
+ */
2815
+ BasicSourceMapConsumer.prototype._version = 3;
2816
+
2817
+ /**
2818
+ * The list of original sources.
2819
+ */
2820
+ Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
2821
+ get: function () {
2822
+ return this._absoluteSources.slice();
2823
+ }
2824
+ });
2825
+
2826
+ /**
2827
+ * Provide the JIT with a nice shape / hidden class.
2828
+ */
2829
+ function Mapping() {
2830
+ this.generatedLine = 0;
2831
+ this.generatedColumn = 0;
2832
+ this.source = null;
2833
+ this.originalLine = null;
2834
+ this.originalColumn = null;
2835
+ this.name = null;
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
+
2844
+ const compareGenerated = util$1.compareByGeneratedPositionsDeflatedNoLine;
2845
+ function sortGenerated(array, start) {
2846
+ let l = array.length;
2847
+ let n = array.length - start;
2848
+ if (n <= 1) {
2849
+ return;
2850
+ } else if (n == 2) {
2851
+ let a = array[start];
2852
+ let b = array[start + 1];
2853
+ if (compareGenerated(a, b) > 0) {
2854
+ array[start] = b;
2855
+ array[start + 1] = a;
2856
+ }
2857
+ } else if (n < 20) {
2858
+ for (let i = start; i < l; i++) {
2859
+ for (let j = i; j > start; j--) {
2860
+ let a = array[j - 1];
2861
+ let b = array[j];
2862
+ if (compareGenerated(a, b) <= 0) {
2863
+ break;
2864
+ }
2865
+ array[j - 1] = b;
2866
+ array[j] = a;
2867
+ }
2868
+ }
2869
+ } else {
2870
+ quickSort(array, compareGenerated, start);
2871
+ }
2872
+ }
2873
+ BasicSourceMapConsumer.prototype._parseMappings =
2874
+ function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
2875
+ var generatedLine = 1;
2876
+ var previousGeneratedColumn = 0;
2877
+ var previousOriginalLine = 0;
2878
+ var previousOriginalColumn = 0;
2879
+ var previousSource = 0;
2880
+ var previousName = 0;
2881
+ var length = aStr.length;
2882
+ var index = 0;
2883
+ var temp = {};
2884
+ var originalMappings = [];
2885
+ var generatedMappings = [];
2886
+ var mapping, segment, end, value;
2887
+
2888
+ let subarrayStart = 0;
2889
+ while (index < length) {
2890
+ if (aStr.charAt(index) === ';') {
2891
+ generatedLine++;
2892
+ index++;
2893
+ previousGeneratedColumn = 0;
2894
+
2895
+ sortGenerated(generatedMappings, subarrayStart);
2896
+ subarrayStart = generatedMappings.length;
2897
+ }
2898
+ else if (aStr.charAt(index) === ',') {
2899
+ index++;
2900
+ }
2901
+ else {
2902
+ mapping = new Mapping();
2903
+ mapping.generatedLine = generatedLine;
2904
+
2905
+ for (end = index; end < length; end++) {
2906
+ if (this._charIsMappingSeparator(aStr, end)) {
2907
+ break;
2908
+ }
2909
+ }
2910
+ aStr.slice(index, end);
2911
+
2912
+ segment = [];
2913
+ while (index < end) {
2914
+ base64VLQ.decode(aStr, index, temp);
2915
+ value = temp.value;
2916
+ index = temp.rest;
2917
+ segment.push(value);
2918
+ }
2919
+
2920
+ if (segment.length === 2) {
2921
+ throw new Error('Found a source, but no line and column');
2922
+ }
2923
+
2924
+ if (segment.length === 3) {
2925
+ throw new Error('Found a source and line, but no column');
2926
+ }
2927
+
2928
+ // Generated column.
2929
+ mapping.generatedColumn = previousGeneratedColumn + segment[0];
2930
+ previousGeneratedColumn = mapping.generatedColumn;
2931
+
2932
+ if (segment.length > 1) {
2933
+ // Original source.
2934
+ mapping.source = previousSource + segment[1];
2935
+ previousSource += segment[1];
2936
+
2937
+ // Original line.
2938
+ mapping.originalLine = previousOriginalLine + segment[2];
2939
+ previousOriginalLine = mapping.originalLine;
2940
+ // Lines are stored 0-based
2941
+ mapping.originalLine += 1;
2942
+
2943
+ // Original column.
2944
+ mapping.originalColumn = previousOriginalColumn + segment[3];
2945
+ previousOriginalColumn = mapping.originalColumn;
2946
+
2947
+ if (segment.length > 4) {
2948
+ // Original name.
2949
+ mapping.name = previousName + segment[4];
2950
+ previousName += segment[4];
2951
+ }
2952
+ }
2953
+
2954
+ generatedMappings.push(mapping);
2955
+ if (typeof mapping.originalLine === 'number') {
2956
+ let currentSource = mapping.source;
2957
+ while (originalMappings.length <= currentSource) {
2958
+ originalMappings.push(null);
2959
+ }
2960
+ if (originalMappings[currentSource] === null) {
2961
+ originalMappings[currentSource] = [];
2962
+ }
2963
+ originalMappings[currentSource].push(mapping);
2964
+ }
2965
+ }
2966
+ }
2967
+
2968
+ sortGenerated(generatedMappings, subarrayStart);
2969
+ this.__generatedMappings = generatedMappings;
2970
+
2971
+ for (var i = 0; i < originalMappings.length; i++) {
2972
+ if (originalMappings[i] != null) {
2973
+ quickSort(originalMappings[i], util$1.compareByOriginalPositionsNoSource);
2974
+ }
2975
+ }
2976
+ this.__originalMappings = [].concat(...originalMappings);
2977
+ };
2978
+
2979
+ /**
2980
+ * Find the mapping that best matches the hypothetical "needle" mapping that
2981
+ * we are searching for in the given "haystack" of mappings.
2982
+ */
2983
+ BasicSourceMapConsumer.prototype._findMapping =
2984
+ function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
2985
+ aColumnName, aComparator, aBias) {
2986
+ // To return the position we are searching for, we must first find the
2987
+ // mapping for the given position and then return the opposite position it
2988
+ // points to. Because the mappings are sorted, we can use binary search to
2989
+ // find the best mapping.
2990
+
2991
+ if (aNeedle[aLineName] <= 0) {
2992
+ throw new TypeError('Line must be greater than or equal to 1, got '
2993
+ + aNeedle[aLineName]);
2994
+ }
2995
+ if (aNeedle[aColumnName] < 0) {
2996
+ throw new TypeError('Column must be greater than or equal to 0, got '
2997
+ + aNeedle[aColumnName]);
2998
+ }
2999
+
3000
+ return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
3001
+ };
3002
+
3003
+ /**
3004
+ * Compute the last column for each generated mapping. The last column is
3005
+ * inclusive.
3006
+ */
3007
+ BasicSourceMapConsumer.prototype.computeColumnSpans =
3008
+ function SourceMapConsumer_computeColumnSpans() {
3009
+ for (var index = 0; index < this._generatedMappings.length; ++index) {
3010
+ var mapping = this._generatedMappings[index];
3011
+
3012
+ // Mappings do not contain a field for the last generated columnt. We
3013
+ // can come up with an optimistic estimate, however, by assuming that
3014
+ // mappings are contiguous (i.e. given two consecutive mappings, the
3015
+ // first mapping ends where the second one starts).
3016
+ if (index + 1 < this._generatedMappings.length) {
3017
+ var nextMapping = this._generatedMappings[index + 1];
3018
+
3019
+ if (mapping.generatedLine === nextMapping.generatedLine) {
3020
+ mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
3021
+ continue;
3022
+ }
3023
+ }
3024
+
3025
+ // The last mapping for each line spans the entire line.
3026
+ mapping.lastGeneratedColumn = Infinity;
3027
+ }
3028
+ };
3029
+
3030
+ /**
3031
+ * Returns the original source, line, and column information for the generated
3032
+ * source's line and column positions provided. The only argument is an object
3033
+ * with the following properties:
3034
+ *
3035
+ * - line: The line number in the generated source. The line number
3036
+ * is 1-based.
3037
+ * - column: The column number in the generated source. The column
3038
+ * number is 0-based.
3039
+ * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
3040
+ * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
3041
+ * closest element that is smaller than or greater than the one we are
3042
+ * searching for, respectively, if the exact element cannot be found.
3043
+ * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
3044
+ *
3045
+ * and an object is returned with the following properties:
3046
+ *
3047
+ * - source: The original source file, or null.
3048
+ * - line: The line number in the original source, or null. The
3049
+ * line number is 1-based.
3050
+ * - column: The column number in the original source, or null. The
3051
+ * column number is 0-based.
3052
+ * - name: The original identifier, or null.
3053
+ */
3054
+ BasicSourceMapConsumer.prototype.originalPositionFor =
3055
+ function SourceMapConsumer_originalPositionFor(aArgs) {
3056
+ var needle = {
3057
+ generatedLine: util$1.getArg(aArgs, 'line'),
3058
+ generatedColumn: util$1.getArg(aArgs, 'column')
3059
+ };
3060
+
3061
+ var index = this._findMapping(
3062
+ needle,
3063
+ this._generatedMappings,
3064
+ "generatedLine",
3065
+ "generatedColumn",
3066
+ util$1.compareByGeneratedPositionsDeflated,
3067
+ util$1.getArg(aArgs, 'bias', SourceMapConsumer$1.GREATEST_LOWER_BOUND)
3068
+ );
3069
+
3070
+ if (index >= 0) {
3071
+ var mapping = this._generatedMappings[index];
3072
+
3073
+ if (mapping.generatedLine === needle.generatedLine) {
3074
+ var source = util$1.getArg(mapping, 'source', null);
3075
+ if (source !== null) {
3076
+ source = this._sources.at(source);
3077
+ source = util$1.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
3078
+ }
3079
+ var name = util$1.getArg(mapping, 'name', null);
3080
+ if (name !== null) {
3081
+ name = this._names.at(name);
3082
+ }
3083
+ return {
3084
+ source: source,
3085
+ line: util$1.getArg(mapping, 'originalLine', null),
3086
+ column: util$1.getArg(mapping, 'originalColumn', null),
3087
+ name: name
3088
+ };
3089
+ }
3090
+ }
3091
+
3092
+ return {
3093
+ source: null,
3094
+ line: null,
3095
+ column: null,
3096
+ name: null
3097
+ };
3098
+ };
3099
+
3100
+ /**
3101
+ * Return true if we have the source content for every source in the source
3102
+ * map, false otherwise.
3103
+ */
3104
+ BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
3105
+ function BasicSourceMapConsumer_hasContentsOfAllSources() {
3106
+ if (!this.sourcesContent) {
3107
+ return false;
3108
+ }
3109
+ return this.sourcesContent.length >= this._sources.size() &&
3110
+ !this.sourcesContent.some(function (sc) { return sc == null; });
3111
+ };
3112
+
3113
+ /**
3114
+ * Returns the original source content. The only argument is the url of the
3115
+ * original source file. Returns null if no original source content is
3116
+ * available.
3117
+ */
3118
+ BasicSourceMapConsumer.prototype.sourceContentFor =
3119
+ function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
3120
+ if (!this.sourcesContent) {
3121
+ return null;
3122
+ }
3123
+
3124
+ var index = this._findSourceIndex(aSource);
3125
+ if (index >= 0) {
3126
+ return this.sourcesContent[index];
3127
+ }
3128
+
3129
+ var relativeSource = aSource;
3130
+ if (this.sourceRoot != null) {
3131
+ relativeSource = util$1.relative(this.sourceRoot, relativeSource);
3132
+ }
3133
+
3134
+ var url;
3135
+ if (this.sourceRoot != null
3136
+ && (url = util$1.urlParse(this.sourceRoot))) {
3137
+ // XXX: file:// URIs and absolute paths lead to unexpected behavior for
3138
+ // many users. We can help them out when they expect file:// URIs to
3139
+ // behave like it would if they were running a local HTTP server. See
3140
+ // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
3141
+ var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
3142
+ if (url.scheme == "file"
3143
+ && this._sources.has(fileUriAbsPath)) {
3144
+ return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
3145
+ }
3146
+
3147
+ if ((!url.path || url.path == "/")
3148
+ && this._sources.has("/" + relativeSource)) {
3149
+ return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
3150
+ }
3151
+ }
3152
+
3153
+ // This function is used recursively from
3154
+ // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
3155
+ // don't want to throw if we can't find the source - we just want to
3156
+ // return null, so we provide a flag to exit gracefully.
3157
+ if (nullOnMissing) {
3158
+ return null;
3159
+ }
3160
+ else {
3161
+ throw new Error('"' + relativeSource + '" is not in the SourceMap.');
3162
+ }
3163
+ };
3164
+
3165
+ /**
3166
+ * Returns the generated line and column information for the original source,
3167
+ * line, and column positions provided. The only argument is an object with
3168
+ * the following properties:
3169
+ *
3170
+ * - source: The filename of the original source.
3171
+ * - line: The line number in the original source. The line number
3172
+ * is 1-based.
3173
+ * - column: The column number in the original source. The column
3174
+ * number is 0-based.
3175
+ * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
3176
+ * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
3177
+ * closest element that is smaller than or greater than the one we are
3178
+ * searching for, respectively, if the exact element cannot be found.
3179
+ * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
3180
+ *
3181
+ * and an object is returned with the following properties:
3182
+ *
3183
+ * - line: The line number in the generated source, or null. The
3184
+ * line number is 1-based.
3185
+ * - column: The column number in the generated source, or null.
3186
+ * The column number is 0-based.
3187
+ */
3188
+ BasicSourceMapConsumer.prototype.generatedPositionFor =
3189
+ function SourceMapConsumer_generatedPositionFor(aArgs) {
3190
+ var source = util$1.getArg(aArgs, 'source');
3191
+ source = this._findSourceIndex(source);
3192
+ if (source < 0) {
3193
+ return {
3194
+ line: null,
3195
+ column: null,
3196
+ lastColumn: null
3197
+ };
3198
+ }
3199
+
3200
+ var needle = {
3201
+ source: source,
3202
+ originalLine: util$1.getArg(aArgs, 'line'),
3203
+ originalColumn: util$1.getArg(aArgs, 'column')
3204
+ };
3205
+
3206
+ var index = this._findMapping(
3207
+ needle,
3208
+ this._originalMappings,
3209
+ "originalLine",
3210
+ "originalColumn",
3211
+ util$1.compareByOriginalPositions,
3212
+ util$1.getArg(aArgs, 'bias', SourceMapConsumer$1.GREATEST_LOWER_BOUND)
3213
+ );
3214
+
3215
+ if (index >= 0) {
3216
+ var mapping = this._originalMappings[index];
3217
+
3218
+ if (mapping.source === needle.source) {
3219
+ return {
3220
+ line: util$1.getArg(mapping, 'generatedLine', null),
3221
+ column: util$1.getArg(mapping, 'generatedColumn', null),
3222
+ lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
3223
+ };
3224
+ }
3225
+ }
3226
+
3227
+ return {
3228
+ line: null,
3229
+ column: null,
3230
+ lastColumn: null
3231
+ };
3232
+ };
3233
+
3234
+ sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
3235
+
3236
+ /**
3237
+ * An IndexedSourceMapConsumer instance represents a parsed source map which
3238
+ * we can query for information. It differs from BasicSourceMapConsumer in
3239
+ * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
3240
+ * input.
3241
+ *
3242
+ * The first parameter is a raw source map (either as a JSON string, or already
3243
+ * parsed to an object). According to the spec for indexed source maps, they
3244
+ * have the following attributes:
3245
+ *
3246
+ * - version: Which version of the source map spec this map is following.
3247
+ * - file: Optional. The generated file this source map is associated with.
3248
+ * - sections: A list of section definitions.
3249
+ *
3250
+ * Each value under the "sections" field has two fields:
3251
+ * - offset: The offset into the original specified at which this section
3252
+ * begins to apply, defined as an object with a "line" and "column"
3253
+ * field.
3254
+ * - map: A source map definition. This source map could also be indexed,
3255
+ * but doesn't have to be.
3256
+ *
3257
+ * Instead of the "map" field, it's also possible to have a "url" field
3258
+ * specifying a URL to retrieve a source map from, but that's currently
3259
+ * unsupported.
3260
+ *
3261
+ * Here's an example source map, taken from the source map spec[0], but
3262
+ * modified to omit a section which uses the "url" field.
3263
+ *
3264
+ * {
3265
+ * version : 3,
3266
+ * file: "app.js",
3267
+ * sections: [{
3268
+ * offset: {line:100, column:10},
3269
+ * map: {
3270
+ * version : 3,
3271
+ * file: "section.js",
3272
+ * sources: ["foo.js", "bar.js"],
3273
+ * names: ["src", "maps", "are", "fun"],
3274
+ * mappings: "AAAA,E;;ABCDE;"
3275
+ * }
3276
+ * }],
3277
+ * }
3278
+ *
3279
+ * The second parameter, if given, is a string whose value is the URL
3280
+ * at which the source map was found. This URL is used to compute the
3281
+ * sources array.
3282
+ *
3283
+ * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
3284
+ */
3285
+ function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
3286
+ var sourceMap = aSourceMap;
3287
+ if (typeof aSourceMap === 'string') {
3288
+ sourceMap = util$1.parseSourceMapInput(aSourceMap);
3289
+ }
3290
+
3291
+ var version = util$1.getArg(sourceMap, 'version');
3292
+ var sections = util$1.getArg(sourceMap, 'sections');
3293
+
3294
+ if (version != this._version) {
3295
+ throw new Error('Unsupported version: ' + version);
3296
+ }
3297
+
3298
+ this._sources = new ArraySet();
3299
+ this._names = new ArraySet();
3300
+
3301
+ var lastOffset = {
3302
+ line: -1,
3303
+ column: 0
3304
+ };
3305
+ this._sections = sections.map(function (s) {
3306
+ if (s.url) {
3307
+ // The url field will require support for asynchronicity.
3308
+ // See https://github.com/mozilla/source-map/issues/16
3309
+ throw new Error('Support for url field in sections not implemented.');
3310
+ }
3311
+ var offset = util$1.getArg(s, 'offset');
3312
+ var offsetLine = util$1.getArg(offset, 'line');
3313
+ var offsetColumn = util$1.getArg(offset, 'column');
3314
+
3315
+ if (offsetLine < lastOffset.line ||
3316
+ (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
3317
+ throw new Error('Section offsets must be ordered and non-overlapping.');
3318
+ }
3319
+ lastOffset = offset;
3320
+
3321
+ return {
3322
+ generatedOffset: {
3323
+ // The offset fields are 0-based, but we use 1-based indices when
3324
+ // encoding/decoding from VLQ.
3325
+ generatedLine: offsetLine + 1,
3326
+ generatedColumn: offsetColumn + 1
3327
+ },
3328
+ consumer: new SourceMapConsumer$1(util$1.getArg(s, 'map'), aSourceMapURL)
3329
+ }
3330
+ });
3331
+ }
3332
+
3333
+ IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer$1.prototype);
3334
+ IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer$1;
3335
+
3336
+ /**
3337
+ * The version of the source mapping spec that we are consuming.
3338
+ */
3339
+ IndexedSourceMapConsumer.prototype._version = 3;
3340
+
3341
+ /**
3342
+ * The list of original sources.
3343
+ */
3344
+ Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
3345
+ get: function () {
3346
+ var sources = [];
3347
+ for (var i = 0; i < this._sections.length; i++) {
3348
+ for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
3349
+ sources.push(this._sections[i].consumer.sources[j]);
3350
+ }
3351
+ }
3352
+ return sources;
3353
+ }
3354
+ });
3355
+
3356
+ /**
3357
+ * Returns the original source, line, and column information for the generated
3358
+ * source's line and column positions provided. The only argument is an object
3359
+ * with the following properties:
3360
+ *
3361
+ * - line: The line number in the generated source. The line number
3362
+ * is 1-based.
3363
+ * - column: The column number in the generated source. The column
3364
+ * number is 0-based.
3365
+ *
3366
+ * and an object is returned with the following properties:
3367
+ *
3368
+ * - source: The original source file, or null.
3369
+ * - line: The line number in the original source, or null. The
3370
+ * line number is 1-based.
3371
+ * - column: The column number in the original source, or null. The
3372
+ * column number is 0-based.
3373
+ * - name: The original identifier, or null.
3374
+ */
3375
+ IndexedSourceMapConsumer.prototype.originalPositionFor =
3376
+ function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
3377
+ var needle = {
3378
+ generatedLine: util$1.getArg(aArgs, 'line'),
3379
+ generatedColumn: util$1.getArg(aArgs, 'column')
3380
+ };
3381
+
3382
+ // Find the section containing the generated position we're trying to map
3383
+ // to an original position.
3384
+ var sectionIndex = binarySearch.search(needle, this._sections,
3385
+ function(needle, section) {
3386
+ var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
3387
+ if (cmp) {
3388
+ return cmp;
3389
+ }
3390
+
3391
+ return (needle.generatedColumn -
3392
+ section.generatedOffset.generatedColumn);
3393
+ });
3394
+ var section = this._sections[sectionIndex];
3395
+
3396
+ if (!section) {
3397
+ return {
3398
+ source: null,
3399
+ line: null,
3400
+ column: null,
3401
+ name: null
3402
+ };
3403
+ }
3404
+
3405
+ return section.consumer.originalPositionFor({
3406
+ line: needle.generatedLine -
3407
+ (section.generatedOffset.generatedLine - 1),
3408
+ column: needle.generatedColumn -
3409
+ (section.generatedOffset.generatedLine === needle.generatedLine
3410
+ ? section.generatedOffset.generatedColumn - 1
3411
+ : 0),
3412
+ bias: aArgs.bias
3413
+ });
3414
+ };
3415
+
3416
+ /**
3417
+ * Return true if we have the source content for every source in the source
3418
+ * map, false otherwise.
3419
+ */
3420
+ IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
3421
+ function IndexedSourceMapConsumer_hasContentsOfAllSources() {
3422
+ return this._sections.every(function (s) {
3423
+ return s.consumer.hasContentsOfAllSources();
3424
+ });
3425
+ };
3426
+
3427
+ /**
3428
+ * Returns the original source content. The only argument is the url of the
3429
+ * original source file. Returns null if no original source content is
3430
+ * available.
3431
+ */
3432
+ IndexedSourceMapConsumer.prototype.sourceContentFor =
3433
+ function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
3434
+ for (var i = 0; i < this._sections.length; i++) {
3435
+ var section = this._sections[i];
3436
+
3437
+ var content = section.consumer.sourceContentFor(aSource, true);
3438
+ if (content) {
3439
+ return content;
3440
+ }
3441
+ }
3442
+ if (nullOnMissing) {
3443
+ return null;
3444
+ }
3445
+ else {
3446
+ throw new Error('"' + aSource + '" is not in the SourceMap.');
3447
+ }
3448
+ };
3449
+
3450
+ /**
3451
+ * Returns the generated line and column information for the original source,
3452
+ * line, and column positions provided. The only argument is an object with
3453
+ * the following properties:
3454
+ *
3455
+ * - source: The filename of the original source.
3456
+ * - line: The line number in the original source. The line number
3457
+ * is 1-based.
3458
+ * - column: The column number in the original source. The column
3459
+ * number is 0-based.
3460
+ *
3461
+ * and an object is returned with the following properties:
3462
+ *
3463
+ * - line: The line number in the generated source, or null. The
3464
+ * line number is 1-based.
3465
+ * - column: The column number in the generated source, or null.
3466
+ * The column number is 0-based.
3467
+ */
3468
+ IndexedSourceMapConsumer.prototype.generatedPositionFor =
3469
+ function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
3470
+ for (var i = 0; i < this._sections.length; i++) {
3471
+ var section = this._sections[i];
3472
+
3473
+ // Only consider this section if the requested source is in the list of
3474
+ // sources of the consumer.
3475
+ if (section.consumer._findSourceIndex(util$1.getArg(aArgs, 'source')) === -1) {
3476
+ continue;
3477
+ }
3478
+ var generatedPosition = section.consumer.generatedPositionFor(aArgs);
3479
+ if (generatedPosition) {
3480
+ var ret = {
3481
+ line: generatedPosition.line +
3482
+ (section.generatedOffset.generatedLine - 1),
3483
+ column: generatedPosition.column +
3484
+ (section.generatedOffset.generatedLine === generatedPosition.line
3485
+ ? section.generatedOffset.generatedColumn - 1
3486
+ : 0)
3487
+ };
3488
+ return ret;
3489
+ }
3490
+ }
3491
+
3492
+ return {
3493
+ line: null,
3494
+ column: null
3495
+ };
3496
+ };
3497
+
3498
+ /**
3499
+ * Parse the mappings in a string in to a data structure which we can easily
3500
+ * query (the ordered arrays in the `this.__generatedMappings` and
3501
+ * `this.__originalMappings` properties).
3502
+ */
3503
+ IndexedSourceMapConsumer.prototype._parseMappings =
3504
+ function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
3505
+ this.__generatedMappings = [];
3506
+ this.__originalMappings = [];
3507
+ for (var i = 0; i < this._sections.length; i++) {
3508
+ var section = this._sections[i];
3509
+ var sectionMappings = section.consumer._generatedMappings;
3510
+ for (var j = 0; j < sectionMappings.length; j++) {
3511
+ var mapping = sectionMappings[j];
3512
+
3513
+ var source = section.consumer._sources.at(mapping.source);
3514
+ source = util$1.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
3515
+ this._sources.add(source);
3516
+ source = this._sources.indexOf(source);
3517
+
3518
+ var name = null;
3519
+ if (mapping.name) {
3520
+ name = section.consumer._names.at(mapping.name);
3521
+ this._names.add(name);
3522
+ name = this._names.indexOf(name);
3523
+ }
3524
+
3525
+ // The mappings coming from the consumer for the section have
3526
+ // generated positions relative to the start of the section, so we
3527
+ // need to offset them to be relative to the start of the concatenated
3528
+ // generated file.
3529
+ var adjustedMapping = {
3530
+ source: source,
3531
+ generatedLine: mapping.generatedLine +
3532
+ (section.generatedOffset.generatedLine - 1),
3533
+ generatedColumn: mapping.generatedColumn +
3534
+ (section.generatedOffset.generatedLine === mapping.generatedLine
3535
+ ? section.generatedOffset.generatedColumn - 1
3536
+ : 0),
3537
+ originalLine: mapping.originalLine,
3538
+ originalColumn: mapping.originalColumn,
3539
+ name: name
3540
+ };
3541
+
3542
+ this.__generatedMappings.push(adjustedMapping);
3543
+ if (typeof adjustedMapping.originalLine === 'number') {
3544
+ this.__originalMappings.push(adjustedMapping);
3545
+ }
3546
+ }
3547
+ }
3548
+
3549
+ quickSort(this.__generatedMappings, util$1.compareByGeneratedPositionsDeflated);
3550
+ quickSort(this.__originalMappings, util$1.compareByOriginalPositions);
3551
+ };
3552
+
3553
+ sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
3554
+
3555
+ /* -*- Mode: js; js-indent-level: 2; -*- */
3556
+
3557
+ /*
3558
+ * Copyright 2011 Mozilla Foundation and contributors
3559
+ * Licensed under the New BSD license. See LICENSE or:
3560
+ * http://opensource.org/licenses/BSD-3-Clause
3561
+ */
3562
+
3563
+ var SourceMapGenerator = sourceMapGenerator.SourceMapGenerator;
3564
+ var util = util$5;
3565
+
3566
+ // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
3567
+ // operating systems these days (capturing the result).
3568
+ var REGEX_NEWLINE = /(\r?\n)/;
3569
+
3570
+ // Newline character code for charCodeAt() comparisons
3571
+ var NEWLINE_CODE = 10;
3572
+
3573
+ // Private symbol for identifying `SourceNode`s when multiple versions of
3574
+ // the source-map library are loaded. This MUST NOT CHANGE across
3575
+ // versions!
3576
+ var isSourceNode = "$$$isSourceNode$$$";
3577
+
3578
+ /**
3579
+ * SourceNodes provide a way to abstract over interpolating/concatenating
3580
+ * snippets of generated JavaScript source code while maintaining the line and
3581
+ * column information associated with the original source code.
3582
+ *
3583
+ * @param aLine The original line number.
3584
+ * @param aColumn The original column number.
3585
+ * @param aSource The original source's filename.
3586
+ * @param aChunks Optional. An array of strings which are snippets of
3587
+ * generated JS, or other SourceNodes.
3588
+ * @param aName The original identifier.
3589
+ */
3590
+ function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
3591
+ this.children = [];
3592
+ this.sourceContents = {};
3593
+ this.line = aLine == null ? null : aLine;
3594
+ this.column = aColumn == null ? null : aColumn;
3595
+ this.source = aSource == null ? null : aSource;
3596
+ this.name = aName == null ? null : aName;
3597
+ this[isSourceNode] = true;
3598
+ if (aChunks != null) this.add(aChunks);
3599
+ }
3600
+
3601
+ /**
3602
+ * Creates a SourceNode from generated code and a SourceMapConsumer.
3603
+ *
3604
+ * @param aGeneratedCode The generated code
3605
+ * @param aSourceMapConsumer The SourceMap for the generated code
3606
+ * @param aRelativePath Optional. The path that relative sources in the
3607
+ * SourceMapConsumer should be relative to.
3608
+ */
3609
+ SourceNode.fromStringWithSourceMap =
3610
+ function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
3611
+ // The SourceNode we want to fill with the generated code
3612
+ // and the SourceMap
3613
+ var node = new SourceNode();
3614
+
3615
+ // All even indices of this array are one line of the generated code,
3616
+ // while all odd indices are the newlines between two adjacent lines
3617
+ // (since `REGEX_NEWLINE` captures its match).
3618
+ // Processed fragments are accessed by calling `shiftNextLine`.
3619
+ var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
3620
+ var remainingLinesIndex = 0;
3621
+ var shiftNextLine = function() {
3622
+ var lineContents = getNextLine();
3623
+ // The last line of a file might not have a newline.
3624
+ var newLine = getNextLine() || "";
3625
+ return lineContents + newLine;
3626
+
3627
+ function getNextLine() {
3628
+ return remainingLinesIndex < remainingLines.length ?
3629
+ remainingLines[remainingLinesIndex++] : undefined;
3630
+ }
3631
+ };
3632
+
3633
+ // We need to remember the position of "remainingLines"
3634
+ var lastGeneratedLine = 1, lastGeneratedColumn = 0;
3635
+
3636
+ // The generate SourceNodes we need a code range.
3637
+ // To extract it current and last mapping is used.
3638
+ // Here we store the last mapping.
3639
+ var lastMapping = null;
3640
+
3641
+ aSourceMapConsumer.eachMapping(function (mapping) {
3642
+ if (lastMapping !== null) {
3643
+ // We add the code from "lastMapping" to "mapping":
3644
+ // First check if there is a new line in between.
3645
+ if (lastGeneratedLine < mapping.generatedLine) {
3646
+ // Associate first line with "lastMapping"
3647
+ addMappingWithCode(lastMapping, shiftNextLine());
3648
+ lastGeneratedLine++;
3649
+ lastGeneratedColumn = 0;
3650
+ // The remaining code is added without mapping
3651
+ } else {
3652
+ // There is no new line in between.
3653
+ // Associate the code between "lastGeneratedColumn" and
3654
+ // "mapping.generatedColumn" with "lastMapping"
3655
+ var nextLine = remainingLines[remainingLinesIndex] || '';
3656
+ var code = nextLine.substr(0, mapping.generatedColumn -
3657
+ lastGeneratedColumn);
3658
+ remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
3659
+ lastGeneratedColumn);
3660
+ lastGeneratedColumn = mapping.generatedColumn;
3661
+ addMappingWithCode(lastMapping, code);
3662
+ // No more remaining code, continue
3663
+ lastMapping = mapping;
3664
+ return;
3665
+ }
3666
+ }
3667
+ // We add the generated code until the first mapping
3668
+ // to the SourceNode without any mapping.
3669
+ // Each line is added as separate string.
3670
+ while (lastGeneratedLine < mapping.generatedLine) {
3671
+ node.add(shiftNextLine());
3672
+ lastGeneratedLine++;
3673
+ }
3674
+ if (lastGeneratedColumn < mapping.generatedColumn) {
3675
+ var nextLine = remainingLines[remainingLinesIndex] || '';
3676
+ node.add(nextLine.substr(0, mapping.generatedColumn));
3677
+ remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
3678
+ lastGeneratedColumn = mapping.generatedColumn;
3679
+ }
3680
+ lastMapping = mapping;
3681
+ }, this);
3682
+ // We have processed all mappings.
3683
+ if (remainingLinesIndex < remainingLines.length) {
3684
+ if (lastMapping) {
3685
+ // Associate the remaining code in the current line with "lastMapping"
3686
+ addMappingWithCode(lastMapping, shiftNextLine());
3687
+ }
3688
+ // and add the remaining lines without any mapping
3689
+ node.add(remainingLines.splice(remainingLinesIndex).join(""));
3690
+ }
3691
+
3692
+ // Copy sourcesContent into SourceNode
3693
+ aSourceMapConsumer.sources.forEach(function (sourceFile) {
3694
+ var content = aSourceMapConsumer.sourceContentFor(sourceFile);
3695
+ if (content != null) {
3696
+ if (aRelativePath != null) {
3697
+ sourceFile = util.join(aRelativePath, sourceFile);
3698
+ }
3699
+ node.setSourceContent(sourceFile, content);
3700
+ }
3701
+ });
3702
+
3703
+ return node;
3704
+
3705
+ function addMappingWithCode(mapping, code) {
3706
+ if (mapping === null || mapping.source === undefined) {
3707
+ node.add(code);
3708
+ } else {
3709
+ var source = aRelativePath
3710
+ ? util.join(aRelativePath, mapping.source)
3711
+ : mapping.source;
3712
+ node.add(new SourceNode(mapping.originalLine,
3713
+ mapping.originalColumn,
3714
+ source,
3715
+ code,
3716
+ mapping.name));
3717
+ }
3718
+ }
3719
+ };
3720
+
3721
+ /**
3722
+ * Add a chunk of generated JS to this source node.
3723
+ *
3724
+ * @param aChunk A string snippet of generated JS code, another instance of
3725
+ * SourceNode, or an array where each member is one of those things.
3726
+ */
3727
+ SourceNode.prototype.add = function SourceNode_add(aChunk) {
3728
+ if (Array.isArray(aChunk)) {
3729
+ aChunk.forEach(function (chunk) {
3730
+ this.add(chunk);
3731
+ }, this);
3732
+ }
3733
+ else if (aChunk[isSourceNode] || typeof aChunk === "string") {
3734
+ if (aChunk) {
3735
+ this.children.push(aChunk);
3736
+ }
3737
+ }
3738
+ else {
3739
+ throw new TypeError(
3740
+ "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
3741
+ );
3742
+ }
3743
+ return this;
3744
+ };
3745
+
3746
+ /**
3747
+ * Add a chunk of generated JS to the beginning of this source node.
3748
+ *
3749
+ * @param aChunk A string snippet of generated JS code, another instance of
3750
+ * SourceNode, or an array where each member is one of those things.
3751
+ */
3752
+ SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
3753
+ if (Array.isArray(aChunk)) {
3754
+ for (var i = aChunk.length-1; i >= 0; i--) {
3755
+ this.prepend(aChunk[i]);
3756
+ }
3757
+ }
3758
+ else if (aChunk[isSourceNode] || typeof aChunk === "string") {
3759
+ this.children.unshift(aChunk);
3760
+ }
3761
+ else {
3762
+ throw new TypeError(
3763
+ "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
3764
+ );
3765
+ }
3766
+ return this;
3767
+ };
3768
+
3769
+ /**
3770
+ * Walk over the tree of JS snippets in this node and its children. The
3771
+ * walking function is called once for each snippet of JS and is passed that
3772
+ * snippet and the its original associated source's line/column location.
3773
+ *
3774
+ * @param aFn The traversal function.
3775
+ */
3776
+ SourceNode.prototype.walk = function SourceNode_walk(aFn) {
3777
+ var chunk;
3778
+ for (var i = 0, len = this.children.length; i < len; i++) {
3779
+ chunk = this.children[i];
3780
+ if (chunk[isSourceNode]) {
3781
+ chunk.walk(aFn);
3782
+ }
3783
+ else {
3784
+ if (chunk !== '') {
3785
+ aFn(chunk, { source: this.source,
3786
+ line: this.line,
3787
+ column: this.column,
3788
+ name: this.name });
3789
+ }
3790
+ }
3791
+ }
3792
+ };
3793
+
3794
+ /**
3795
+ * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
3796
+ * each of `this.children`.
3797
+ *
3798
+ * @param aSep The separator.
3799
+ */
3800
+ SourceNode.prototype.join = function SourceNode_join(aSep) {
3801
+ var newChildren;
3802
+ var i;
3803
+ var len = this.children.length;
3804
+ if (len > 0) {
3805
+ newChildren = [];
3806
+ for (i = 0; i < len-1; i++) {
3807
+ newChildren.push(this.children[i]);
3808
+ newChildren.push(aSep);
3809
+ }
3810
+ newChildren.push(this.children[i]);
3811
+ this.children = newChildren;
3812
+ }
3813
+ return this;
3814
+ };
3815
+
3816
+ /**
3817
+ * Call String.prototype.replace on the very right-most source snippet. Useful
3818
+ * for trimming whitespace from the end of a source node, etc.
3819
+ *
3820
+ * @param aPattern The pattern to replace.
3821
+ * @param aReplacement The thing to replace the pattern with.
3822
+ */
3823
+ SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
3824
+ var lastChild = this.children[this.children.length - 1];
3825
+ if (lastChild[isSourceNode]) {
3826
+ lastChild.replaceRight(aPattern, aReplacement);
3827
+ }
3828
+ else if (typeof lastChild === 'string') {
3829
+ this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
3830
+ }
3831
+ else {
3832
+ this.children.push(''.replace(aPattern, aReplacement));
3833
+ }
3834
+ return this;
3835
+ };
3836
+
3837
+ /**
3838
+ * Set the source content for a source file. This will be added to the SourceMapGenerator
3839
+ * in the sourcesContent field.
3840
+ *
3841
+ * @param aSourceFile The filename of the source file
3842
+ * @param aSourceContent The content of the source file
3843
+ */
3844
+ SourceNode.prototype.setSourceContent =
3845
+ function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
3846
+ this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
3847
+ };
3848
+
3849
+ /**
3850
+ * Walk over the tree of SourceNodes. The walking function is called for each
3851
+ * source file content and is passed the filename and source content.
3852
+ *
3853
+ * @param aFn The traversal function.
3854
+ */
3855
+ SourceNode.prototype.walkSourceContents =
3856
+ function SourceNode_walkSourceContents(aFn) {
3857
+ for (var i = 0, len = this.children.length; i < len; i++) {
3858
+ if (this.children[i][isSourceNode]) {
3859
+ this.children[i].walkSourceContents(aFn);
3860
+ }
3861
+ }
3862
+
3863
+ var sources = Object.keys(this.sourceContents);
3864
+ for (var i = 0, len = sources.length; i < len; i++) {
3865
+ aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
3866
+ }
3867
+ };
3868
+
3869
+ /**
3870
+ * Return the string representation of this source node. Walks over the tree
3871
+ * and concatenates all the various snippets together to one string.
3872
+ */
3873
+ SourceNode.prototype.toString = function SourceNode_toString() {
3874
+ var str = "";
3875
+ this.walk(function (chunk) {
3876
+ str += chunk;
3877
+ });
3878
+ return str;
3879
+ };
3880
+
3881
+ /**
3882
+ * Returns the string representation of this source node along with a source
3883
+ * map.
3884
+ */
3885
+ SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
3886
+ var generated = {
3887
+ code: "",
3888
+ line: 1,
3889
+ column: 0
3890
+ };
3891
+ var map = new SourceMapGenerator(aArgs);
3892
+ var sourceMappingActive = false;
3893
+ var lastOriginalSource = null;
3894
+ var lastOriginalLine = null;
3895
+ var lastOriginalColumn = null;
3896
+ var lastOriginalName = null;
3897
+ this.walk(function (chunk, original) {
3898
+ generated.code += chunk;
3899
+ if (original.source !== null
3900
+ && original.line !== null
3901
+ && original.column !== null) {
3902
+ if(lastOriginalSource !== original.source
3903
+ || lastOriginalLine !== original.line
3904
+ || lastOriginalColumn !== original.column
3905
+ || lastOriginalName !== original.name) {
3906
+ map.addMapping({
3907
+ source: original.source,
3908
+ original: {
3909
+ line: original.line,
3910
+ column: original.column
3911
+ },
3912
+ generated: {
3913
+ line: generated.line,
3914
+ column: generated.column
3915
+ },
3916
+ name: original.name
3917
+ });
3918
+ }
3919
+ lastOriginalSource = original.source;
3920
+ lastOriginalLine = original.line;
3921
+ lastOriginalColumn = original.column;
3922
+ lastOriginalName = original.name;
3923
+ sourceMappingActive = true;
3924
+ } else if (sourceMappingActive) {
3925
+ map.addMapping({
3926
+ generated: {
3927
+ line: generated.line,
3928
+ column: generated.column
3929
+ }
3930
+ });
3931
+ lastOriginalSource = null;
3932
+ sourceMappingActive = false;
3933
+ }
3934
+ for (var idx = 0, length = chunk.length; idx < length; idx++) {
3935
+ if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
3936
+ generated.line++;
3937
+ generated.column = 0;
3938
+ // Mappings end at eol
3939
+ if (idx + 1 === length) {
3940
+ lastOriginalSource = null;
3941
+ sourceMappingActive = false;
3942
+ } else if (sourceMappingActive) {
3943
+ map.addMapping({
3944
+ source: original.source,
3945
+ original: {
3946
+ line: original.line,
3947
+ column: original.column
3948
+ },
3949
+ generated: {
3950
+ line: generated.line,
3951
+ column: generated.column
3952
+ },
3953
+ name: original.name
3954
+ });
3955
+ }
3956
+ } else {
3957
+ generated.column++;
3958
+ }
3959
+ }
3960
+ });
3961
+ this.walkSourceContents(function (sourceFile, sourceContent) {
3962
+ map.setSourceContent(sourceFile, sourceContent);
3963
+ });
3964
+
3965
+ return { code: generated.code, map: map };
3966
+ };
3967
+
3968
+ /*
3969
+ * Copyright 2009-2011 Mozilla Foundation and contributors
3970
+ * Licensed under the New BSD license. See LICENSE.txt or:
3971
+ * http://opensource.org/licenses/BSD-3-Clause
3972
+ */
3973
+ var SourceMapConsumer = sourceMapConsumer.SourceMapConsumer;
3974
+
3975
+ /* eslint-disable yoda */
3976
+
3977
+ function isFullwidthCodePoint(codePoint) {
3978
+ if (!Number.isInteger(codePoint)) {
3979
+ return false;
3980
+ }
3981
+
3982
+ // Code points are derived from:
3983
+ // https://unicode.org/Public/UNIDATA/EastAsianWidth.txt
3984
+ return codePoint >= 0x1100 && (
3985
+ codePoint <= 0x115F || // Hangul Jamo
3986
+ codePoint === 0x2329 || // LEFT-POINTING ANGLE BRACKET
3987
+ codePoint === 0x232A || // RIGHT-POINTING ANGLE BRACKET
3988
+ // CJK Radicals Supplement .. Enclosed CJK Letters and Months
3989
+ (0x2E80 <= codePoint && codePoint <= 0x3247 && codePoint !== 0x303F) ||
3990
+ // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A
3991
+ (0x3250 <= codePoint && codePoint <= 0x4DBF) ||
3992
+ // CJK Unified Ideographs .. Yi Radicals
3993
+ (0x4E00 <= codePoint && codePoint <= 0xA4C6) ||
3994
+ // Hangul Jamo Extended-A
3995
+ (0xA960 <= codePoint && codePoint <= 0xA97C) ||
3996
+ // Hangul Syllables
3997
+ (0xAC00 <= codePoint && codePoint <= 0xD7A3) ||
3998
+ // CJK Compatibility Ideographs
3999
+ (0xF900 <= codePoint && codePoint <= 0xFAFF) ||
4000
+ // Vertical Forms
4001
+ (0xFE10 <= codePoint && codePoint <= 0xFE19) ||
4002
+ // CJK Compatibility Forms .. Small Form Variants
4003
+ (0xFE30 <= codePoint && codePoint <= 0xFE6B) ||
4004
+ // Halfwidth and Fullwidth Forms
4005
+ (0xFF01 <= codePoint && codePoint <= 0xFF60) ||
4006
+ (0xFFE0 <= codePoint && codePoint <= 0xFFE6) ||
4007
+ // Kana Supplement
4008
+ (0x1B000 <= codePoint && codePoint <= 0x1B001) ||
4009
+ // Enclosed Ideographic Supplement
4010
+ (0x1F200 <= codePoint && codePoint <= 0x1F251) ||
4011
+ // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane
4012
+ (0x20000 <= codePoint && codePoint <= 0x3FFFD)
4013
+ );
4014
+ }
4015
+
4016
+ const ANSI_BACKGROUND_OFFSET = 10;
4017
+
4018
+ const wrapAnsi16 = (offset = 0) => code => `\u001B[${code + offset}m`;
4019
+
4020
+ const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
4021
+
4022
+ const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
4023
+
4024
+ function assembleStyles() {
4025
+ const codes = new Map();
4026
+ const styles = {
4027
+ modifier: {
4028
+ reset: [0, 0],
4029
+ // 21 isn't widely supported and 22 does the same thing
4030
+ bold: [1, 22],
4031
+ dim: [2, 22],
4032
+ italic: [3, 23],
4033
+ underline: [4, 24],
4034
+ overline: [53, 55],
4035
+ inverse: [7, 27],
4036
+ hidden: [8, 28],
4037
+ strikethrough: [9, 29]
4038
+ },
4039
+ color: {
4040
+ black: [30, 39],
4041
+ red: [31, 39],
4042
+ green: [32, 39],
4043
+ yellow: [33, 39],
4044
+ blue: [34, 39],
4045
+ magenta: [35, 39],
4046
+ cyan: [36, 39],
4047
+ white: [37, 39],
4048
+
4049
+ // Bright color
4050
+ blackBright: [90, 39],
4051
+ redBright: [91, 39],
4052
+ greenBright: [92, 39],
4053
+ yellowBright: [93, 39],
4054
+ blueBright: [94, 39],
4055
+ magentaBright: [95, 39],
4056
+ cyanBright: [96, 39],
4057
+ whiteBright: [97, 39]
4058
+ },
4059
+ bgColor: {
4060
+ bgBlack: [40, 49],
4061
+ bgRed: [41, 49],
4062
+ bgGreen: [42, 49],
4063
+ bgYellow: [43, 49],
4064
+ bgBlue: [44, 49],
4065
+ bgMagenta: [45, 49],
4066
+ bgCyan: [46, 49],
4067
+ bgWhite: [47, 49],
4068
+
4069
+ // Bright color
4070
+ bgBlackBright: [100, 49],
4071
+ bgRedBright: [101, 49],
4072
+ bgGreenBright: [102, 49],
4073
+ bgYellowBright: [103, 49],
4074
+ bgBlueBright: [104, 49],
4075
+ bgMagentaBright: [105, 49],
4076
+ bgCyanBright: [106, 49],
4077
+ bgWhiteBright: [107, 49]
4078
+ }
4079
+ };
4080
+
4081
+ // Alias bright black as gray (and grey)
4082
+ styles.color.gray = styles.color.blackBright;
4083
+ styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
4084
+ styles.color.grey = styles.color.blackBright;
4085
+ styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
4086
+
4087
+ for (const [groupName, group] of Object.entries(styles)) {
4088
+ for (const [styleName, style] of Object.entries(group)) {
4089
+ styles[styleName] = {
4090
+ open: `\u001B[${style[0]}m`,
4091
+ close: `\u001B[${style[1]}m`
4092
+ };
4093
+
4094
+ group[styleName] = styles[styleName];
4095
+
4096
+ codes.set(style[0], style[1]);
4097
+ }
4098
+
4099
+ Object.defineProperty(styles, groupName, {
4100
+ value: group,
4101
+ enumerable: false
4102
+ });
4103
+ }
4104
+
4105
+ Object.defineProperty(styles, 'codes', {
4106
+ value: codes,
4107
+ enumerable: false
4108
+ });
4109
+
4110
+ styles.color.close = '\u001B[39m';
4111
+ styles.bgColor.close = '\u001B[49m';
4112
+
4113
+ styles.color.ansi = wrapAnsi16();
4114
+ styles.color.ansi256 = wrapAnsi256();
4115
+ styles.color.ansi16m = wrapAnsi16m();
4116
+ styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
4117
+ styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
4118
+ styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
4119
+
4120
+ // From https://github.com/Qix-/color-convert/blob/3f0e0d4e92e235796ccb17f6e85c72094a651f49/conversions.js
4121
+ Object.defineProperties(styles, {
4122
+ rgbToAnsi256: {
4123
+ value: (red, green, blue) => {
4124
+ // We use the extended greyscale palette here, with the exception of
4125
+ // black and white. normal palette only has 4 greyscale shades.
4126
+ if (red === green && green === blue) {
4127
+ if (red < 8) {
4128
+ return 16;
4129
+ }
4130
+
4131
+ if (red > 248) {
4132
+ return 231;
4133
+ }
4134
+
4135
+ return Math.round(((red - 8) / 247) * 24) + 232;
4136
+ }
4137
+
4138
+ return 16 +
4139
+ (36 * Math.round(red / 255 * 5)) +
4140
+ (6 * Math.round(green / 255 * 5)) +
4141
+ Math.round(blue / 255 * 5);
4142
+ },
4143
+ enumerable: false
4144
+ },
4145
+ hexToRgb: {
4146
+ value: hex => {
4147
+ const matches = /(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16));
4148
+ if (!matches) {
4149
+ return [0, 0, 0];
4150
+ }
4151
+
4152
+ let {colorString} = matches.groups;
4153
+
4154
+ if (colorString.length === 3) {
4155
+ colorString = colorString.split('').map(character => character + character).join('');
4156
+ }
4157
+
4158
+ const integer = Number.parseInt(colorString, 16);
4159
+
4160
+ return [
4161
+ (integer >> 16) & 0xFF,
4162
+ (integer >> 8) & 0xFF,
4163
+ integer & 0xFF
4164
+ ];
4165
+ },
4166
+ enumerable: false
4167
+ },
4168
+ hexToAnsi256: {
4169
+ value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
4170
+ enumerable: false
4171
+ },
4172
+ ansi256ToAnsi: {
4173
+ value: code => {
4174
+ if (code < 8) {
4175
+ return 30 + code;
4176
+ }
4177
+
4178
+ if (code < 16) {
4179
+ return 90 + (code - 8);
4180
+ }
4181
+
4182
+ let red;
4183
+ let green;
4184
+ let blue;
4185
+
4186
+ if (code >= 232) {
4187
+ red = (((code - 232) * 10) + 8) / 255;
4188
+ green = red;
4189
+ blue = red;
4190
+ } else {
4191
+ code -= 16;
4192
+
4193
+ const remainder = code % 36;
4194
+
4195
+ red = Math.floor(code / 36) / 5;
4196
+ green = Math.floor(remainder / 6) / 5;
4197
+ blue = (remainder % 6) / 5;
4198
+ }
4199
+
4200
+ const value = Math.max(red, green, blue) * 2;
4201
+
4202
+ if (value === 0) {
4203
+ return 30;
4204
+ }
4205
+
4206
+ let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
4207
+
4208
+ if (value === 2) {
4209
+ result += 60;
4210
+ }
4211
+
4212
+ return result;
4213
+ },
4214
+ enumerable: false
4215
+ },
4216
+ rgbToAnsi: {
4217
+ value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
4218
+ enumerable: false
4219
+ },
4220
+ hexToAnsi: {
4221
+ value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
4222
+ enumerable: false
4223
+ }
4224
+ });
4225
+
4226
+ return styles;
4227
+ }
4228
+
4229
+ const ansiStyles = assembleStyles();
4230
+
4231
+ const astralRegex = /^[\uD800-\uDBFF][\uDC00-\uDFFF]$/;
4232
+
4233
+ const ESCAPES = [
4234
+ '\u001B',
4235
+ '\u009B'
4236
+ ];
4237
+
4238
+ const wrapAnsi = code => `${ESCAPES[0]}[${code}m`;
4239
+
4240
+ const checkAnsi = (ansiCodes, isEscapes, endAnsiCode) => {
4241
+ let output = [];
4242
+ ansiCodes = [...ansiCodes];
4243
+
4244
+ for (let ansiCode of ansiCodes) {
4245
+ const ansiCodeOrigin = ansiCode;
4246
+ if (ansiCode.includes(';')) {
4247
+ ansiCode = ansiCode.split(';')[0][0] + '0';
4248
+ }
4249
+
4250
+ const item = ansiStyles.codes.get(Number.parseInt(ansiCode, 10));
4251
+ if (item) {
4252
+ const indexEscape = ansiCodes.indexOf(item.toString());
4253
+ if (indexEscape === -1) {
4254
+ output.push(wrapAnsi(isEscapes ? item : ansiCodeOrigin));
4255
+ } else {
4256
+ ansiCodes.splice(indexEscape, 1);
4257
+ }
4258
+ } else if (isEscapes) {
4259
+ output.push(wrapAnsi(0));
4260
+ break;
4261
+ } else {
4262
+ output.push(wrapAnsi(ansiCodeOrigin));
4263
+ }
4264
+ }
4265
+
4266
+ if (isEscapes) {
4267
+ output = output.filter((element, index) => output.indexOf(element) === index);
4268
+
4269
+ if (endAnsiCode !== undefined) {
4270
+ const fistEscapeCode = wrapAnsi(ansiStyles.codes.get(Number.parseInt(endAnsiCode, 10)));
4271
+ // TODO: Remove the use of `.reduce` here.
4272
+ // eslint-disable-next-line unicorn/no-array-reduce
4273
+ output = output.reduce((current, next) => next === fistEscapeCode ? [next, ...current] : [...current, next], []);
4274
+ }
4275
+ }
4276
+
4277
+ return output.join('');
4278
+ };
4279
+
4280
+ function sliceAnsi(string, begin, end) {
4281
+ const characters = [...string];
4282
+ const ansiCodes = [];
4283
+
4284
+ let stringEnd = typeof end === 'number' ? end : characters.length;
4285
+ let isInsideEscape = false;
4286
+ let ansiCode;
4287
+ let visible = 0;
4288
+ let output = '';
4289
+
4290
+ for (const [index, character] of characters.entries()) {
4291
+ let leftEscape = false;
4292
+
4293
+ if (ESCAPES.includes(character)) {
4294
+ const code = /\d[^m]*/.exec(string.slice(index, index + 18));
4295
+ ansiCode = code && code.length > 0 ? code[0] : undefined;
4296
+
4297
+ if (visible < stringEnd) {
4298
+ isInsideEscape = true;
4299
+
4300
+ if (ansiCode !== undefined) {
4301
+ ansiCodes.push(ansiCode);
4302
+ }
4303
+ }
4304
+ } else if (isInsideEscape && character === 'm') {
4305
+ isInsideEscape = false;
4306
+ leftEscape = true;
4307
+ }
4308
+
4309
+ if (!isInsideEscape && !leftEscape) {
4310
+ visible++;
4311
+ }
4312
+
4313
+ if (!astralRegex.test(character) && isFullwidthCodePoint(character.codePointAt())) {
4314
+ visible++;
4315
+
4316
+ if (typeof end !== 'number') {
4317
+ stringEnd++;
4318
+ }
4319
+ }
4320
+
4321
+ if (visible > begin && visible <= stringEnd) {
4322
+ output += character;
4323
+ } else if (visible === begin && !isInsideEscape && ansiCode !== undefined) {
4324
+ output = checkAnsi(ansiCodes);
4325
+ } else if (visible >= stringEnd) {
4326
+ output += checkAnsi(ansiCodes, true, ansiCode);
4327
+ break;
4328
+ }
4329
+ }
4330
+
4331
+ return output;
4332
+ }
4333
+
4334
+ function ansiRegex({onlyFirst = false} = {}) {
4335
+ const pattern = [
4336
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
4337
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
4338
+ ].join('|');
4339
+
4340
+ return new RegExp(pattern, onlyFirst ? undefined : 'g');
4341
+ }
4342
+
4343
+ function stripAnsi(string) {
4344
+ if (typeof string !== 'string') {
4345
+ throw new TypeError(`Expected a \`string\`, got \`${typeof string}\``);
4346
+ }
4347
+
4348
+ return string.replace(ansiRegex(), '');
4349
+ }
4350
+
4351
+ var emojiRegex = function () {
4352
+ // https://mths.be/emoji
4353
+ return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
4354
+ };
4355
+
4356
+ function stringWidth(string) {
4357
+ if (typeof string !== 'string' || string.length === 0) {
4358
+ return 0;
4359
+ }
4360
+
4361
+ string = stripAnsi(string);
4362
+
4363
+ if (string.length === 0) {
4364
+ return 0;
4365
+ }
4366
+
4367
+ string = string.replace(emojiRegex(), ' ');
4368
+
4369
+ let width = 0;
4370
+
4371
+ for (let index = 0; index < string.length; index++) {
4372
+ const codePoint = string.codePointAt(index);
4373
+
4374
+ // Ignore control characters
4375
+ if (codePoint <= 0x1F || (codePoint >= 0x7F && codePoint <= 0x9F)) {
4376
+ continue;
4377
+ }
4378
+
4379
+ // Ignore combining characters
4380
+ if (codePoint >= 0x300 && codePoint <= 0x36F) {
4381
+ continue;
4382
+ }
4383
+
4384
+ // Surrogates
4385
+ if (codePoint > 0xFFFF) {
4386
+ index++;
4387
+ }
4388
+
4389
+ width += isFullwidthCodePoint(codePoint) ? 2 : 1;
4390
+ }
4391
+
4392
+ return width;
4393
+ }
4394
+
4395
+ function getIndexOfNearestSpace(string, wantedIndex, shouldSearchRight) {
4396
+ if (string.charAt(wantedIndex) === ' ') {
4397
+ return wantedIndex;
4398
+ }
4399
+
4400
+ for (let index = 1; index <= 3; index++) {
4401
+ if (shouldSearchRight) {
4402
+ if (string.charAt(wantedIndex + index) === ' ') {
4403
+ return wantedIndex + index;
4404
+ }
4405
+ } else if (string.charAt(wantedIndex - index) === ' ') {
4406
+ return wantedIndex - index;
4407
+ }
4408
+ }
4409
+
4410
+ return wantedIndex;
4411
+ }
4412
+
4413
+ function cliTruncate(text, columns, options) {
4414
+ options = {
4415
+ position: 'end',
4416
+ preferTruncationOnSpace: false,
4417
+ truncationCharacter: '…',
4418
+ ...options,
4419
+ };
4420
+
4421
+ const {position, space, preferTruncationOnSpace} = options;
4422
+ let {truncationCharacter} = options;
4423
+
4424
+ if (typeof text !== 'string') {
4425
+ throw new TypeError(`Expected \`input\` to be a string, got ${typeof text}`);
4426
+ }
4427
+
4428
+ if (typeof columns !== 'number') {
4429
+ throw new TypeError(`Expected \`columns\` to be a number, got ${typeof columns}`);
4430
+ }
4431
+
4432
+ if (columns < 1) {
4433
+ return '';
4434
+ }
4435
+
4436
+ if (columns === 1) {
4437
+ return truncationCharacter;
4438
+ }
4439
+
4440
+ const length = stringWidth(text);
4441
+
4442
+ if (length <= columns) {
4443
+ return text;
4444
+ }
4445
+
4446
+ if (position === 'start') {
4447
+ if (preferTruncationOnSpace) {
4448
+ const nearestSpace = getIndexOfNearestSpace(text, length - columns + 1, true);
4449
+ return truncationCharacter + sliceAnsi(text, nearestSpace, length).trim();
4450
+ }
4451
+
4452
+ if (space === true) {
4453
+ truncationCharacter += ' ';
4454
+ }
4455
+
4456
+ return truncationCharacter + sliceAnsi(text, length - columns + stringWidth(truncationCharacter), length);
4457
+ }
4458
+
4459
+ if (position === 'middle') {
4460
+ if (space === true) {
4461
+ truncationCharacter = ` ${truncationCharacter} `;
4462
+ }
4463
+
4464
+ const half = Math.floor(columns / 2);
4465
+
4466
+ if (preferTruncationOnSpace) {
4467
+ const spaceNearFirstBreakPoint = getIndexOfNearestSpace(text, half);
4468
+ const spaceNearSecondBreakPoint = getIndexOfNearestSpace(text, length - (columns - half) + 1, true);
4469
+ return sliceAnsi(text, 0, spaceNearFirstBreakPoint) + truncationCharacter + sliceAnsi(text, spaceNearSecondBreakPoint, length).trim();
4470
+ }
4471
+
4472
+ return (
4473
+ sliceAnsi(text, 0, half)
4474
+ + truncationCharacter
4475
+ + sliceAnsi(text, length - (columns - half) + stringWidth(truncationCharacter), length)
4476
+ );
4477
+ }
4478
+
4479
+ if (position === 'end') {
4480
+ if (preferTruncationOnSpace) {
4481
+ const nearestSpace = getIndexOfNearestSpace(text, columns - 1);
4482
+ return sliceAnsi(text, 0, nearestSpace) + truncationCharacter;
4483
+ }
4484
+
4485
+ if (space === true) {
4486
+ truncationCharacter = ` ${truncationCharacter}`;
4487
+ }
4488
+
4489
+ return sliceAnsi(text, 0, columns - stringWidth(truncationCharacter)) + truncationCharacter;
4490
+ }
4491
+
4492
+ throw new Error(`Expected \`options.position\` to be either \`start\`, \`middle\` or \`end\`, got ${position}`);
4493
+ }
4494
+
4495
+ const F_RIGHT = "\u2192";
4496
+ const F_DOWN = "\u2193";
4497
+ const F_DOWN_RIGHT = "\u21B3";
4498
+ const F_POINTER = "\u276F";
4499
+ const F_DOT = "\xB7";
4500
+ const F_CHECK = "\u221A";
4501
+ const F_CROSS = "\xD7";
4502
+ const F_LONG_DASH = "\u23AF";
4503
+
4504
+ async function printError(error, ctx) {
4505
+ let e = error;
4506
+ if (typeof error === "string") {
4507
+ e = {
4508
+ message: error.split(/\n/g)[0],
4509
+ stack: error
4510
+ };
4511
+ }
4512
+ const stackStr = e.stack || e.stackStr || "";
4513
+ const stacks = parseStack(stackStr);
4514
+ if (!stacks.length) {
4515
+ ctx.console.error(e);
4516
+ } else {
4517
+ const nearest = stacks.find((stack) => {
4518
+ return !stack.file.includes("vitest/dist") && ctx.server.moduleGraph.getModuleById(stack.file) && existsSync(stack.file);
4519
+ });
4520
+ printErrorMessage(e);
4521
+ await printStack(ctx, stacks, nearest, async (s, pos) => {
4522
+ if (s === nearest) {
4523
+ const sourceCode = await promises.readFile(nearest.file, "utf-8");
4524
+ ctx.console.log(c.yellow(generateCodeFrame(sourceCode, 4, pos)));
4525
+ }
4526
+ });
4527
+ }
4528
+ handleImportOutsideModuleError(stackStr, ctx);
4529
+ if (e.showDiff)
4530
+ displayDiff(e.actual, e.expected);
4531
+ }
4532
+ const esmErrors = [
4533
+ "Cannot use import statement outside a module",
4534
+ "Unexpected token 'export'"
4535
+ ];
4536
+ function handleImportOutsideModuleError(stack, ctx) {
4537
+ if (!esmErrors.some((e) => stack.includes(e)))
4538
+ return;
4539
+ const path = stack.split("\n")[0].trim();
4540
+ let name = path.split("/node_modules/").pop() || "";
4541
+ if (name == null ? void 0 : name.startsWith("@"))
4542
+ name = name.split("/").slice(0, 2).join("/");
4543
+ else
4544
+ name = name.split("/")[0];
4545
+ ctx.console.error(c.yellow(`Module ${path} seems to be an ES Module but shipped in a CommonJS package. You might want to create an issue to the package ${c.bold(`"${name}"`)} asking them to ship the file in .mjs extension or add "type": "module" in their package.json.
4546
+
4547
+ As a temporary workaround you can try to inline the package by updating your config:
4548
+
4549
+ ` + c.gray(c.dim("// vitest.config.js")) + "\n" + c.green(`export default {
4550
+ test: {
4551
+ deps: {
4552
+ inline: [
4553
+ ${c.yellow(c.bold(`"${name}"`))}
4554
+ ]
4555
+ }
4556
+ }
4557
+ }
4558
+ `)));
4559
+ }
4560
+ async function getSourcePos(ctx, nearest) {
4561
+ const mod = ctx.server.moduleGraph.getModuleById(nearest.file);
4562
+ const transformResult = mod == null ? void 0 : mod.ssrTransformResult;
4563
+ const pos = await getOriginalPos(transformResult == null ? void 0 : transformResult.map, nearest);
4564
+ return pos;
4565
+ }
4566
+ function displayDiff(actual, expected) {
4567
+ console.error(c.gray(unifiedDiff(stringify(actual), stringify(expected))));
4568
+ }
4569
+ function printErrorMessage(error) {
4570
+ const errorName = error.name || error.nameStr || "Unknown Error";
4571
+ console.error(c.red(`${c.bold(errorName)}: ${error.message}`));
4572
+ }
4573
+ async function printStack(ctx, stack, highlight, onStack) {
4574
+ if (!stack.length)
4575
+ return;
4576
+ for (const frame of stack) {
4577
+ const pos = await getSourcePos(ctx, frame) || frame;
4578
+ const color = frame === highlight ? c.yellow : c.gray;
4579
+ const path = relative(ctx.config.root, frame.file);
4580
+ if (!ctx.config.silent)
4581
+ ctx.console.log(color(` ${c.dim(F_POINTER)} ${[frame.method, c.dim(`${path}:${pos.line}:${pos.column}`)].filter(Boolean).join(" ")}`));
4582
+ await (onStack == null ? void 0 : onStack(frame, pos));
4583
+ if (frame.file in ctx.state.filesMap)
4584
+ break;
4585
+ }
4586
+ if (!ctx.config.silent)
4587
+ ctx.console.log();
4588
+ }
4589
+ function getOriginalPos(map, { line, column }) {
4590
+ return new Promise((resolve) => {
4591
+ if (!map)
4592
+ return resolve(null);
4593
+ const consumer = new SourceMapConsumer(map);
4594
+ const pos = consumer.originalPositionFor({ line, column });
4595
+ if (pos.line != null && pos.column != null)
4596
+ resolve(pos);
4597
+ else
4598
+ resolve(null);
4599
+ });
4600
+ }
4601
+ const splitRE = /\r?\n/;
4602
+ function posToNumber(source, pos) {
4603
+ if (typeof pos === "number")
4604
+ return pos;
4605
+ const lines = source.split(splitRE);
4606
+ const { line, column } = pos;
4607
+ let start = 0;
4608
+ if (line > lines.length)
4609
+ return source.length;
4610
+ for (let i = 0; i < line - 1; i++)
4611
+ start += lines[i].length + 1;
4612
+ return start + column;
4613
+ }
4614
+ function generateCodeFrame(source, indent = 0, start = 0, end, range = 2) {
4615
+ start = posToNumber(source, start);
4616
+ end = end || start;
4617
+ const lines = source.split(splitRE);
4618
+ let count = 0;
4619
+ let res = [];
4620
+ function lineNo(no = "") {
4621
+ return c.gray(`${String(no).padStart(3, " ")}| `);
4622
+ }
4623
+ for (let i = 0; i < lines.length; i++) {
4624
+ count += lines[i].length + 1;
4625
+ if (count >= start) {
4626
+ for (let j = i - range; j <= i + range || end > count; j++) {
4627
+ if (j < 0 || j >= lines.length)
4628
+ continue;
4629
+ const lineLength = lines[j].length;
4630
+ if (lineLength > 200)
4631
+ return "";
4632
+ res.push(lineNo(j + 1) + cliTruncate(lines[j], process.stdout.columns - 5 - indent));
4633
+ if (j === i) {
4634
+ const pad = start - (count - lineLength);
4635
+ const length = Math.max(1, end > count ? lineLength - pad : end - start);
4636
+ res.push(lineNo() + " ".repeat(pad) + c.red("^".repeat(length)));
4637
+ } else if (j > i) {
4638
+ if (end > count) {
4639
+ const length = Math.max(1, Math.min(end - count, lineLength));
4640
+ res.push(lineNo() + c.red("^".repeat(length)));
4641
+ }
4642
+ count += lineLength + 1;
4643
+ }
4644
+ }
4645
+ break;
4646
+ }
4647
+ }
4648
+ if (indent)
4649
+ res = res.map((line) => " ".repeat(indent) + line);
4650
+ return res.join("\n");
4651
+ }
4652
+ function stringify(obj) {
4653
+ return format(obj);
4654
+ }
4655
+ const stackFnCallRE = /at (.*) \((.+):(\d+):(\d+)\)$/;
4656
+ const stackBarePathRE = /at ?(.*) (.+):(\d+):(\d+)$/;
4657
+ function parseStack(stack) {
4658
+ const lines = stack.split("\n");
4659
+ const stackFrames = lines.map((raw) => {
4660
+ const line = raw.trim();
4661
+ const match = line.match(stackFnCallRE) || line.match(stackBarePathRE);
4662
+ if (!match)
4663
+ return null;
4664
+ let file = match[2];
4665
+ if (file.startsWith("file://"))
4666
+ file = file.slice(7);
4667
+ return {
4668
+ method: match[1],
4669
+ file: match[2],
4670
+ line: parseInt(match[3]),
4671
+ column: parseInt(match[4])
4672
+ };
4673
+ });
4674
+ return stackFrames.filter(notNullish);
4675
+ }
4676
+ function unifiedDiff(actual, expected) {
4677
+ if (actual === expected)
4678
+ return "";
4679
+ const diffLimit = 10;
4680
+ const indent = " ";
4681
+ let expectedLinesCount = 0;
4682
+ let actualLinesCount = 0;
4683
+ function preprocess(line) {
4684
+ if (line[0] === "+") {
4685
+ if (expectedLinesCount >= diffLimit)
4686
+ return;
4687
+ expectedLinesCount++;
4688
+ return (compact) => {
4689
+ if (compact)
4690
+ return c.red(formatLine(line.slice(1)));
4691
+ line = line[0] + " " + line.slice(1);
4692
+ const isLastLine = expectedLinesCount === diffLimit;
4693
+ return indent + c.red(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
4694
+ };
4695
+ }
4696
+ if (line[0] === "-") {
4697
+ if (actualLinesCount >= diffLimit)
4698
+ return;
4699
+ actualLinesCount++;
4700
+ return (compact) => {
4701
+ if (compact)
4702
+ return c.green(formatLine(line.slice(1)));
4703
+ line = line[0] + " " + line.slice(1);
4704
+ const isLastLine = actualLinesCount === diffLimit;
4705
+ return indent + c.green(`${formatLine(line)} ${isLastLine ? renderTruncateMessage(indent) : ""}`);
4706
+ };
4707
+ }
4708
+ if (line.match(/@@/))
4709
+ return () => "--";
4710
+ if (line.match(/\\ No newline/))
4711
+ return null;
4712
+ return () => indent + " " + line;
4713
+ }
4714
+ const msg = createPatch("string", actual, expected);
4715
+ const lines = msg.split("\n").splice(5);
4716
+ const cleanLines = lines.map(preprocess).filter(notBlank);
4717
+ if (expectedLinesCount === 1 && actualLinesCount === 1) {
4718
+ return `
4719
+ ${indent}${c.green("- expected")} ${cleanLines[0](true)}
4720
+ ${indent}${c.red("+ actual")} ${cleanLines[1](true)}`;
4721
+ }
4722
+ return `
4723
+ ${indent}${c.green("- expected")}
4724
+ ${indent}${c.red("+ actual")}
4725
+
4726
+ ${cleanLines.map((l) => l()).join("\n")}`;
4727
+ }
4728
+ function formatLine(line) {
4729
+ return cliTruncate(line, (process.stdout.columns || 40) - 1);
4730
+ }
4731
+ function renderTruncateMessage(indent) {
4732
+ return `
4733
+ ${indent}${c.dim("[...truncated]")}`;
4734
+ }
4735
+ function notBlank(line) {
4736
+ return typeof line !== "undefined" && line !== null;
4737
+ }
4738
+
4739
+ export { F_POINTER as F, ansiStyles as a, stripAnsi as b, sliceAnsi as c, F_DOWN as d, F_LONG_DASH as e, F_DOWN_RIGHT as f, F_DOT as g, F_CHECK as h, F_CROSS as i, cliTruncate as j, F_RIGHT as k, printError as p, stringWidth as s, unifiedDiff as u };