vitest 0.0.129 → 0.0.133

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