vitest 0.8.2 → 0.8.5

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