vitest 0.24.4 → 0.25.0

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 (49) hide show
  1. package/LICENSE.md +286 -57
  2. package/dist/browser.d.ts +3 -3
  3. package/dist/browser.js +17 -9
  4. package/dist/{chunk-api-setup.5a197c69.js → chunk-api-setup.a13c5f9d.js} +38 -19
  5. package/dist/{chunk-install-pkg.22707ee4.js → chunk-install-pkg.55bfe508.js} +4 -5
  6. package/dist/{chunk-integrations-coverage.cca09977.js → chunk-integrations-coverage.befed097.js} +57 -1
  7. package/dist/chunk-integrations-globals.391b3839.js +25 -0
  8. package/dist/{chunk-node-git.82174cfe.js → chunk-node-git.af5c9d73.js} +5 -6
  9. package/dist/{chunk-runtime-chain.a5cd236b.js → chunk-runtime-chain.3b531731.js} +27 -23
  10. package/dist/chunk-runtime-error.3cc15c6f.js +142 -0
  11. package/dist/{chunk-runtime-mocker.f994e23a.js → chunk-runtime-mocker.a5d87666.js} +4 -4
  12. package/dist/chunk-runtime-rpc.4a2d45ab.js +30 -0
  13. package/dist/chunk-runtime-setup.f644ac4c.js +1350 -0
  14. package/dist/{chunk-runtime-hooks.66004497.js → chunk-runtime-test-state.31ce8643.js} +106 -6
  15. package/dist/{chunk-mock-date.9fe2b438.js → chunk-typecheck-constants.410fa7b2.js} +23 -4
  16. package/dist/{chunk-utils-env.b1281522.js → chunk-utils-env.7fe285cc.js} +2 -0
  17. package/dist/chunk-utils-source-map.1a66263d.js +90 -0
  18. package/dist/{chunk-utils-source-map.d9d36eb0.js → chunk-utils-timers.d1fcc6bb.js} +309 -3722
  19. package/dist/{chunk-vite-node-client.9fbd5d5b.js → chunk-vite-node-client.13ea0a59.js} +25 -5
  20. package/dist/{chunk-vite-node-externalize.e66d46f6.js → chunk-vite-node-externalize.01d0d22c.js} +824 -97
  21. package/dist/chunk-vite-node-utils.b89230f3.js +1400 -0
  22. package/dist/cli-wrapper.js +5 -6
  23. package/dist/cli.js +27 -13
  24. package/dist/config.cjs +6 -1
  25. package/dist/config.d.ts +6 -1
  26. package/dist/config.js +6 -1
  27. package/dist/entry.js +11 -9
  28. package/dist/environments.d.ts +1 -1
  29. package/dist/index-b68b3c09.d.ts +256 -0
  30. package/dist/index.d.ts +4 -4
  31. package/dist/index.js +13 -7
  32. package/dist/loader.js +4 -3
  33. package/dist/node.d.ts +2 -2
  34. package/dist/node.js +18 -11
  35. package/dist/suite.js +6 -6
  36. package/dist/{global-58e8e951.d.ts → types-b3ff5eea.d.ts} +215 -18
  37. package/dist/{vendor-index.cc8d244b.js → vendor-index.16d769d7.js} +1 -2
  38. package/dist/{vendor-index.12d51d29.js → vendor-index.22806ffb.js} +279 -7
  39. package/dist/{vendor-index.9c919048.js → vendor-index.808a85a6.js} +0 -0
  40. package/dist/worker.js +11 -8
  41. package/globals.d.ts +2 -0
  42. package/package.json +13 -9
  43. package/dist/chunk-integrations-globals.88fd2e64.js +0 -25
  44. package/dist/chunk-runtime-error.9c28c08f.js +0 -807
  45. package/dist/chunk-runtime-rpc.e583f5e7.js +0 -16
  46. package/dist/chunk-utils-timers.ab764c0c.js +0 -27
  47. package/dist/chunk-vite-node-utils.5096a80d.js +0 -6952
  48. package/dist/index-220c1d70.d.ts +0 -117
  49. package/dist/vendor-index.1a291e86.js +0 -275
@@ -1,5 +1,11 @@
1
- import { s as slash, j as notNullish } from './chunk-mock-date.9fe2b438.js';
2
- import { p as picocolors } from './chunk-utils-env.b1281522.js';
1
+ import { p as picocolors } from './chunk-utils-env.7fe285cc.js';
2
+
3
+ const {
4
+ setTimeout: safeSetTimeout,
5
+ setInterval: safeSetInterval,
6
+ clearInterval: safeClearInterval,
7
+ clearTimeout: safeClearTimeout
8
+ } = globalThis;
3
9
 
4
10
  var build = {};
5
11
 
@@ -2322,3680 +2328,254 @@ plugins_1 = build.plugins = plugins;
2322
2328
  var _default = format;
2323
2329
  build.default = _default;
2324
2330
 
2325
- var sourceMapGenerator = {};
2326
-
2327
- var base64Vlq = {};
2328
-
2329
- var base64$1 = {};
2331
+ function Diff() {}
2332
+ Diff.prototype = {
2333
+ diff: function diff(oldString, newString) {
2334
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
2335
+ var callback = options.callback;
2330
2336
 
2331
- /* -*- Mode: js; js-indent-level: 2; -*- */
2337
+ if (typeof options === 'function') {
2338
+ callback = options;
2339
+ options = {};
2340
+ }
2332
2341
 
2333
- /*
2334
- * Copyright 2011 Mozilla Foundation and contributors
2335
- * Licensed under the New BSD license. See LICENSE or:
2336
- * http://opensource.org/licenses/BSD-3-Clause
2337
- */
2342
+ this.options = options;
2343
+ var self = this;
2338
2344
 
2339
- var intToCharMap = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
2345
+ function done(value) {
2346
+ if (callback) {
2347
+ setTimeout(function () {
2348
+ callback(undefined, value);
2349
+ }, 0);
2350
+ return true;
2351
+ } else {
2352
+ return value;
2353
+ }
2354
+ } // Allow subclasses to massage the input prior to running
2340
2355
 
2341
- /**
2342
- * Encode an integer in the range of 0 to 63 to a single base 64 digit.
2343
- */
2344
- base64$1.encode = function (number) {
2345
- if (0 <= number && number < intToCharMap.length) {
2346
- return intToCharMap[number];
2347
- }
2348
- throw new TypeError("Must be between 0 and 63: " + number);
2349
- };
2350
2356
 
2351
- /**
2352
- * Decode a single base 64 character code digit to an integer. Returns -1 on
2353
- * failure.
2354
- */
2355
- base64$1.decode = function (charCode) {
2356
- var bigA = 65; // 'A'
2357
- var bigZ = 90; // 'Z'
2357
+ oldString = this.castInput(oldString);
2358
+ newString = this.castInput(newString);
2359
+ oldString = this.removeEmpty(this.tokenize(oldString));
2360
+ newString = this.removeEmpty(this.tokenize(newString));
2361
+ var newLen = newString.length,
2362
+ oldLen = oldString.length;
2363
+ var editLength = 1;
2364
+ var maxEditLength = newLen + oldLen;
2358
2365
 
2359
- var littleA = 97; // 'a'
2360
- var littleZ = 122; // 'z'
2366
+ if (options.maxEditLength) {
2367
+ maxEditLength = Math.min(maxEditLength, options.maxEditLength);
2368
+ }
2361
2369
 
2362
- var zero = 48; // '0'
2363
- var nine = 57; // '9'
2370
+ var bestPath = [{
2371
+ newPos: -1,
2372
+ components: []
2373
+ }]; // Seed editLength = 0, i.e. the content starts with the same values
2364
2374
 
2365
- var plus = 43; // '+'
2366
- var slash = 47; // '/'
2375
+ var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
2367
2376
 
2368
- var littleOffset = 26;
2369
- var numberOffset = 52;
2377
+ if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
2378
+ // Identity per the equality and tokenizer
2379
+ return done([{
2380
+ value: this.join(newString),
2381
+ count: newString.length
2382
+ }]);
2383
+ } // Main worker method. checks all permutations of a given edit length for acceptance.
2370
2384
 
2371
- // 0 - 25: ABCDEFGHIJKLMNOPQRSTUVWXYZ
2372
- if (bigA <= charCode && charCode <= bigZ) {
2373
- return (charCode - bigA);
2374
- }
2375
2385
 
2376
- // 26 - 51: abcdefghijklmnopqrstuvwxyz
2377
- if (littleA <= charCode && charCode <= littleZ) {
2378
- return (charCode - littleA + littleOffset);
2379
- }
2386
+ function execEditLength() {
2387
+ for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
2388
+ var basePath = void 0;
2380
2389
 
2381
- // 52 - 61: 0123456789
2382
- if (zero <= charCode && charCode <= nine) {
2383
- return (charCode - zero + numberOffset);
2384
- }
2390
+ var addPath = bestPath[diagonalPath - 1],
2391
+ removePath = bestPath[diagonalPath + 1],
2392
+ _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
2385
2393
 
2386
- // 62: +
2387
- if (charCode == plus) {
2388
- return 62;
2389
- }
2394
+ if (addPath) {
2395
+ // No one else is going to attempt to use this value, clear it
2396
+ bestPath[diagonalPath - 1] = undefined;
2397
+ }
2390
2398
 
2391
- // 63: /
2392
- if (charCode == slash) {
2393
- return 63;
2394
- }
2399
+ var canAdd = addPath && addPath.newPos + 1 < newLen,
2400
+ canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
2395
2401
 
2396
- // Invalid base64 digit.
2397
- return -1;
2398
- };
2402
+ if (!canAdd && !canRemove) {
2403
+ // If this path is a terminal then prune
2404
+ bestPath[diagonalPath] = undefined;
2405
+ continue;
2406
+ } // Select the diagonal that we want to branch from. We select the prior
2407
+ // path whose position in the new string is the farthest from the origin
2408
+ // and does not pass the bounds of the diff graph
2399
2409
 
2400
- /* -*- Mode: js; js-indent-level: 2; -*- */
2401
2410
 
2402
- /*
2403
- * Copyright 2011 Mozilla Foundation and contributors
2404
- * Licensed under the New BSD license. See LICENSE or:
2405
- * http://opensource.org/licenses/BSD-3-Clause
2406
- *
2407
- * Based on the Base 64 VLQ implementation in Closure Compiler:
2408
- * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java
2409
- *
2410
- * Copyright 2011 The Closure Compiler Authors. All rights reserved.
2411
- * Redistribution and use in source and binary forms, with or without
2412
- * modification, are permitted provided that the following conditions are
2413
- * met:
2414
- *
2415
- * * Redistributions of source code must retain the above copyright
2416
- * notice, this list of conditions and the following disclaimer.
2417
- * * Redistributions in binary form must reproduce the above
2418
- * copyright notice, this list of conditions and the following
2419
- * disclaimer in the documentation and/or other materials provided
2420
- * with the distribution.
2421
- * * Neither the name of Google Inc. nor the names of its
2422
- * contributors may be used to endorse or promote products derived
2423
- * from this software without specific prior written permission.
2424
- *
2425
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2426
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2427
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2428
- * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2429
- * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2430
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2431
- * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2432
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2433
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2434
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2435
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2436
- */
2411
+ if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
2412
+ basePath = clonePath(removePath);
2413
+ self.pushComponent(basePath.components, undefined, true);
2414
+ } else {
2415
+ basePath = addPath; // No need to clone, we've pulled it from the list
2437
2416
 
2438
- var base64 = base64$1;
2417
+ basePath.newPos++;
2418
+ self.pushComponent(basePath.components, true, undefined);
2419
+ }
2439
2420
 
2440
- // A single base 64 digit can contain 6 bits of data. For the base 64 variable
2441
- // length quantities we use in the source map spec, the first bit is the sign,
2442
- // the next four bits are the actual value, and the 6th bit is the
2443
- // continuation bit. The continuation bit tells us whether there are more
2444
- // digits in this value following this digit.
2445
- //
2446
- // Continuation
2447
- // | Sign
2448
- // | |
2449
- // V V
2450
- // 101011
2421
+ _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
2451
2422
 
2452
- var VLQ_BASE_SHIFT = 5;
2423
+ if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
2424
+ return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
2425
+ } else {
2426
+ // Otherwise track this path as a potential candidate and continue.
2427
+ bestPath[diagonalPath] = basePath;
2428
+ }
2429
+ }
2453
2430
 
2454
- // binary: 100000
2455
- var VLQ_BASE = 1 << VLQ_BASE_SHIFT;
2431
+ editLength++;
2432
+ } // Performs the length of edit iteration. Is a bit fugly as this has to support the
2433
+ // sync and async mode which is never fun. Loops over execEditLength until a value
2434
+ // is produced, or until the edit length exceeds options.maxEditLength (if given),
2435
+ // in which case it will return undefined.
2456
2436
 
2457
- // binary: 011111
2458
- var VLQ_BASE_MASK = VLQ_BASE - 1;
2459
2437
 
2460
- // binary: 100000
2461
- var VLQ_CONTINUATION_BIT = VLQ_BASE;
2438
+ if (callback) {
2439
+ (function exec() {
2440
+ setTimeout(function () {
2441
+ if (editLength > maxEditLength) {
2442
+ return callback();
2443
+ }
2462
2444
 
2463
- /**
2464
- * Converts from a two-complement value to a value where the sign bit is
2465
- * placed in the least significant bit. For example, as decimals:
2466
- * 1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
2467
- * 2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
2468
- */
2469
- function toVLQSigned(aValue) {
2470
- return aValue < 0
2471
- ? ((-aValue) << 1) + 1
2472
- : (aValue << 1) + 0;
2473
- }
2445
+ if (!execEditLength()) {
2446
+ exec();
2447
+ }
2448
+ }, 0);
2449
+ })();
2450
+ } else {
2451
+ while (editLength <= maxEditLength) {
2452
+ var ret = execEditLength();
2474
2453
 
2475
- /**
2476
- * Converts to a two-complement value from a value where the sign bit is
2477
- * placed in the least significant bit. For example, as decimals:
2478
- * 2 (10 binary) becomes 1, 3 (11 binary) becomes -1
2479
- * 4 (100 binary) becomes 2, 5 (101 binary) becomes -2
2480
- */
2481
- function fromVLQSigned(aValue) {
2482
- var isNegative = (aValue & 1) === 1;
2483
- var shifted = aValue >> 1;
2484
- return isNegative
2485
- ? -shifted
2486
- : shifted;
2487
- }
2454
+ if (ret) {
2455
+ return ret;
2456
+ }
2457
+ }
2458
+ }
2459
+ },
2460
+ pushComponent: function pushComponent(components, added, removed) {
2461
+ var last = components[components.length - 1];
2488
2462
 
2489
- /**
2490
- * Returns the base 64 VLQ encoded value.
2491
- */
2492
- base64Vlq.encode = function base64VLQ_encode(aValue) {
2493
- var encoded = "";
2494
- var digit;
2495
-
2496
- var vlq = toVLQSigned(aValue);
2497
-
2498
- do {
2499
- digit = vlq & VLQ_BASE_MASK;
2500
- vlq >>>= VLQ_BASE_SHIFT;
2501
- if (vlq > 0) {
2502
- // There are still more digits in this value, so we must make sure the
2503
- // continuation bit is marked.
2504
- digit |= VLQ_CONTINUATION_BIT;
2463
+ if (last && last.added === added && last.removed === removed) {
2464
+ // We need to clone here as the component clone operation is just
2465
+ // as shallow array clone
2466
+ components[components.length - 1] = {
2467
+ count: last.count + 1,
2468
+ added: added,
2469
+ removed: removed
2470
+ };
2471
+ } else {
2472
+ components.push({
2473
+ count: 1,
2474
+ added: added,
2475
+ removed: removed
2476
+ });
2505
2477
  }
2506
- encoded += base64.encode(digit);
2507
- } while (vlq > 0);
2478
+ },
2479
+ extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
2480
+ var newLen = newString.length,
2481
+ oldLen = oldString.length,
2482
+ newPos = basePath.newPos,
2483
+ oldPos = newPos - diagonalPath,
2484
+ commonCount = 0;
2508
2485
 
2509
- return encoded;
2510
- };
2486
+ while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
2487
+ newPos++;
2488
+ oldPos++;
2489
+ commonCount++;
2490
+ }
2511
2491
 
2512
- /**
2513
- * Decodes the next base 64 VLQ value from the given string and returns the
2514
- * value and the rest of the string via the out parameter.
2515
- */
2516
- base64Vlq.decode = function base64VLQ_decode(aStr, aIndex, aOutParam) {
2517
- var strLen = aStr.length;
2518
- var result = 0;
2519
- var shift = 0;
2520
- var continuation, digit;
2521
-
2522
- do {
2523
- if (aIndex >= strLen) {
2524
- throw new Error("Expected more digits in base 64 VLQ value.");
2492
+ if (commonCount) {
2493
+ basePath.components.push({
2494
+ count: commonCount
2495
+ });
2525
2496
  }
2526
2497
 
2527
- digit = base64.decode(aStr.charCodeAt(aIndex++));
2528
- if (digit === -1) {
2529
- throw new Error("Invalid base64 digit: " + aStr.charAt(aIndex - 1));
2498
+ basePath.newPos = newPos;
2499
+ return oldPos;
2500
+ },
2501
+ equals: function equals(left, right) {
2502
+ if (this.options.comparator) {
2503
+ return this.options.comparator(left, right);
2504
+ } else {
2505
+ return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
2530
2506
  }
2507
+ },
2508
+ removeEmpty: function removeEmpty(array) {
2509
+ var ret = [];
2531
2510
 
2532
- continuation = !!(digit & VLQ_CONTINUATION_BIT);
2533
- digit &= VLQ_BASE_MASK;
2534
- result = result + (digit << shift);
2535
- shift += VLQ_BASE_SHIFT;
2536
- } while (continuation);
2511
+ for (var i = 0; i < array.length; i++) {
2512
+ if (array[i]) {
2513
+ ret.push(array[i]);
2514
+ }
2515
+ }
2537
2516
 
2538
- aOutParam.value = fromVLQSigned(result);
2539
- aOutParam.rest = aIndex;
2517
+ return ret;
2518
+ },
2519
+ castInput: function castInput(value) {
2520
+ return value;
2521
+ },
2522
+ tokenize: function tokenize(value) {
2523
+ return value.split('');
2524
+ },
2525
+ join: function join(chars) {
2526
+ return chars.join('');
2527
+ }
2540
2528
  };
2541
2529
 
2542
- var util$5 = {};
2543
-
2544
- /* -*- Mode: js; js-indent-level: 2; -*- */
2545
-
2546
- (function (exports) {
2547
- /*
2548
- * Copyright 2011 Mozilla Foundation and contributors
2549
- * Licensed under the New BSD license. See LICENSE or:
2550
- * http://opensource.org/licenses/BSD-3-Clause
2551
- */
2552
-
2553
- /**
2554
- * This is a helper function for getting values from parameter/options
2555
- * objects.
2556
- *
2557
- * @param args The object we are extracting values from
2558
- * @param name The name of the property we are getting.
2559
- * @param defaultValue An optional value to return if the property is missing
2560
- * from the object. If this is not specified and the property is missing, an
2561
- * error will be thrown.
2562
- */
2563
- function getArg(aArgs, aName, aDefaultValue) {
2564
- if (aName in aArgs) {
2565
- return aArgs[aName];
2566
- } else if (arguments.length === 3) {
2567
- return aDefaultValue;
2568
- } else {
2569
- throw new Error('"' + aName + '" is a required argument.');
2570
- }
2571
- }
2572
- exports.getArg = getArg;
2530
+ function buildValues(diff, components, newString, oldString, useLongestToken) {
2531
+ var componentPos = 0,
2532
+ componentLen = components.length,
2533
+ newPos = 0,
2534
+ oldPos = 0;
2573
2535
 
2574
- var urlRegexp = /^(?:([\w+\-.]+):)?\/\/(?:(\w+:\w+)@)?([\w.-]*)(?::(\d+))?(.*)$/;
2575
- var dataUrlRegexp = /^data:.+\,.+$/;
2536
+ for (; componentPos < componentLen; componentPos++) {
2537
+ var component = components[componentPos];
2576
2538
 
2577
- function urlParse(aUrl) {
2578
- var match = aUrl.match(urlRegexp);
2579
- if (!match) {
2580
- return null;
2581
- }
2582
- return {
2583
- scheme: match[1],
2584
- auth: match[2],
2585
- host: match[3],
2586
- port: match[4],
2587
- path: match[5]
2588
- };
2589
- }
2590
- exports.urlParse = urlParse;
2539
+ if (!component.removed) {
2540
+ if (!component.added && useLongestToken) {
2541
+ var value = newString.slice(newPos, newPos + component.count);
2542
+ value = value.map(function (value, i) {
2543
+ var oldValue = oldString[oldPos + i];
2544
+ return oldValue.length > value.length ? oldValue : value;
2545
+ });
2546
+ component.value = diff.join(value);
2547
+ } else {
2548
+ component.value = diff.join(newString.slice(newPos, newPos + component.count));
2549
+ }
2591
2550
 
2592
- function urlGenerate(aParsedUrl) {
2593
- var url = '';
2594
- if (aParsedUrl.scheme) {
2595
- url += aParsedUrl.scheme + ':';
2596
- }
2597
- url += '//';
2598
- if (aParsedUrl.auth) {
2599
- url += aParsedUrl.auth + '@';
2600
- }
2601
- if (aParsedUrl.host) {
2602
- url += aParsedUrl.host;
2603
- }
2604
- if (aParsedUrl.port) {
2605
- url += ":" + aParsedUrl.port;
2606
- }
2607
- if (aParsedUrl.path) {
2608
- url += aParsedUrl.path;
2609
- }
2610
- return url;
2611
- }
2612
- exports.urlGenerate = urlGenerate;
2613
-
2614
- var MAX_CACHED_INPUTS = 32;
2615
-
2616
- /**
2617
- * Takes some function `f(input) -> result` and returns a memoized version of
2618
- * `f`.
2619
- *
2620
- * We keep at most `MAX_CACHED_INPUTS` memoized results of `f` alive. The
2621
- * memoization is a dumb-simple, linear least-recently-used cache.
2622
- */
2623
- function lruMemoize(f) {
2624
- var cache = [];
2625
-
2626
- return function(input) {
2627
- for (var i = 0; i < cache.length; i++) {
2628
- if (cache[i].input === input) {
2629
- var temp = cache[0];
2630
- cache[0] = cache[i];
2631
- cache[i] = temp;
2632
- return cache[0].result;
2633
- }
2634
- }
2551
+ newPos += component.count; // Common case
2635
2552
 
2636
- var result = f(input);
2553
+ if (!component.added) {
2554
+ oldPos += component.count;
2555
+ }
2556
+ } else {
2557
+ component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
2558
+ oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
2559
+ // The diffing algorithm is tied to add then remove output and this is the simplest
2560
+ // route to get the desired output with minimal overhead.
2637
2561
 
2638
- cache.unshift({
2639
- input,
2640
- result,
2641
- });
2562
+ if (componentPos && components[componentPos - 1].added) {
2563
+ var tmp = components[componentPos - 1];
2564
+ components[componentPos - 1] = components[componentPos];
2565
+ components[componentPos] = tmp;
2566
+ }
2567
+ }
2568
+ } // Special case handle for when one terminal is ignored (i.e. whitespace).
2569
+ // For this case we merge the terminal into the prior string and drop the change.
2570
+ // This is only available for string mode.
2642
2571
 
2643
- if (cache.length > MAX_CACHED_INPUTS) {
2644
- cache.pop();
2645
- }
2646
2572
 
2647
- return result;
2648
- };
2649
- }
2573
+ var lastComponent = components[componentLen - 1];
2650
2574
 
2651
- /**
2652
- * Normalizes a path, or the path portion of a URL:
2653
- *
2654
- * - Replaces consecutive slashes with one slash.
2655
- * - Removes unnecessary '.' parts.
2656
- * - Removes unnecessary '<dir>/..' parts.
2657
- *
2658
- * Based on code in the Node.js 'path' core module.
2659
- *
2660
- * @param aPath The path or url to normalize.
2661
- */
2662
- var normalize = lruMemoize(function normalize(aPath) {
2663
- var path = aPath;
2664
- var url = urlParse(aPath);
2665
- if (url) {
2666
- if (!url.path) {
2667
- return aPath;
2668
- }
2669
- path = url.path;
2670
- }
2671
- var isAbsolute = exports.isAbsolute(path);
2672
- // Split the path into parts between `/` characters. This is much faster than
2673
- // using `.split(/\/+/g)`.
2674
- var parts = [];
2675
- var start = 0;
2676
- var i = 0;
2677
- while (true) {
2678
- start = i;
2679
- i = path.indexOf("/", start);
2680
- if (i === -1) {
2681
- parts.push(path.slice(start));
2682
- break;
2683
- } else {
2684
- parts.push(path.slice(start, i));
2685
- while (i < path.length && path[i] === "/") {
2686
- i++;
2687
- }
2688
- }
2689
- }
2690
-
2691
- for (var part, up = 0, i = parts.length - 1; i >= 0; i--) {
2692
- part = parts[i];
2693
- if (part === '.') {
2694
- parts.splice(i, 1);
2695
- } else if (part === '..') {
2696
- up++;
2697
- } else if (up > 0) {
2698
- if (part === '') {
2699
- // The first part is blank if the path is absolute. Trying to go
2700
- // above the root is a no-op. Therefore we can remove all '..' parts
2701
- // directly after the root.
2702
- parts.splice(i + 1, up);
2703
- up = 0;
2704
- } else {
2705
- parts.splice(i, 2);
2706
- up--;
2707
- }
2708
- }
2709
- }
2710
- path = parts.join('/');
2711
-
2712
- if (path === '') {
2713
- path = isAbsolute ? '/' : '.';
2714
- }
2715
-
2716
- if (url) {
2717
- url.path = path;
2718
- return urlGenerate(url);
2719
- }
2720
- return path;
2721
- });
2722
- exports.normalize = normalize;
2723
-
2724
- /**
2725
- * Joins two paths/URLs.
2726
- *
2727
- * @param aRoot The root path or URL.
2728
- * @param aPath The path or URL to be joined with the root.
2729
- *
2730
- * - If aPath is a URL or a data URI, aPath is returned, unless aPath is a
2731
- * scheme-relative URL: Then the scheme of aRoot, if any, is prepended
2732
- * first.
2733
- * - Otherwise aPath is a path. If aRoot is a URL, then its path portion
2734
- * is updated with the result and aRoot is returned. Otherwise the result
2735
- * is returned.
2736
- * - If aPath is absolute, the result is aPath.
2737
- * - Otherwise the two paths are joined with a slash.
2738
- * - Joining for example 'http://' and 'www.example.com' is also supported.
2739
- */
2740
- function join(aRoot, aPath) {
2741
- if (aRoot === "") {
2742
- aRoot = ".";
2743
- }
2744
- if (aPath === "") {
2745
- aPath = ".";
2746
- }
2747
- var aPathUrl = urlParse(aPath);
2748
- var aRootUrl = urlParse(aRoot);
2749
- if (aRootUrl) {
2750
- aRoot = aRootUrl.path || '/';
2751
- }
2752
-
2753
- // `join(foo, '//www.example.org')`
2754
- if (aPathUrl && !aPathUrl.scheme) {
2755
- if (aRootUrl) {
2756
- aPathUrl.scheme = aRootUrl.scheme;
2757
- }
2758
- return urlGenerate(aPathUrl);
2759
- }
2760
-
2761
- if (aPathUrl || aPath.match(dataUrlRegexp)) {
2762
- return aPath;
2763
- }
2764
-
2765
- // `join('http://', 'www.example.com')`
2766
- if (aRootUrl && !aRootUrl.host && !aRootUrl.path) {
2767
- aRootUrl.host = aPath;
2768
- return urlGenerate(aRootUrl);
2769
- }
2770
-
2771
- var joined = aPath.charAt(0) === '/'
2772
- ? aPath
2773
- : normalize(aRoot.replace(/\/+$/, '') + '/' + aPath);
2774
-
2775
- if (aRootUrl) {
2776
- aRootUrl.path = joined;
2777
- return urlGenerate(aRootUrl);
2778
- }
2779
- return joined;
2780
- }
2781
- exports.join = join;
2782
-
2783
- exports.isAbsolute = function (aPath) {
2784
- return aPath.charAt(0) === '/' || urlRegexp.test(aPath);
2785
- };
2786
-
2787
- /**
2788
- * Make a path relative to a URL or another path.
2789
- *
2790
- * @param aRoot The root path or URL.
2791
- * @param aPath The path or URL to be made relative to aRoot.
2792
- */
2793
- function relative(aRoot, aPath) {
2794
- if (aRoot === "") {
2795
- aRoot = ".";
2796
- }
2797
-
2798
- aRoot = aRoot.replace(/\/$/, '');
2799
-
2800
- // It is possible for the path to be above the root. In this case, simply
2801
- // checking whether the root is a prefix of the path won't work. Instead, we
2802
- // need to remove components from the root one by one, until either we find
2803
- // a prefix that fits, or we run out of components to remove.
2804
- var level = 0;
2805
- while (aPath.indexOf(aRoot + '/') !== 0) {
2806
- var index = aRoot.lastIndexOf("/");
2807
- if (index < 0) {
2808
- return aPath;
2809
- }
2810
-
2811
- // If the only part of the root that is left is the scheme (i.e. http://,
2812
- // file:///, etc.), one or more slashes (/), or simply nothing at all, we
2813
- // have exhausted all components, so the path is not relative to the root.
2814
- aRoot = aRoot.slice(0, index);
2815
- if (aRoot.match(/^([^\/]+:\/)?\/*$/)) {
2816
- return aPath;
2817
- }
2818
-
2819
- ++level;
2820
- }
2821
-
2822
- // Make sure we add a "../" for each component we removed from the root.
2823
- return Array(level + 1).join("../") + aPath.substr(aRoot.length + 1);
2824
- }
2825
- exports.relative = relative;
2826
-
2827
- var supportsNullProto = (function () {
2828
- var obj = Object.create(null);
2829
- return !('__proto__' in obj);
2830
- }());
2831
-
2832
- function identity (s) {
2833
- return s;
2834
- }
2835
-
2836
- /**
2837
- * Because behavior goes wacky when you set `__proto__` on objects, we
2838
- * have to prefix all the strings in our set with an arbitrary character.
2839
- *
2840
- * See https://github.com/mozilla/source-map/pull/31 and
2841
- * https://github.com/mozilla/source-map/issues/30
2842
- *
2843
- * @param String aStr
2844
- */
2845
- function toSetString(aStr) {
2846
- if (isProtoString(aStr)) {
2847
- return '$' + aStr;
2848
- }
2849
-
2850
- return aStr;
2851
- }
2852
- exports.toSetString = supportsNullProto ? identity : toSetString;
2853
-
2854
- function fromSetString(aStr) {
2855
- if (isProtoString(aStr)) {
2856
- return aStr.slice(1);
2857
- }
2858
-
2859
- return aStr;
2860
- }
2861
- exports.fromSetString = supportsNullProto ? identity : fromSetString;
2862
-
2863
- function isProtoString(s) {
2864
- if (!s) {
2865
- return false;
2866
- }
2867
-
2868
- var length = s.length;
2869
-
2870
- if (length < 9 /* "__proto__".length */) {
2871
- return false;
2872
- }
2873
-
2874
- if (s.charCodeAt(length - 1) !== 95 /* '_' */ ||
2875
- s.charCodeAt(length - 2) !== 95 /* '_' */ ||
2876
- s.charCodeAt(length - 3) !== 111 /* 'o' */ ||
2877
- s.charCodeAt(length - 4) !== 116 /* 't' */ ||
2878
- s.charCodeAt(length - 5) !== 111 /* 'o' */ ||
2879
- s.charCodeAt(length - 6) !== 114 /* 'r' */ ||
2880
- s.charCodeAt(length - 7) !== 112 /* 'p' */ ||
2881
- s.charCodeAt(length - 8) !== 95 /* '_' */ ||
2882
- s.charCodeAt(length - 9) !== 95 /* '_' */) {
2883
- return false;
2884
- }
2885
-
2886
- for (var i = length - 10; i >= 0; i--) {
2887
- if (s.charCodeAt(i) !== 36 /* '$' */) {
2888
- return false;
2889
- }
2890
- }
2891
-
2892
- return true;
2893
- }
2894
-
2895
- /**
2896
- * Comparator between two mappings where the original positions are compared.
2897
- *
2898
- * Optionally pass in `true` as `onlyCompareGenerated` to consider two
2899
- * mappings with the same original source/line/column, but different generated
2900
- * line and column the same. Useful when searching for a mapping with a
2901
- * stubbed out mapping.
2902
- */
2903
- function compareByOriginalPositions(mappingA, mappingB, onlyCompareOriginal) {
2904
- var cmp = strcmp(mappingA.source, mappingB.source);
2905
- if (cmp !== 0) {
2906
- return cmp;
2907
- }
2908
-
2909
- cmp = mappingA.originalLine - mappingB.originalLine;
2910
- if (cmp !== 0) {
2911
- return cmp;
2912
- }
2913
-
2914
- cmp = mappingA.originalColumn - mappingB.originalColumn;
2915
- if (cmp !== 0 || onlyCompareOriginal) {
2916
- return cmp;
2917
- }
2918
-
2919
- cmp = mappingA.generatedColumn - mappingB.generatedColumn;
2920
- if (cmp !== 0) {
2921
- return cmp;
2922
- }
2923
-
2924
- cmp = mappingA.generatedLine - mappingB.generatedLine;
2925
- if (cmp !== 0) {
2926
- return cmp;
2927
- }
2928
-
2929
- return strcmp(mappingA.name, mappingB.name);
2930
- }
2931
- exports.compareByOriginalPositions = compareByOriginalPositions;
2932
-
2933
- function compareByOriginalPositionsNoSource(mappingA, mappingB, onlyCompareOriginal) {
2934
- var cmp;
2935
-
2936
- cmp = mappingA.originalLine - mappingB.originalLine;
2937
- if (cmp !== 0) {
2938
- return cmp;
2939
- }
2940
-
2941
- cmp = mappingA.originalColumn - mappingB.originalColumn;
2942
- if (cmp !== 0 || onlyCompareOriginal) {
2943
- return cmp;
2944
- }
2945
-
2946
- cmp = mappingA.generatedColumn - mappingB.generatedColumn;
2947
- if (cmp !== 0) {
2948
- return cmp;
2949
- }
2950
-
2951
- cmp = mappingA.generatedLine - mappingB.generatedLine;
2952
- if (cmp !== 0) {
2953
- return cmp;
2954
- }
2955
-
2956
- return strcmp(mappingA.name, mappingB.name);
2957
- }
2958
- exports.compareByOriginalPositionsNoSource = compareByOriginalPositionsNoSource;
2959
-
2960
- /**
2961
- * Comparator between two mappings with deflated source and name indices where
2962
- * the generated positions are compared.
2963
- *
2964
- * Optionally pass in `true` as `onlyCompareGenerated` to consider two
2965
- * mappings with the same generated line and column, but different
2966
- * source/name/original line and column the same. Useful when searching for a
2967
- * mapping with a stubbed out mapping.
2968
- */
2969
- function compareByGeneratedPositionsDeflated(mappingA, mappingB, onlyCompareGenerated) {
2970
- var cmp = mappingA.generatedLine - mappingB.generatedLine;
2971
- if (cmp !== 0) {
2972
- return cmp;
2973
- }
2974
-
2975
- cmp = mappingA.generatedColumn - mappingB.generatedColumn;
2976
- if (cmp !== 0 || onlyCompareGenerated) {
2977
- return cmp;
2978
- }
2979
-
2980
- cmp = strcmp(mappingA.source, mappingB.source);
2981
- if (cmp !== 0) {
2982
- return cmp;
2983
- }
2984
-
2985
- cmp = mappingA.originalLine - mappingB.originalLine;
2986
- if (cmp !== 0) {
2987
- return cmp;
2988
- }
2989
-
2990
- cmp = mappingA.originalColumn - mappingB.originalColumn;
2991
- if (cmp !== 0) {
2992
- return cmp;
2993
- }
2994
-
2995
- return strcmp(mappingA.name, mappingB.name);
2996
- }
2997
- exports.compareByGeneratedPositionsDeflated = compareByGeneratedPositionsDeflated;
2998
-
2999
- function compareByGeneratedPositionsDeflatedNoLine(mappingA, mappingB, onlyCompareGenerated) {
3000
- var cmp = mappingA.generatedColumn - mappingB.generatedColumn;
3001
- if (cmp !== 0 || onlyCompareGenerated) {
3002
- return cmp;
3003
- }
3004
-
3005
- cmp = strcmp(mappingA.source, mappingB.source);
3006
- if (cmp !== 0) {
3007
- return cmp;
3008
- }
3009
-
3010
- cmp = mappingA.originalLine - mappingB.originalLine;
3011
- if (cmp !== 0) {
3012
- return cmp;
3013
- }
3014
-
3015
- cmp = mappingA.originalColumn - mappingB.originalColumn;
3016
- if (cmp !== 0) {
3017
- return cmp;
3018
- }
3019
-
3020
- return strcmp(mappingA.name, mappingB.name);
3021
- }
3022
- exports.compareByGeneratedPositionsDeflatedNoLine = compareByGeneratedPositionsDeflatedNoLine;
3023
-
3024
- function strcmp(aStr1, aStr2) {
3025
- if (aStr1 === aStr2) {
3026
- return 0;
3027
- }
3028
-
3029
- if (aStr1 === null) {
3030
- return 1; // aStr2 !== null
3031
- }
3032
-
3033
- if (aStr2 === null) {
3034
- return -1; // aStr1 !== null
3035
- }
3036
-
3037
- if (aStr1 > aStr2) {
3038
- return 1;
3039
- }
3040
-
3041
- return -1;
3042
- }
3043
-
3044
- /**
3045
- * Comparator between two mappings with inflated source and name strings where
3046
- * the generated positions are compared.
3047
- */
3048
- function compareByGeneratedPositionsInflated(mappingA, mappingB) {
3049
- var cmp = mappingA.generatedLine - mappingB.generatedLine;
3050
- if (cmp !== 0) {
3051
- return cmp;
3052
- }
3053
-
3054
- cmp = mappingA.generatedColumn - mappingB.generatedColumn;
3055
- if (cmp !== 0) {
3056
- return cmp;
3057
- }
3058
-
3059
- cmp = strcmp(mappingA.source, mappingB.source);
3060
- if (cmp !== 0) {
3061
- return cmp;
3062
- }
3063
-
3064
- cmp = mappingA.originalLine - mappingB.originalLine;
3065
- if (cmp !== 0) {
3066
- return cmp;
3067
- }
3068
-
3069
- cmp = mappingA.originalColumn - mappingB.originalColumn;
3070
- if (cmp !== 0) {
3071
- return cmp;
3072
- }
3073
-
3074
- return strcmp(mappingA.name, mappingB.name);
3075
- }
3076
- exports.compareByGeneratedPositionsInflated = compareByGeneratedPositionsInflated;
3077
-
3078
- /**
3079
- * Strip any JSON XSSI avoidance prefix from the string (as documented
3080
- * in the source maps specification), and then parse the string as
3081
- * JSON.
3082
- */
3083
- function parseSourceMapInput(str) {
3084
- return JSON.parse(str.replace(/^\)]}'[^\n]*\n/, ''));
3085
- }
3086
- exports.parseSourceMapInput = parseSourceMapInput;
3087
-
3088
- /**
3089
- * Compute the URL of a source given the the source root, the source's
3090
- * URL, and the source map's URL.
3091
- */
3092
- function computeSourceURL(sourceRoot, sourceURL, sourceMapURL) {
3093
- sourceURL = sourceURL || '';
3094
-
3095
- if (sourceRoot) {
3096
- // This follows what Chrome does.
3097
- if (sourceRoot[sourceRoot.length - 1] !== '/' && sourceURL[0] !== '/') {
3098
- sourceRoot += '/';
3099
- }
3100
- // The spec says:
3101
- // Line 4: An optional source root, useful for relocating source
3102
- // files on a server or removing repeated values in the
3103
- // “sources” entry. This value is prepended to the individual
3104
- // entries in the “source” field.
3105
- sourceURL = sourceRoot + sourceURL;
3106
- }
3107
-
3108
- // Historically, SourceMapConsumer did not take the sourceMapURL as
3109
- // a parameter. This mode is still somewhat supported, which is why
3110
- // this code block is conditional. However, it's preferable to pass
3111
- // the source map URL to SourceMapConsumer, so that this function
3112
- // can implement the source URL resolution algorithm as outlined in
3113
- // the spec. This block is basically the equivalent of:
3114
- // new URL(sourceURL, sourceMapURL).toString()
3115
- // ... except it avoids using URL, which wasn't available in the
3116
- // older releases of node still supported by this library.
3117
- //
3118
- // The spec says:
3119
- // If the sources are not absolute URLs after prepending of the
3120
- // “sourceRoot”, the sources are resolved relative to the
3121
- // SourceMap (like resolving script src in a html document).
3122
- if (sourceMapURL) {
3123
- var parsed = urlParse(sourceMapURL);
3124
- if (!parsed) {
3125
- throw new Error("sourceMapURL could not be parsed");
3126
- }
3127
- if (parsed.path) {
3128
- // Strip the last path component, but keep the "/".
3129
- var index = parsed.path.lastIndexOf('/');
3130
- if (index >= 0) {
3131
- parsed.path = parsed.path.substring(0, index + 1);
3132
- }
3133
- }
3134
- sourceURL = join(urlGenerate(parsed), sourceURL);
3135
- }
3136
-
3137
- return normalize(sourceURL);
3138
- }
3139
- exports.computeSourceURL = computeSourceURL;
3140
- } (util$5));
3141
-
3142
- var arraySet = {};
3143
-
3144
- /* -*- Mode: js; js-indent-level: 2; -*- */
3145
-
3146
- /*
3147
- * Copyright 2011 Mozilla Foundation and contributors
3148
- * Licensed under the New BSD license. See LICENSE or:
3149
- * http://opensource.org/licenses/BSD-3-Clause
3150
- */
3151
-
3152
- var util$4 = util$5;
3153
- var has = Object.prototype.hasOwnProperty;
3154
- var hasNativeMap = typeof Map !== "undefined";
3155
-
3156
- /**
3157
- * A data structure which is a combination of an array and a set. Adding a new
3158
- * member is O(1), testing for membership is O(1), and finding the index of an
3159
- * element is O(1). Removing elements from the set is not supported. Only
3160
- * strings are supported for membership.
3161
- */
3162
- function ArraySet$2() {
3163
- this._array = [];
3164
- this._set = hasNativeMap ? new Map() : Object.create(null);
3165
- }
3166
-
3167
- /**
3168
- * Static method for creating ArraySet instances from an existing array.
3169
- */
3170
- ArraySet$2.fromArray = function ArraySet_fromArray(aArray, aAllowDuplicates) {
3171
- var set = new ArraySet$2();
3172
- for (var i = 0, len = aArray.length; i < len; i++) {
3173
- set.add(aArray[i], aAllowDuplicates);
3174
- }
3175
- return set;
3176
- };
3177
-
3178
- /**
3179
- * Return how many unique items are in this ArraySet. If duplicates have been
3180
- * added, than those do not count towards the size.
3181
- *
3182
- * @returns Number
3183
- */
3184
- ArraySet$2.prototype.size = function ArraySet_size() {
3185
- return hasNativeMap ? this._set.size : Object.getOwnPropertyNames(this._set).length;
3186
- };
3187
-
3188
- /**
3189
- * Add the given string to this set.
3190
- *
3191
- * @param String aStr
3192
- */
3193
- ArraySet$2.prototype.add = function ArraySet_add(aStr, aAllowDuplicates) {
3194
- var sStr = hasNativeMap ? aStr : util$4.toSetString(aStr);
3195
- var isDuplicate = hasNativeMap ? this.has(aStr) : has.call(this._set, sStr);
3196
- var idx = this._array.length;
3197
- if (!isDuplicate || aAllowDuplicates) {
3198
- this._array.push(aStr);
3199
- }
3200
- if (!isDuplicate) {
3201
- if (hasNativeMap) {
3202
- this._set.set(aStr, idx);
3203
- } else {
3204
- this._set[sStr] = idx;
3205
- }
3206
- }
3207
- };
3208
-
3209
- /**
3210
- * Is the given string a member of this set?
3211
- *
3212
- * @param String aStr
3213
- */
3214
- ArraySet$2.prototype.has = function ArraySet_has(aStr) {
3215
- if (hasNativeMap) {
3216
- return this._set.has(aStr);
3217
- } else {
3218
- var sStr = util$4.toSetString(aStr);
3219
- return has.call(this._set, sStr);
3220
- }
3221
- };
3222
-
3223
- /**
3224
- * What is the index of the given string in the array?
3225
- *
3226
- * @param String aStr
3227
- */
3228
- ArraySet$2.prototype.indexOf = function ArraySet_indexOf(aStr) {
3229
- if (hasNativeMap) {
3230
- var idx = this._set.get(aStr);
3231
- if (idx >= 0) {
3232
- return idx;
3233
- }
3234
- } else {
3235
- var sStr = util$4.toSetString(aStr);
3236
- if (has.call(this._set, sStr)) {
3237
- return this._set[sStr];
3238
- }
3239
- }
3240
-
3241
- throw new Error('"' + aStr + '" is not in the set.');
3242
- };
3243
-
3244
- /**
3245
- * What is the element at the given index?
3246
- *
3247
- * @param Number aIdx
3248
- */
3249
- ArraySet$2.prototype.at = function ArraySet_at(aIdx) {
3250
- if (aIdx >= 0 && aIdx < this._array.length) {
3251
- return this._array[aIdx];
3252
- }
3253
- throw new Error('No element indexed by ' + aIdx);
3254
- };
3255
-
3256
- /**
3257
- * Returns the array representation of this set (which has the proper indices
3258
- * indicated by indexOf). Note that this is a copy of the internal array used
3259
- * for storing the members so that no one can mess with internal state.
3260
- */
3261
- ArraySet$2.prototype.toArray = function ArraySet_toArray() {
3262
- return this._array.slice();
3263
- };
3264
-
3265
- arraySet.ArraySet = ArraySet$2;
3266
-
3267
- var mappingList = {};
3268
-
3269
- /* -*- Mode: js; js-indent-level: 2; -*- */
3270
-
3271
- /*
3272
- * Copyright 2014 Mozilla Foundation and contributors
3273
- * Licensed under the New BSD license. See LICENSE or:
3274
- * http://opensource.org/licenses/BSD-3-Clause
3275
- */
3276
-
3277
- var util$3 = util$5;
3278
-
3279
- /**
3280
- * Determine whether mappingB is after mappingA with respect to generated
3281
- * position.
3282
- */
3283
- function generatedPositionAfter(mappingA, mappingB) {
3284
- // Optimized for most common case
3285
- var lineA = mappingA.generatedLine;
3286
- var lineB = mappingB.generatedLine;
3287
- var columnA = mappingA.generatedColumn;
3288
- var columnB = mappingB.generatedColumn;
3289
- return lineB > lineA || lineB == lineA && columnB >= columnA ||
3290
- util$3.compareByGeneratedPositionsInflated(mappingA, mappingB) <= 0;
3291
- }
3292
-
3293
- /**
3294
- * A data structure to provide a sorted view of accumulated mappings in a
3295
- * performance conscious manner. It trades a neglibable overhead in general
3296
- * case for a large speedup in case of mappings being added in order.
3297
- */
3298
- function MappingList$1() {
3299
- this._array = [];
3300
- this._sorted = true;
3301
- // Serves as infimum
3302
- this._last = {generatedLine: -1, generatedColumn: 0};
3303
- }
3304
-
3305
- /**
3306
- * Iterate through internal items. This method takes the same arguments that
3307
- * `Array.prototype.forEach` takes.
3308
- *
3309
- * NOTE: The order of the mappings is NOT guaranteed.
3310
- */
3311
- MappingList$1.prototype.unsortedForEach =
3312
- function MappingList_forEach(aCallback, aThisArg) {
3313
- this._array.forEach(aCallback, aThisArg);
3314
- };
3315
-
3316
- /**
3317
- * Add the given source mapping.
3318
- *
3319
- * @param Object aMapping
3320
- */
3321
- MappingList$1.prototype.add = function MappingList_add(aMapping) {
3322
- if (generatedPositionAfter(this._last, aMapping)) {
3323
- this._last = aMapping;
3324
- this._array.push(aMapping);
3325
- } else {
3326
- this._sorted = false;
3327
- this._array.push(aMapping);
3328
- }
3329
- };
3330
-
3331
- /**
3332
- * Returns the flat, sorted array of mappings. The mappings are sorted by
3333
- * generated position.
3334
- *
3335
- * WARNING: This method returns internal data without copying, for
3336
- * performance. The return value must NOT be mutated, and should be treated as
3337
- * an immutable borrow. If you want to take ownership, you must make your own
3338
- * copy.
3339
- */
3340
- MappingList$1.prototype.toArray = function MappingList_toArray() {
3341
- if (!this._sorted) {
3342
- this._array.sort(util$3.compareByGeneratedPositionsInflated);
3343
- this._sorted = true;
3344
- }
3345
- return this._array;
3346
- };
3347
-
3348
- mappingList.MappingList = MappingList$1;
3349
-
3350
- /* -*- Mode: js; js-indent-level: 2; -*- */
3351
-
3352
- /*
3353
- * Copyright 2011 Mozilla Foundation and contributors
3354
- * Licensed under the New BSD license. See LICENSE or:
3355
- * http://opensource.org/licenses/BSD-3-Clause
3356
- */
3357
-
3358
- var base64VLQ$1 = base64Vlq;
3359
- var util$2 = util$5;
3360
- var ArraySet$1 = arraySet.ArraySet;
3361
- var MappingList = mappingList.MappingList;
3362
-
3363
- /**
3364
- * An instance of the SourceMapGenerator represents a source map which is
3365
- * being built incrementally. You may pass an object with the following
3366
- * properties:
3367
- *
3368
- * - file: The filename of the generated source.
3369
- * - sourceRoot: A root for all relative URLs in this source map.
3370
- */
3371
- function SourceMapGenerator$1(aArgs) {
3372
- if (!aArgs) {
3373
- aArgs = {};
3374
- }
3375
- this._file = util$2.getArg(aArgs, 'file', null);
3376
- this._sourceRoot = util$2.getArg(aArgs, 'sourceRoot', null);
3377
- this._skipValidation = util$2.getArg(aArgs, 'skipValidation', false);
3378
- this._sources = new ArraySet$1();
3379
- this._names = new ArraySet$1();
3380
- this._mappings = new MappingList();
3381
- this._sourcesContents = null;
3382
- }
3383
-
3384
- SourceMapGenerator$1.prototype._version = 3;
3385
-
3386
- /**
3387
- * Creates a new SourceMapGenerator based on a SourceMapConsumer
3388
- *
3389
- * @param aSourceMapConsumer The SourceMap.
3390
- */
3391
- SourceMapGenerator$1.fromSourceMap =
3392
- function SourceMapGenerator_fromSourceMap(aSourceMapConsumer) {
3393
- var sourceRoot = aSourceMapConsumer.sourceRoot;
3394
- var generator = new SourceMapGenerator$1({
3395
- file: aSourceMapConsumer.file,
3396
- sourceRoot: sourceRoot
3397
- });
3398
- aSourceMapConsumer.eachMapping(function (mapping) {
3399
- var newMapping = {
3400
- generated: {
3401
- line: mapping.generatedLine,
3402
- column: mapping.generatedColumn
3403
- }
3404
- };
3405
-
3406
- if (mapping.source != null) {
3407
- newMapping.source = mapping.source;
3408
- if (sourceRoot != null) {
3409
- newMapping.source = util$2.relative(sourceRoot, newMapping.source);
3410
- }
3411
-
3412
- newMapping.original = {
3413
- line: mapping.originalLine,
3414
- column: mapping.originalColumn
3415
- };
3416
-
3417
- if (mapping.name != null) {
3418
- newMapping.name = mapping.name;
3419
- }
3420
- }
3421
-
3422
- generator.addMapping(newMapping);
3423
- });
3424
- aSourceMapConsumer.sources.forEach(function (sourceFile) {
3425
- var sourceRelative = sourceFile;
3426
- if (sourceRoot !== null) {
3427
- sourceRelative = util$2.relative(sourceRoot, sourceFile);
3428
- }
3429
-
3430
- if (!generator._sources.has(sourceRelative)) {
3431
- generator._sources.add(sourceRelative);
3432
- }
3433
-
3434
- var content = aSourceMapConsumer.sourceContentFor(sourceFile);
3435
- if (content != null) {
3436
- generator.setSourceContent(sourceFile, content);
3437
- }
3438
- });
3439
- return generator;
3440
- };
3441
-
3442
- /**
3443
- * Add a single mapping from original source line and column to the generated
3444
- * source's line and column for this source map being created. The mapping
3445
- * object should have the following properties:
3446
- *
3447
- * - generated: An object with the generated line and column positions.
3448
- * - original: An object with the original line and column positions.
3449
- * - source: The original source file (relative to the sourceRoot).
3450
- * - name: An optional original token name for this mapping.
3451
- */
3452
- SourceMapGenerator$1.prototype.addMapping =
3453
- function SourceMapGenerator_addMapping(aArgs) {
3454
- var generated = util$2.getArg(aArgs, 'generated');
3455
- var original = util$2.getArg(aArgs, 'original', null);
3456
- var source = util$2.getArg(aArgs, 'source', null);
3457
- var name = util$2.getArg(aArgs, 'name', null);
3458
-
3459
- if (!this._skipValidation) {
3460
- this._validateMapping(generated, original, source, name);
3461
- }
3462
-
3463
- if (source != null) {
3464
- source = String(source);
3465
- if (!this._sources.has(source)) {
3466
- this._sources.add(source);
3467
- }
3468
- }
3469
-
3470
- if (name != null) {
3471
- name = String(name);
3472
- if (!this._names.has(name)) {
3473
- this._names.add(name);
3474
- }
3475
- }
3476
-
3477
- this._mappings.add({
3478
- generatedLine: generated.line,
3479
- generatedColumn: generated.column,
3480
- originalLine: original != null && original.line,
3481
- originalColumn: original != null && original.column,
3482
- source: source,
3483
- name: name
3484
- });
3485
- };
3486
-
3487
- /**
3488
- * Set the source content for a source file.
3489
- */
3490
- SourceMapGenerator$1.prototype.setSourceContent =
3491
- function SourceMapGenerator_setSourceContent(aSourceFile, aSourceContent) {
3492
- var source = aSourceFile;
3493
- if (this._sourceRoot != null) {
3494
- source = util$2.relative(this._sourceRoot, source);
3495
- }
3496
-
3497
- if (aSourceContent != null) {
3498
- // Add the source content to the _sourcesContents map.
3499
- // Create a new _sourcesContents map if the property is null.
3500
- if (!this._sourcesContents) {
3501
- this._sourcesContents = Object.create(null);
3502
- }
3503
- this._sourcesContents[util$2.toSetString(source)] = aSourceContent;
3504
- } else if (this._sourcesContents) {
3505
- // Remove the source file from the _sourcesContents map.
3506
- // If the _sourcesContents map is empty, set the property to null.
3507
- delete this._sourcesContents[util$2.toSetString(source)];
3508
- if (Object.keys(this._sourcesContents).length === 0) {
3509
- this._sourcesContents = null;
3510
- }
3511
- }
3512
- };
3513
-
3514
- /**
3515
- * Applies the mappings of a sub-source-map for a specific source file to the
3516
- * source map being generated. Each mapping to the supplied source file is
3517
- * rewritten using the supplied source map. Note: The resolution for the
3518
- * resulting mappings is the minimium of this map and the supplied map.
3519
- *
3520
- * @param aSourceMapConsumer The source map to be applied.
3521
- * @param aSourceFile Optional. The filename of the source file.
3522
- * If omitted, SourceMapConsumer's file property will be used.
3523
- * @param aSourceMapPath Optional. The dirname of the path to the source map
3524
- * to be applied. If relative, it is relative to the SourceMapConsumer.
3525
- * This parameter is needed when the two source maps aren't in the same
3526
- * directory, and the source map to be applied contains relative source
3527
- * paths. If so, those relative source paths need to be rewritten
3528
- * relative to the SourceMapGenerator.
3529
- */
3530
- SourceMapGenerator$1.prototype.applySourceMap =
3531
- function SourceMapGenerator_applySourceMap(aSourceMapConsumer, aSourceFile, aSourceMapPath) {
3532
- var sourceFile = aSourceFile;
3533
- // If aSourceFile is omitted, we will use the file property of the SourceMap
3534
- if (aSourceFile == null) {
3535
- if (aSourceMapConsumer.file == null) {
3536
- throw new Error(
3537
- 'SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, ' +
3538
- 'or the source map\'s "file" property. Both were omitted.'
3539
- );
3540
- }
3541
- sourceFile = aSourceMapConsumer.file;
3542
- }
3543
- var sourceRoot = this._sourceRoot;
3544
- // Make "sourceFile" relative if an absolute Url is passed.
3545
- if (sourceRoot != null) {
3546
- sourceFile = util$2.relative(sourceRoot, sourceFile);
3547
- }
3548
- // Applying the SourceMap can add and remove items from the sources and
3549
- // the names array.
3550
- var newSources = new ArraySet$1();
3551
- var newNames = new ArraySet$1();
3552
-
3553
- // Find mappings for the "sourceFile"
3554
- this._mappings.unsortedForEach(function (mapping) {
3555
- if (mapping.source === sourceFile && mapping.originalLine != null) {
3556
- // Check if it can be mapped by the source map, then update the mapping.
3557
- var original = aSourceMapConsumer.originalPositionFor({
3558
- line: mapping.originalLine,
3559
- column: mapping.originalColumn
3560
- });
3561
- if (original.source != null) {
3562
- // Copy mapping
3563
- mapping.source = original.source;
3564
- if (aSourceMapPath != null) {
3565
- mapping.source = util$2.join(aSourceMapPath, mapping.source);
3566
- }
3567
- if (sourceRoot != null) {
3568
- mapping.source = util$2.relative(sourceRoot, mapping.source);
3569
- }
3570
- mapping.originalLine = original.line;
3571
- mapping.originalColumn = original.column;
3572
- if (original.name != null) {
3573
- mapping.name = original.name;
3574
- }
3575
- }
3576
- }
3577
-
3578
- var source = mapping.source;
3579
- if (source != null && !newSources.has(source)) {
3580
- newSources.add(source);
3581
- }
3582
-
3583
- var name = mapping.name;
3584
- if (name != null && !newNames.has(name)) {
3585
- newNames.add(name);
3586
- }
3587
-
3588
- }, this);
3589
- this._sources = newSources;
3590
- this._names = newNames;
3591
-
3592
- // Copy sourcesContents of applied map.
3593
- aSourceMapConsumer.sources.forEach(function (sourceFile) {
3594
- var content = aSourceMapConsumer.sourceContentFor(sourceFile);
3595
- if (content != null) {
3596
- if (aSourceMapPath != null) {
3597
- sourceFile = util$2.join(aSourceMapPath, sourceFile);
3598
- }
3599
- if (sourceRoot != null) {
3600
- sourceFile = util$2.relative(sourceRoot, sourceFile);
3601
- }
3602
- this.setSourceContent(sourceFile, content);
3603
- }
3604
- }, this);
3605
- };
3606
-
3607
- /**
3608
- * A mapping can have one of the three levels of data:
3609
- *
3610
- * 1. Just the generated position.
3611
- * 2. The Generated position, original position, and original source.
3612
- * 3. Generated and original position, original source, as well as a name
3613
- * token.
3614
- *
3615
- * To maintain consistency, we validate that any new mapping being added falls
3616
- * in to one of these categories.
3617
- */
3618
- SourceMapGenerator$1.prototype._validateMapping =
3619
- function SourceMapGenerator_validateMapping(aGenerated, aOriginal, aSource,
3620
- aName) {
3621
- // When aOriginal is truthy but has empty values for .line and .column,
3622
- // it is most likely a programmer error. In this case we throw a very
3623
- // specific error message to try to guide them the right way.
3624
- // For example: https://github.com/Polymer/polymer-bundler/pull/519
3625
- if (aOriginal && typeof aOriginal.line !== 'number' && typeof aOriginal.column !== 'number') {
3626
- throw new Error(
3627
- 'original.line and original.column are not numbers -- you probably meant to omit ' +
3628
- 'the original mapping entirely and only map the generated position. If so, pass ' +
3629
- 'null for the original mapping instead of an object with empty or null values.'
3630
- );
3631
- }
3632
-
3633
- if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
3634
- && aGenerated.line > 0 && aGenerated.column >= 0
3635
- && !aOriginal && !aSource && !aName) {
3636
- // Case 1.
3637
- return;
3638
- }
3639
- else if (aGenerated && 'line' in aGenerated && 'column' in aGenerated
3640
- && aOriginal && 'line' in aOriginal && 'column' in aOriginal
3641
- && aGenerated.line > 0 && aGenerated.column >= 0
3642
- && aOriginal.line > 0 && aOriginal.column >= 0
3643
- && aSource) {
3644
- // Cases 2 and 3.
3645
- return;
3646
- }
3647
- else {
3648
- throw new Error('Invalid mapping: ' + JSON.stringify({
3649
- generated: aGenerated,
3650
- source: aSource,
3651
- original: aOriginal,
3652
- name: aName
3653
- }));
3654
- }
3655
- };
3656
-
3657
- /**
3658
- * Serialize the accumulated mappings in to the stream of base 64 VLQs
3659
- * specified by the source map format.
3660
- */
3661
- SourceMapGenerator$1.prototype._serializeMappings =
3662
- function SourceMapGenerator_serializeMappings() {
3663
- var previousGeneratedColumn = 0;
3664
- var previousGeneratedLine = 1;
3665
- var previousOriginalColumn = 0;
3666
- var previousOriginalLine = 0;
3667
- var previousName = 0;
3668
- var previousSource = 0;
3669
- var result = '';
3670
- var next;
3671
- var mapping;
3672
- var nameIdx;
3673
- var sourceIdx;
3674
-
3675
- var mappings = this._mappings.toArray();
3676
- for (var i = 0, len = mappings.length; i < len; i++) {
3677
- mapping = mappings[i];
3678
- next = '';
3679
-
3680
- if (mapping.generatedLine !== previousGeneratedLine) {
3681
- previousGeneratedColumn = 0;
3682
- while (mapping.generatedLine !== previousGeneratedLine) {
3683
- next += ';';
3684
- previousGeneratedLine++;
3685
- }
3686
- }
3687
- else {
3688
- if (i > 0) {
3689
- if (!util$2.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])) {
3690
- continue;
3691
- }
3692
- next += ',';
3693
- }
3694
- }
3695
-
3696
- next += base64VLQ$1.encode(mapping.generatedColumn
3697
- - previousGeneratedColumn);
3698
- previousGeneratedColumn = mapping.generatedColumn;
3699
-
3700
- if (mapping.source != null) {
3701
- sourceIdx = this._sources.indexOf(mapping.source);
3702
- next += base64VLQ$1.encode(sourceIdx - previousSource);
3703
- previousSource = sourceIdx;
3704
-
3705
- // lines are stored 0-based in SourceMap spec version 3
3706
- next += base64VLQ$1.encode(mapping.originalLine - 1
3707
- - previousOriginalLine);
3708
- previousOriginalLine = mapping.originalLine - 1;
3709
-
3710
- next += base64VLQ$1.encode(mapping.originalColumn
3711
- - previousOriginalColumn);
3712
- previousOriginalColumn = mapping.originalColumn;
3713
-
3714
- if (mapping.name != null) {
3715
- nameIdx = this._names.indexOf(mapping.name);
3716
- next += base64VLQ$1.encode(nameIdx - previousName);
3717
- previousName = nameIdx;
3718
- }
3719
- }
3720
-
3721
- result += next;
3722
- }
3723
-
3724
- return result;
3725
- };
3726
-
3727
- SourceMapGenerator$1.prototype._generateSourcesContent =
3728
- function SourceMapGenerator_generateSourcesContent(aSources, aSourceRoot) {
3729
- return aSources.map(function (source) {
3730
- if (!this._sourcesContents) {
3731
- return null;
3732
- }
3733
- if (aSourceRoot != null) {
3734
- source = util$2.relative(aSourceRoot, source);
3735
- }
3736
- var key = util$2.toSetString(source);
3737
- return Object.prototype.hasOwnProperty.call(this._sourcesContents, key)
3738
- ? this._sourcesContents[key]
3739
- : null;
3740
- }, this);
3741
- };
3742
-
3743
- /**
3744
- * Externalize the source map.
3745
- */
3746
- SourceMapGenerator$1.prototype.toJSON =
3747
- function SourceMapGenerator_toJSON() {
3748
- var map = {
3749
- version: this._version,
3750
- sources: this._sources.toArray(),
3751
- names: this._names.toArray(),
3752
- mappings: this._serializeMappings()
3753
- };
3754
- if (this._file != null) {
3755
- map.file = this._file;
3756
- }
3757
- if (this._sourceRoot != null) {
3758
- map.sourceRoot = this._sourceRoot;
3759
- }
3760
- if (this._sourcesContents) {
3761
- map.sourcesContent = this._generateSourcesContent(map.sources, map.sourceRoot);
3762
- }
3763
-
3764
- return map;
3765
- };
3766
-
3767
- /**
3768
- * Render the source map being generated to a string.
3769
- */
3770
- SourceMapGenerator$1.prototype.toString =
3771
- function SourceMapGenerator_toString() {
3772
- return JSON.stringify(this.toJSON());
3773
- };
3774
-
3775
- sourceMapGenerator.SourceMapGenerator = SourceMapGenerator$1;
3776
-
3777
- var sourceMapConsumer = {};
3778
-
3779
- var binarySearch$1 = {};
3780
-
3781
- /* -*- Mode: js; js-indent-level: 2; -*- */
3782
-
3783
- (function (exports) {
3784
- /*
3785
- * Copyright 2011 Mozilla Foundation and contributors
3786
- * Licensed under the New BSD license. See LICENSE or:
3787
- * http://opensource.org/licenses/BSD-3-Clause
3788
- */
3789
-
3790
- exports.GREATEST_LOWER_BOUND = 1;
3791
- exports.LEAST_UPPER_BOUND = 2;
3792
-
3793
- /**
3794
- * Recursive implementation of binary search.
3795
- *
3796
- * @param aLow Indices here and lower do not contain the needle.
3797
- * @param aHigh Indices here and higher do not contain the needle.
3798
- * @param aNeedle The element being searched for.
3799
- * @param aHaystack The non-empty array being searched.
3800
- * @param aCompare Function which takes two elements and returns -1, 0, or 1.
3801
- * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
3802
- * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
3803
- * closest element that is smaller than or greater than the one we are
3804
- * searching for, respectively, if the exact element cannot be found.
3805
- */
3806
- function recursiveSearch(aLow, aHigh, aNeedle, aHaystack, aCompare, aBias) {
3807
- // This function terminates when one of the following is true:
3808
- //
3809
- // 1. We find the exact element we are looking for.
3810
- //
3811
- // 2. We did not find the exact element, but we can return the index of
3812
- // the next-closest element.
3813
- //
3814
- // 3. We did not find the exact element, and there is no next-closest
3815
- // element than the one we are searching for, so we return -1.
3816
- var mid = Math.floor((aHigh - aLow) / 2) + aLow;
3817
- var cmp = aCompare(aNeedle, aHaystack[mid], true);
3818
- if (cmp === 0) {
3819
- // Found the element we are looking for.
3820
- return mid;
3821
- }
3822
- else if (cmp > 0) {
3823
- // Our needle is greater than aHaystack[mid].
3824
- if (aHigh - mid > 1) {
3825
- // The element is in the upper half.
3826
- return recursiveSearch(mid, aHigh, aNeedle, aHaystack, aCompare, aBias);
3827
- }
3828
-
3829
- // The exact needle element was not found in this haystack. Determine if
3830
- // we are in termination case (3) or (2) and return the appropriate thing.
3831
- if (aBias == exports.LEAST_UPPER_BOUND) {
3832
- return aHigh < aHaystack.length ? aHigh : -1;
3833
- } else {
3834
- return mid;
3835
- }
3836
- }
3837
- else {
3838
- // Our needle is less than aHaystack[mid].
3839
- if (mid - aLow > 1) {
3840
- // The element is in the lower half.
3841
- return recursiveSearch(aLow, mid, aNeedle, aHaystack, aCompare, aBias);
3842
- }
3843
-
3844
- // we are in termination case (3) or (2) and return the appropriate thing.
3845
- if (aBias == exports.LEAST_UPPER_BOUND) {
3846
- return mid;
3847
- } else {
3848
- return aLow < 0 ? -1 : aLow;
3849
- }
3850
- }
3851
- }
3852
-
3853
- /**
3854
- * This is an implementation of binary search which will always try and return
3855
- * the index of the closest element if there is no exact hit. This is because
3856
- * mappings between original and generated line/col pairs are single points,
3857
- * and there is an implicit region between each of them, so a miss just means
3858
- * that you aren't on the very start of a region.
3859
- *
3860
- * @param aNeedle The element you are looking for.
3861
- * @param aHaystack The array that is being searched.
3862
- * @param aCompare A function which takes the needle and an element in the
3863
- * array and returns -1, 0, or 1 depending on whether the needle is less
3864
- * than, equal to, or greater than the element, respectively.
3865
- * @param aBias Either 'binarySearch.GREATEST_LOWER_BOUND' or
3866
- * 'binarySearch.LEAST_UPPER_BOUND'. Specifies whether to return the
3867
- * closest element that is smaller than or greater than the one we are
3868
- * searching for, respectively, if the exact element cannot be found.
3869
- * Defaults to 'binarySearch.GREATEST_LOWER_BOUND'.
3870
- */
3871
- exports.search = function search(aNeedle, aHaystack, aCompare, aBias) {
3872
- if (aHaystack.length === 0) {
3873
- return -1;
3874
- }
3875
-
3876
- var index = recursiveSearch(-1, aHaystack.length, aNeedle, aHaystack,
3877
- aCompare, aBias || exports.GREATEST_LOWER_BOUND);
3878
- if (index < 0) {
3879
- return -1;
3880
- }
3881
-
3882
- // We have found either the exact element, or the next-closest element than
3883
- // the one we are searching for. However, there may be more than one such
3884
- // element. Make sure we always return the smallest of these.
3885
- while (index - 1 >= 0) {
3886
- if (aCompare(aHaystack[index], aHaystack[index - 1], true) !== 0) {
3887
- break;
3888
- }
3889
- --index;
3890
- }
3891
-
3892
- return index;
3893
- };
3894
- } (binarySearch$1));
3895
-
3896
- var quickSort$1 = {};
3897
-
3898
- /* -*- Mode: js; js-indent-level: 2; -*- */
3899
-
3900
- /*
3901
- * Copyright 2011 Mozilla Foundation and contributors
3902
- * Licensed under the New BSD license. See LICENSE or:
3903
- * http://opensource.org/licenses/BSD-3-Clause
3904
- */
3905
-
3906
- // It turns out that some (most?) JavaScript engines don't self-host
3907
- // `Array.prototype.sort`. This makes sense because C++ will likely remain
3908
- // faster than JS when doing raw CPU-intensive sorting. However, when using a
3909
- // custom comparator function, calling back and forth between the VM's C++ and
3910
- // JIT'd JS is rather slow *and* loses JIT type information, resulting in
3911
- // worse generated code for the comparator function than would be optimal. In
3912
- // fact, when sorting with a comparator, these costs outweigh the benefits of
3913
- // sorting in C++. By using our own JS-implemented Quick Sort (below), we get
3914
- // a ~3500ms mean speed-up in `bench/bench.html`.
3915
-
3916
- function SortTemplate(comparator) {
3917
-
3918
- /**
3919
- * Swap the elements indexed by `x` and `y` in the array `ary`.
3920
- *
3921
- * @param {Array} ary
3922
- * The array.
3923
- * @param {Number} x
3924
- * The index of the first item.
3925
- * @param {Number} y
3926
- * The index of the second item.
3927
- */
3928
- function swap(ary, x, y) {
3929
- var temp = ary[x];
3930
- ary[x] = ary[y];
3931
- ary[y] = temp;
3932
- }
3933
-
3934
- /**
3935
- * Returns a random integer within the range `low .. high` inclusive.
3936
- *
3937
- * @param {Number} low
3938
- * The lower bound on the range.
3939
- * @param {Number} high
3940
- * The upper bound on the range.
3941
- */
3942
- function randomIntInRange(low, high) {
3943
- return Math.round(low + (Math.random() * (high - low)));
3944
- }
3945
-
3946
- /**
3947
- * The Quick Sort algorithm.
3948
- *
3949
- * @param {Array} ary
3950
- * An array to sort.
3951
- * @param {function} comparator
3952
- * Function to use to compare two items.
3953
- * @param {Number} p
3954
- * Start index of the array
3955
- * @param {Number} r
3956
- * End index of the array
3957
- */
3958
- function doQuickSort(ary, comparator, p, r) {
3959
- // If our lower bound is less than our upper bound, we (1) partition the
3960
- // array into two pieces and (2) recurse on each half. If it is not, this is
3961
- // the empty array and our base case.
3962
-
3963
- if (p < r) {
3964
- // (1) Partitioning.
3965
- //
3966
- // The partitioning chooses a pivot between `p` and `r` and moves all
3967
- // elements that are less than or equal to the pivot to the before it, and
3968
- // all the elements that are greater than it after it. The effect is that
3969
- // once partition is done, the pivot is in the exact place it will be when
3970
- // the array is put in sorted order, and it will not need to be moved
3971
- // again. This runs in O(n) time.
3972
-
3973
- // Always choose a random pivot so that an input array which is reverse
3974
- // sorted does not cause O(n^2) running time.
3975
- var pivotIndex = randomIntInRange(p, r);
3976
- var i = p - 1;
3977
-
3978
- swap(ary, pivotIndex, r);
3979
- var pivot = ary[r];
3980
-
3981
- // Immediately after `j` is incremented in this loop, the following hold
3982
- // true:
3983
- //
3984
- // * Every element in `ary[p .. i]` is less than or equal to the pivot.
3985
- //
3986
- // * Every element in `ary[i+1 .. j-1]` is greater than the pivot.
3987
- for (var j = p; j < r; j++) {
3988
- if (comparator(ary[j], pivot, false) <= 0) {
3989
- i += 1;
3990
- swap(ary, i, j);
3991
- }
3992
- }
3993
-
3994
- swap(ary, i + 1, j);
3995
- var q = i + 1;
3996
-
3997
- // (2) Recurse on each half.
3998
-
3999
- doQuickSort(ary, comparator, p, q - 1);
4000
- doQuickSort(ary, comparator, q + 1, r);
4001
- }
4002
- }
4003
-
4004
- return doQuickSort;
4005
- }
4006
-
4007
- function cloneSort(comparator) {
4008
- let template = SortTemplate.toString();
4009
- let templateFn = new Function(`return ${template}`)();
4010
- return templateFn(comparator);
4011
- }
4012
-
4013
- /**
4014
- * Sort the given array in-place with the given comparator function.
4015
- *
4016
- * @param {Array} ary
4017
- * An array to sort.
4018
- * @param {function} comparator
4019
- * Function to use to compare two items.
4020
- */
4021
-
4022
- let sortCache = new WeakMap();
4023
- quickSort$1.quickSort = function (ary, comparator, start = 0) {
4024
- let doQuickSort = sortCache.get(comparator);
4025
- if (doQuickSort === void 0) {
4026
- doQuickSort = cloneSort(comparator);
4027
- sortCache.set(comparator, doQuickSort);
4028
- }
4029
- doQuickSort(ary, comparator, start, ary.length - 1);
4030
- };
4031
-
4032
- /* -*- Mode: js; js-indent-level: 2; -*- */
4033
-
4034
- /*
4035
- * Copyright 2011 Mozilla Foundation and contributors
4036
- * Licensed under the New BSD license. See LICENSE or:
4037
- * http://opensource.org/licenses/BSD-3-Clause
4038
- */
4039
-
4040
- var util$1 = util$5;
4041
- var binarySearch = binarySearch$1;
4042
- var ArraySet = arraySet.ArraySet;
4043
- var base64VLQ = base64Vlq;
4044
- var quickSort = quickSort$1.quickSort;
4045
-
4046
- function SourceMapConsumer$1(aSourceMap, aSourceMapURL) {
4047
- var sourceMap = aSourceMap;
4048
- if (typeof aSourceMap === 'string') {
4049
- sourceMap = util$1.parseSourceMapInput(aSourceMap);
4050
- }
4051
-
4052
- return sourceMap.sections != null
4053
- ? new IndexedSourceMapConsumer(sourceMap, aSourceMapURL)
4054
- : new BasicSourceMapConsumer(sourceMap, aSourceMapURL);
4055
- }
4056
-
4057
- SourceMapConsumer$1.fromSourceMap = function(aSourceMap, aSourceMapURL) {
4058
- return BasicSourceMapConsumer.fromSourceMap(aSourceMap, aSourceMapURL);
4059
- };
4060
-
4061
- /**
4062
- * The version of the source mapping spec that we are consuming.
4063
- */
4064
- SourceMapConsumer$1.prototype._version = 3;
4065
-
4066
- // `__generatedMappings` and `__originalMappings` are arrays that hold the
4067
- // parsed mapping coordinates from the source map's "mappings" attribute. They
4068
- // are lazily instantiated, accessed via the `_generatedMappings` and
4069
- // `_originalMappings` getters respectively, and we only parse the mappings
4070
- // and create these arrays once queried for a source location. We jump through
4071
- // these hoops because there can be many thousands of mappings, and parsing
4072
- // them is expensive, so we only want to do it if we must.
4073
- //
4074
- // Each object in the arrays is of the form:
4075
- //
4076
- // {
4077
- // generatedLine: The line number in the generated code,
4078
- // generatedColumn: The column number in the generated code,
4079
- // source: The path to the original source file that generated this
4080
- // chunk of code,
4081
- // originalLine: The line number in the original source that
4082
- // corresponds to this chunk of generated code,
4083
- // originalColumn: The column number in the original source that
4084
- // corresponds to this chunk of generated code,
4085
- // name: The name of the original symbol which generated this chunk of
4086
- // code.
4087
- // }
4088
- //
4089
- // All properties except for `generatedLine` and `generatedColumn` can be
4090
- // `null`.
4091
- //
4092
- // `_generatedMappings` is ordered by the generated positions.
4093
- //
4094
- // `_originalMappings` is ordered by the original positions.
4095
-
4096
- SourceMapConsumer$1.prototype.__generatedMappings = null;
4097
- Object.defineProperty(SourceMapConsumer$1.prototype, '_generatedMappings', {
4098
- configurable: true,
4099
- enumerable: true,
4100
- get: function () {
4101
- if (!this.__generatedMappings) {
4102
- this._parseMappings(this._mappings, this.sourceRoot);
4103
- }
4104
-
4105
- return this.__generatedMappings;
4106
- }
4107
- });
4108
-
4109
- SourceMapConsumer$1.prototype.__originalMappings = null;
4110
- Object.defineProperty(SourceMapConsumer$1.prototype, '_originalMappings', {
4111
- configurable: true,
4112
- enumerable: true,
4113
- get: function () {
4114
- if (!this.__originalMappings) {
4115
- this._parseMappings(this._mappings, this.sourceRoot);
4116
- }
4117
-
4118
- return this.__originalMappings;
4119
- }
4120
- });
4121
-
4122
- SourceMapConsumer$1.prototype._charIsMappingSeparator =
4123
- function SourceMapConsumer_charIsMappingSeparator(aStr, index) {
4124
- var c = aStr.charAt(index);
4125
- return c === ";" || c === ",";
4126
- };
4127
-
4128
- /**
4129
- * Parse the mappings in a string in to a data structure which we can easily
4130
- * query (the ordered arrays in the `this.__generatedMappings` and
4131
- * `this.__originalMappings` properties).
4132
- */
4133
- SourceMapConsumer$1.prototype._parseMappings =
4134
- function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
4135
- throw new Error("Subclasses must implement _parseMappings");
4136
- };
4137
-
4138
- SourceMapConsumer$1.GENERATED_ORDER = 1;
4139
- SourceMapConsumer$1.ORIGINAL_ORDER = 2;
4140
-
4141
- SourceMapConsumer$1.GREATEST_LOWER_BOUND = 1;
4142
- SourceMapConsumer$1.LEAST_UPPER_BOUND = 2;
4143
-
4144
- /**
4145
- * Iterate over each mapping between an original source/line/column and a
4146
- * generated line/column in this source map.
4147
- *
4148
- * @param Function aCallback
4149
- * The function that is called with each mapping.
4150
- * @param Object aContext
4151
- * Optional. If specified, this object will be the value of `this` every
4152
- * time that `aCallback` is called.
4153
- * @param aOrder
4154
- * Either `SourceMapConsumer.GENERATED_ORDER` or
4155
- * `SourceMapConsumer.ORIGINAL_ORDER`. Specifies whether you want to
4156
- * iterate over the mappings sorted by the generated file's line/column
4157
- * order or the original's source/line/column order, respectively. Defaults to
4158
- * `SourceMapConsumer.GENERATED_ORDER`.
4159
- */
4160
- SourceMapConsumer$1.prototype.eachMapping =
4161
- function SourceMapConsumer_eachMapping(aCallback, aContext, aOrder) {
4162
- var context = aContext || null;
4163
- var order = aOrder || SourceMapConsumer$1.GENERATED_ORDER;
4164
-
4165
- var mappings;
4166
- switch (order) {
4167
- case SourceMapConsumer$1.GENERATED_ORDER:
4168
- mappings = this._generatedMappings;
4169
- break;
4170
- case SourceMapConsumer$1.ORIGINAL_ORDER:
4171
- mappings = this._originalMappings;
4172
- break;
4173
- default:
4174
- throw new Error("Unknown order of iteration.");
4175
- }
4176
-
4177
- var sourceRoot = this.sourceRoot;
4178
- var boundCallback = aCallback.bind(context);
4179
- var names = this._names;
4180
- var sources = this._sources;
4181
- var sourceMapURL = this._sourceMapURL;
4182
-
4183
- for (var i = 0, n = mappings.length; i < n; i++) {
4184
- var mapping = mappings[i];
4185
- var source = mapping.source === null ? null : sources.at(mapping.source);
4186
- source = util$1.computeSourceURL(sourceRoot, source, sourceMapURL);
4187
- boundCallback({
4188
- source: source,
4189
- generatedLine: mapping.generatedLine,
4190
- generatedColumn: mapping.generatedColumn,
4191
- originalLine: mapping.originalLine,
4192
- originalColumn: mapping.originalColumn,
4193
- name: mapping.name === null ? null : names.at(mapping.name)
4194
- });
4195
- }
4196
- };
4197
-
4198
- /**
4199
- * Returns all generated line and column information for the original source,
4200
- * line, and column provided. If no column is provided, returns all mappings
4201
- * corresponding to a either the line we are searching for or the next
4202
- * closest line that has any mappings. Otherwise, returns all mappings
4203
- * corresponding to the given line and either the column we are searching for
4204
- * or the next closest column that has any offsets.
4205
- *
4206
- * The only argument is an object with the following properties:
4207
- *
4208
- * - source: The filename of the original source.
4209
- * - line: The line number in the original source. The line number is 1-based.
4210
- * - column: Optional. the column number in the original source.
4211
- * The column number is 0-based.
4212
- *
4213
- * and an array of objects is returned, each with the following properties:
4214
- *
4215
- * - line: The line number in the generated source, or null. The
4216
- * line number is 1-based.
4217
- * - column: The column number in the generated source, or null.
4218
- * The column number is 0-based.
4219
- */
4220
- SourceMapConsumer$1.prototype.allGeneratedPositionsFor =
4221
- function SourceMapConsumer_allGeneratedPositionsFor(aArgs) {
4222
- var line = util$1.getArg(aArgs, 'line');
4223
-
4224
- // When there is no exact match, BasicSourceMapConsumer.prototype._findMapping
4225
- // returns the index of the closest mapping less than the needle. By
4226
- // setting needle.originalColumn to 0, we thus find the last mapping for
4227
- // the given line, provided such a mapping exists.
4228
- var needle = {
4229
- source: util$1.getArg(aArgs, 'source'),
4230
- originalLine: line,
4231
- originalColumn: util$1.getArg(aArgs, 'column', 0)
4232
- };
4233
-
4234
- needle.source = this._findSourceIndex(needle.source);
4235
- if (needle.source < 0) {
4236
- return [];
4237
- }
4238
-
4239
- var mappings = [];
4240
-
4241
- var index = this._findMapping(needle,
4242
- this._originalMappings,
4243
- "originalLine",
4244
- "originalColumn",
4245
- util$1.compareByOriginalPositions,
4246
- binarySearch.LEAST_UPPER_BOUND);
4247
- if (index >= 0) {
4248
- var mapping = this._originalMappings[index];
4249
-
4250
- if (aArgs.column === undefined) {
4251
- var originalLine = mapping.originalLine;
4252
-
4253
- // Iterate until either we run out of mappings, or we run into
4254
- // a mapping for a different line than the one we found. Since
4255
- // mappings are sorted, this is guaranteed to find all mappings for
4256
- // the line we found.
4257
- while (mapping && mapping.originalLine === originalLine) {
4258
- mappings.push({
4259
- line: util$1.getArg(mapping, 'generatedLine', null),
4260
- column: util$1.getArg(mapping, 'generatedColumn', null),
4261
- lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
4262
- });
4263
-
4264
- mapping = this._originalMappings[++index];
4265
- }
4266
- } else {
4267
- var originalColumn = mapping.originalColumn;
4268
-
4269
- // Iterate until either we run out of mappings, or we run into
4270
- // a mapping for a different line than the one we were searching for.
4271
- // Since mappings are sorted, this is guaranteed to find all mappings for
4272
- // the line we are searching for.
4273
- while (mapping &&
4274
- mapping.originalLine === line &&
4275
- mapping.originalColumn == originalColumn) {
4276
- mappings.push({
4277
- line: util$1.getArg(mapping, 'generatedLine', null),
4278
- column: util$1.getArg(mapping, 'generatedColumn', null),
4279
- lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
4280
- });
4281
-
4282
- mapping = this._originalMappings[++index];
4283
- }
4284
- }
4285
- }
4286
-
4287
- return mappings;
4288
- };
4289
-
4290
- sourceMapConsumer.SourceMapConsumer = SourceMapConsumer$1;
4291
-
4292
- /**
4293
- * A BasicSourceMapConsumer instance represents a parsed source map which we can
4294
- * query for information about the original file positions by giving it a file
4295
- * position in the generated source.
4296
- *
4297
- * The first parameter is the raw source map (either as a JSON string, or
4298
- * already parsed to an object). According to the spec, source maps have the
4299
- * following attributes:
4300
- *
4301
- * - version: Which version of the source map spec this map is following.
4302
- * - sources: An array of URLs to the original source files.
4303
- * - names: An array of identifiers which can be referrenced by individual mappings.
4304
- * - sourceRoot: Optional. The URL root from which all sources are relative.
4305
- * - sourcesContent: Optional. An array of contents of the original source files.
4306
- * - mappings: A string of base64 VLQs which contain the actual mappings.
4307
- * - file: Optional. The generated file this source map is associated with.
4308
- *
4309
- * Here is an example source map, taken from the source map spec[0]:
4310
- *
4311
- * {
4312
- * version : 3,
4313
- * file: "out.js",
4314
- * sourceRoot : "",
4315
- * sources: ["foo.js", "bar.js"],
4316
- * names: ["src", "maps", "are", "fun"],
4317
- * mappings: "AA,AB;;ABCDE;"
4318
- * }
4319
- *
4320
- * The second parameter, if given, is a string whose value is the URL
4321
- * at which the source map was found. This URL is used to compute the
4322
- * sources array.
4323
- *
4324
- * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit?pli=1#
4325
- */
4326
- function BasicSourceMapConsumer(aSourceMap, aSourceMapURL) {
4327
- var sourceMap = aSourceMap;
4328
- if (typeof aSourceMap === 'string') {
4329
- sourceMap = util$1.parseSourceMapInput(aSourceMap);
4330
- }
4331
-
4332
- var version = util$1.getArg(sourceMap, 'version');
4333
- var sources = util$1.getArg(sourceMap, 'sources');
4334
- // Sass 3.3 leaves out the 'names' array, so we deviate from the spec (which
4335
- // requires the array) to play nice here.
4336
- var names = util$1.getArg(sourceMap, 'names', []);
4337
- var sourceRoot = util$1.getArg(sourceMap, 'sourceRoot', null);
4338
- var sourcesContent = util$1.getArg(sourceMap, 'sourcesContent', null);
4339
- var mappings = util$1.getArg(sourceMap, 'mappings');
4340
- var file = util$1.getArg(sourceMap, 'file', null);
4341
-
4342
- // Once again, Sass deviates from the spec and supplies the version as a
4343
- // string rather than a number, so we use loose equality checking here.
4344
- if (version != this._version) {
4345
- throw new Error('Unsupported version: ' + version);
4346
- }
4347
-
4348
- if (sourceRoot) {
4349
- sourceRoot = util$1.normalize(sourceRoot);
4350
- }
4351
-
4352
- sources = sources
4353
- .map(String)
4354
- // Some source maps produce relative source paths like "./foo.js" instead of
4355
- // "foo.js". Normalize these first so that future comparisons will succeed.
4356
- // See bugzil.la/1090768.
4357
- .map(util$1.normalize)
4358
- // Always ensure that absolute sources are internally stored relative to
4359
- // the source root, if the source root is absolute. Not doing this would
4360
- // be particularly problematic when the source root is a prefix of the
4361
- // source (valid, but why??). See github issue #199 and bugzil.la/1188982.
4362
- .map(function (source) {
4363
- return sourceRoot && util$1.isAbsolute(sourceRoot) && util$1.isAbsolute(source)
4364
- ? util$1.relative(sourceRoot, source)
4365
- : source;
4366
- });
4367
-
4368
- // Pass `true` below to allow duplicate names and sources. While source maps
4369
- // are intended to be compressed and deduplicated, the TypeScript compiler
4370
- // sometimes generates source maps with duplicates in them. See Github issue
4371
- // #72 and bugzil.la/889492.
4372
- this._names = ArraySet.fromArray(names.map(String), true);
4373
- this._sources = ArraySet.fromArray(sources, true);
4374
-
4375
- this._absoluteSources = this._sources.toArray().map(function (s) {
4376
- return util$1.computeSourceURL(sourceRoot, s, aSourceMapURL);
4377
- });
4378
-
4379
- this.sourceRoot = sourceRoot;
4380
- this.sourcesContent = sourcesContent;
4381
- this._mappings = mappings;
4382
- this._sourceMapURL = aSourceMapURL;
4383
- this.file = file;
4384
- }
4385
-
4386
- BasicSourceMapConsumer.prototype = Object.create(SourceMapConsumer$1.prototype);
4387
- BasicSourceMapConsumer.prototype.consumer = SourceMapConsumer$1;
4388
-
4389
- /**
4390
- * Utility function to find the index of a source. Returns -1 if not
4391
- * found.
4392
- */
4393
- BasicSourceMapConsumer.prototype._findSourceIndex = function(aSource) {
4394
- var relativeSource = aSource;
4395
- if (this.sourceRoot != null) {
4396
- relativeSource = util$1.relative(this.sourceRoot, relativeSource);
4397
- }
4398
-
4399
- if (this._sources.has(relativeSource)) {
4400
- return this._sources.indexOf(relativeSource);
4401
- }
4402
-
4403
- // Maybe aSource is an absolute URL as returned by |sources|. In
4404
- // this case we can't simply undo the transform.
4405
- var i;
4406
- for (i = 0; i < this._absoluteSources.length; ++i) {
4407
- if (this._absoluteSources[i] == aSource) {
4408
- return i;
4409
- }
4410
- }
4411
-
4412
- return -1;
4413
- };
4414
-
4415
- /**
4416
- * Create a BasicSourceMapConsumer from a SourceMapGenerator.
4417
- *
4418
- * @param SourceMapGenerator aSourceMap
4419
- * The source map that will be consumed.
4420
- * @param String aSourceMapURL
4421
- * The URL at which the source map can be found (optional)
4422
- * @returns BasicSourceMapConsumer
4423
- */
4424
- BasicSourceMapConsumer.fromSourceMap =
4425
- function SourceMapConsumer_fromSourceMap(aSourceMap, aSourceMapURL) {
4426
- var smc = Object.create(BasicSourceMapConsumer.prototype);
4427
-
4428
- var names = smc._names = ArraySet.fromArray(aSourceMap._names.toArray(), true);
4429
- var sources = smc._sources = ArraySet.fromArray(aSourceMap._sources.toArray(), true);
4430
- smc.sourceRoot = aSourceMap._sourceRoot;
4431
- smc.sourcesContent = aSourceMap._generateSourcesContent(smc._sources.toArray(),
4432
- smc.sourceRoot);
4433
- smc.file = aSourceMap._file;
4434
- smc._sourceMapURL = aSourceMapURL;
4435
- smc._absoluteSources = smc._sources.toArray().map(function (s) {
4436
- return util$1.computeSourceURL(smc.sourceRoot, s, aSourceMapURL);
4437
- });
4438
-
4439
- // Because we are modifying the entries (by converting string sources and
4440
- // names to indices into the sources and names ArraySets), we have to make
4441
- // a copy of the entry or else bad things happen. Shared mutable state
4442
- // strikes again! See github issue #191.
4443
-
4444
- var generatedMappings = aSourceMap._mappings.toArray().slice();
4445
- var destGeneratedMappings = smc.__generatedMappings = [];
4446
- var destOriginalMappings = smc.__originalMappings = [];
4447
-
4448
- for (var i = 0, length = generatedMappings.length; i < length; i++) {
4449
- var srcMapping = generatedMappings[i];
4450
- var destMapping = new Mapping;
4451
- destMapping.generatedLine = srcMapping.generatedLine;
4452
- destMapping.generatedColumn = srcMapping.generatedColumn;
4453
-
4454
- if (srcMapping.source) {
4455
- destMapping.source = sources.indexOf(srcMapping.source);
4456
- destMapping.originalLine = srcMapping.originalLine;
4457
- destMapping.originalColumn = srcMapping.originalColumn;
4458
-
4459
- if (srcMapping.name) {
4460
- destMapping.name = names.indexOf(srcMapping.name);
4461
- }
4462
-
4463
- destOriginalMappings.push(destMapping);
4464
- }
4465
-
4466
- destGeneratedMappings.push(destMapping);
4467
- }
4468
-
4469
- quickSort(smc.__originalMappings, util$1.compareByOriginalPositions);
4470
-
4471
- return smc;
4472
- };
4473
-
4474
- /**
4475
- * The version of the source mapping spec that we are consuming.
4476
- */
4477
- BasicSourceMapConsumer.prototype._version = 3;
4478
-
4479
- /**
4480
- * The list of original sources.
4481
- */
4482
- Object.defineProperty(BasicSourceMapConsumer.prototype, 'sources', {
4483
- get: function () {
4484
- return this._absoluteSources.slice();
4485
- }
4486
- });
4487
-
4488
- /**
4489
- * Provide the JIT with a nice shape / hidden class.
4490
- */
4491
- function Mapping() {
4492
- this.generatedLine = 0;
4493
- this.generatedColumn = 0;
4494
- this.source = null;
4495
- this.originalLine = null;
4496
- this.originalColumn = null;
4497
- this.name = null;
4498
- }
4499
-
4500
- /**
4501
- * Parse the mappings in a string in to a data structure which we can easily
4502
- * query (the ordered arrays in the `this.__generatedMappings` and
4503
- * `this.__originalMappings` properties).
4504
- */
4505
-
4506
- const compareGenerated = util$1.compareByGeneratedPositionsDeflatedNoLine;
4507
- function sortGenerated(array, start) {
4508
- let l = array.length;
4509
- let n = array.length - start;
4510
- if (n <= 1) {
4511
- return;
4512
- } else if (n == 2) {
4513
- let a = array[start];
4514
- let b = array[start + 1];
4515
- if (compareGenerated(a, b) > 0) {
4516
- array[start] = b;
4517
- array[start + 1] = a;
4518
- }
4519
- } else if (n < 20) {
4520
- for (let i = start; i < l; i++) {
4521
- for (let j = i; j > start; j--) {
4522
- let a = array[j - 1];
4523
- let b = array[j];
4524
- if (compareGenerated(a, b) <= 0) {
4525
- break;
4526
- }
4527
- array[j - 1] = b;
4528
- array[j] = a;
4529
- }
4530
- }
4531
- } else {
4532
- quickSort(array, compareGenerated, start);
4533
- }
4534
- }
4535
- BasicSourceMapConsumer.prototype._parseMappings =
4536
- function SourceMapConsumer_parseMappings(aStr, aSourceRoot) {
4537
- var generatedLine = 1;
4538
- var previousGeneratedColumn = 0;
4539
- var previousOriginalLine = 0;
4540
- var previousOriginalColumn = 0;
4541
- var previousSource = 0;
4542
- var previousName = 0;
4543
- var length = aStr.length;
4544
- var index = 0;
4545
- var temp = {};
4546
- var originalMappings = [];
4547
- var generatedMappings = [];
4548
- var mapping, segment, end, value;
4549
-
4550
- let subarrayStart = 0;
4551
- while (index < length) {
4552
- if (aStr.charAt(index) === ';') {
4553
- generatedLine++;
4554
- index++;
4555
- previousGeneratedColumn = 0;
4556
-
4557
- sortGenerated(generatedMappings, subarrayStart);
4558
- subarrayStart = generatedMappings.length;
4559
- }
4560
- else if (aStr.charAt(index) === ',') {
4561
- index++;
4562
- }
4563
- else {
4564
- mapping = new Mapping();
4565
- mapping.generatedLine = generatedLine;
4566
-
4567
- for (end = index; end < length; end++) {
4568
- if (this._charIsMappingSeparator(aStr, end)) {
4569
- break;
4570
- }
4571
- }
4572
- aStr.slice(index, end);
4573
-
4574
- segment = [];
4575
- while (index < end) {
4576
- base64VLQ.decode(aStr, index, temp);
4577
- value = temp.value;
4578
- index = temp.rest;
4579
- segment.push(value);
4580
- }
4581
-
4582
- if (segment.length === 2) {
4583
- throw new Error('Found a source, but no line and column');
4584
- }
4585
-
4586
- if (segment.length === 3) {
4587
- throw new Error('Found a source and line, but no column');
4588
- }
4589
-
4590
- // Generated column.
4591
- mapping.generatedColumn = previousGeneratedColumn + segment[0];
4592
- previousGeneratedColumn = mapping.generatedColumn;
4593
-
4594
- if (segment.length > 1) {
4595
- // Original source.
4596
- mapping.source = previousSource + segment[1];
4597
- previousSource += segment[1];
4598
-
4599
- // Original line.
4600
- mapping.originalLine = previousOriginalLine + segment[2];
4601
- previousOriginalLine = mapping.originalLine;
4602
- // Lines are stored 0-based
4603
- mapping.originalLine += 1;
4604
-
4605
- // Original column.
4606
- mapping.originalColumn = previousOriginalColumn + segment[3];
4607
- previousOriginalColumn = mapping.originalColumn;
4608
-
4609
- if (segment.length > 4) {
4610
- // Original name.
4611
- mapping.name = previousName + segment[4];
4612
- previousName += segment[4];
4613
- }
4614
- }
4615
-
4616
- generatedMappings.push(mapping);
4617
- if (typeof mapping.originalLine === 'number') {
4618
- let currentSource = mapping.source;
4619
- while (originalMappings.length <= currentSource) {
4620
- originalMappings.push(null);
4621
- }
4622
- if (originalMappings[currentSource] === null) {
4623
- originalMappings[currentSource] = [];
4624
- }
4625
- originalMappings[currentSource].push(mapping);
4626
- }
4627
- }
4628
- }
4629
-
4630
- sortGenerated(generatedMappings, subarrayStart);
4631
- this.__generatedMappings = generatedMappings;
4632
-
4633
- for (var i = 0; i < originalMappings.length; i++) {
4634
- if (originalMappings[i] != null) {
4635
- quickSort(originalMappings[i], util$1.compareByOriginalPositionsNoSource);
4636
- }
4637
- }
4638
- this.__originalMappings = [].concat(...originalMappings);
4639
- };
4640
-
4641
- /**
4642
- * Find the mapping that best matches the hypothetical "needle" mapping that
4643
- * we are searching for in the given "haystack" of mappings.
4644
- */
4645
- BasicSourceMapConsumer.prototype._findMapping =
4646
- function SourceMapConsumer_findMapping(aNeedle, aMappings, aLineName,
4647
- aColumnName, aComparator, aBias) {
4648
- // To return the position we are searching for, we must first find the
4649
- // mapping for the given position and then return the opposite position it
4650
- // points to. Because the mappings are sorted, we can use binary search to
4651
- // find the best mapping.
4652
-
4653
- if (aNeedle[aLineName] <= 0) {
4654
- throw new TypeError('Line must be greater than or equal to 1, got '
4655
- + aNeedle[aLineName]);
4656
- }
4657
- if (aNeedle[aColumnName] < 0) {
4658
- throw new TypeError('Column must be greater than or equal to 0, got '
4659
- + aNeedle[aColumnName]);
4660
- }
4661
-
4662
- return binarySearch.search(aNeedle, aMappings, aComparator, aBias);
4663
- };
4664
-
4665
- /**
4666
- * Compute the last column for each generated mapping. The last column is
4667
- * inclusive.
4668
- */
4669
- BasicSourceMapConsumer.prototype.computeColumnSpans =
4670
- function SourceMapConsumer_computeColumnSpans() {
4671
- for (var index = 0; index < this._generatedMappings.length; ++index) {
4672
- var mapping = this._generatedMappings[index];
4673
-
4674
- // Mappings do not contain a field for the last generated columnt. We
4675
- // can come up with an optimistic estimate, however, by assuming that
4676
- // mappings are contiguous (i.e. given two consecutive mappings, the
4677
- // first mapping ends where the second one starts).
4678
- if (index + 1 < this._generatedMappings.length) {
4679
- var nextMapping = this._generatedMappings[index + 1];
4680
-
4681
- if (mapping.generatedLine === nextMapping.generatedLine) {
4682
- mapping.lastGeneratedColumn = nextMapping.generatedColumn - 1;
4683
- continue;
4684
- }
4685
- }
4686
-
4687
- // The last mapping for each line spans the entire line.
4688
- mapping.lastGeneratedColumn = Infinity;
4689
- }
4690
- };
4691
-
4692
- /**
4693
- * Returns the original source, line, and column information for the generated
4694
- * source's line and column positions provided. The only argument is an object
4695
- * with the following properties:
4696
- *
4697
- * - line: The line number in the generated source. The line number
4698
- * is 1-based.
4699
- * - column: The column number in the generated source. The column
4700
- * number is 0-based.
4701
- * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
4702
- * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
4703
- * closest element that is smaller than or greater than the one we are
4704
- * searching for, respectively, if the exact element cannot be found.
4705
- * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
4706
- *
4707
- * and an object is returned with the following properties:
4708
- *
4709
- * - source: The original source file, or null.
4710
- * - line: The line number in the original source, or null. The
4711
- * line number is 1-based.
4712
- * - column: The column number in the original source, or null. The
4713
- * column number is 0-based.
4714
- * - name: The original identifier, or null.
4715
- */
4716
- BasicSourceMapConsumer.prototype.originalPositionFor =
4717
- function SourceMapConsumer_originalPositionFor(aArgs) {
4718
- var needle = {
4719
- generatedLine: util$1.getArg(aArgs, 'line'),
4720
- generatedColumn: util$1.getArg(aArgs, 'column')
4721
- };
4722
-
4723
- var index = this._findMapping(
4724
- needle,
4725
- this._generatedMappings,
4726
- "generatedLine",
4727
- "generatedColumn",
4728
- util$1.compareByGeneratedPositionsDeflated,
4729
- util$1.getArg(aArgs, 'bias', SourceMapConsumer$1.GREATEST_LOWER_BOUND)
4730
- );
4731
-
4732
- if (index >= 0) {
4733
- var mapping = this._generatedMappings[index];
4734
-
4735
- if (mapping.generatedLine === needle.generatedLine) {
4736
- var source = util$1.getArg(mapping, 'source', null);
4737
- if (source !== null) {
4738
- source = this._sources.at(source);
4739
- source = util$1.computeSourceURL(this.sourceRoot, source, this._sourceMapURL);
4740
- }
4741
- var name = util$1.getArg(mapping, 'name', null);
4742
- if (name !== null) {
4743
- name = this._names.at(name);
4744
- }
4745
- return {
4746
- source: source,
4747
- line: util$1.getArg(mapping, 'originalLine', null),
4748
- column: util$1.getArg(mapping, 'originalColumn', null),
4749
- name: name
4750
- };
4751
- }
4752
- }
4753
-
4754
- return {
4755
- source: null,
4756
- line: null,
4757
- column: null,
4758
- name: null
4759
- };
4760
- };
4761
-
4762
- /**
4763
- * Return true if we have the source content for every source in the source
4764
- * map, false otherwise.
4765
- */
4766
- BasicSourceMapConsumer.prototype.hasContentsOfAllSources =
4767
- function BasicSourceMapConsumer_hasContentsOfAllSources() {
4768
- if (!this.sourcesContent) {
4769
- return false;
4770
- }
4771
- return this.sourcesContent.length >= this._sources.size() &&
4772
- !this.sourcesContent.some(function (sc) { return sc == null; });
4773
- };
4774
-
4775
- /**
4776
- * Returns the original source content. The only argument is the url of the
4777
- * original source file. Returns null if no original source content is
4778
- * available.
4779
- */
4780
- BasicSourceMapConsumer.prototype.sourceContentFor =
4781
- function SourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
4782
- if (!this.sourcesContent) {
4783
- return null;
4784
- }
4785
-
4786
- var index = this._findSourceIndex(aSource);
4787
- if (index >= 0) {
4788
- return this.sourcesContent[index];
4789
- }
4790
-
4791
- var relativeSource = aSource;
4792
- if (this.sourceRoot != null) {
4793
- relativeSource = util$1.relative(this.sourceRoot, relativeSource);
4794
- }
4795
-
4796
- var url;
4797
- if (this.sourceRoot != null
4798
- && (url = util$1.urlParse(this.sourceRoot))) {
4799
- // XXX: file:// URIs and absolute paths lead to unexpected behavior for
4800
- // many users. We can help them out when they expect file:// URIs to
4801
- // behave like it would if they were running a local HTTP server. See
4802
- // https://bugzilla.mozilla.org/show_bug.cgi?id=885597.
4803
- var fileUriAbsPath = relativeSource.replace(/^file:\/\//, "");
4804
- if (url.scheme == "file"
4805
- && this._sources.has(fileUriAbsPath)) {
4806
- return this.sourcesContent[this._sources.indexOf(fileUriAbsPath)]
4807
- }
4808
-
4809
- if ((!url.path || url.path == "/")
4810
- && this._sources.has("/" + relativeSource)) {
4811
- return this.sourcesContent[this._sources.indexOf("/" + relativeSource)];
4812
- }
4813
- }
4814
-
4815
- // This function is used recursively from
4816
- // IndexedSourceMapConsumer.prototype.sourceContentFor. In that case, we
4817
- // don't want to throw if we can't find the source - we just want to
4818
- // return null, so we provide a flag to exit gracefully.
4819
- if (nullOnMissing) {
4820
- return null;
4821
- }
4822
- else {
4823
- throw new Error('"' + relativeSource + '" is not in the SourceMap.');
4824
- }
4825
- };
4826
-
4827
- /**
4828
- * Returns the generated line and column information for the original source,
4829
- * line, and column positions provided. The only argument is an object with
4830
- * the following properties:
4831
- *
4832
- * - source: The filename of the original source.
4833
- * - line: The line number in the original source. The line number
4834
- * is 1-based.
4835
- * - column: The column number in the original source. The column
4836
- * number is 0-based.
4837
- * - bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or
4838
- * 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the
4839
- * closest element that is smaller than or greater than the one we are
4840
- * searching for, respectively, if the exact element cannot be found.
4841
- * Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.
4842
- *
4843
- * and an object is returned with the following properties:
4844
- *
4845
- * - line: The line number in the generated source, or null. The
4846
- * line number is 1-based.
4847
- * - column: The column number in the generated source, or null.
4848
- * The column number is 0-based.
4849
- */
4850
- BasicSourceMapConsumer.prototype.generatedPositionFor =
4851
- function SourceMapConsumer_generatedPositionFor(aArgs) {
4852
- var source = util$1.getArg(aArgs, 'source');
4853
- source = this._findSourceIndex(source);
4854
- if (source < 0) {
4855
- return {
4856
- line: null,
4857
- column: null,
4858
- lastColumn: null
4859
- };
4860
- }
4861
-
4862
- var needle = {
4863
- source: source,
4864
- originalLine: util$1.getArg(aArgs, 'line'),
4865
- originalColumn: util$1.getArg(aArgs, 'column')
4866
- };
4867
-
4868
- var index = this._findMapping(
4869
- needle,
4870
- this._originalMappings,
4871
- "originalLine",
4872
- "originalColumn",
4873
- util$1.compareByOriginalPositions,
4874
- util$1.getArg(aArgs, 'bias', SourceMapConsumer$1.GREATEST_LOWER_BOUND)
4875
- );
4876
-
4877
- if (index >= 0) {
4878
- var mapping = this._originalMappings[index];
4879
-
4880
- if (mapping.source === needle.source) {
4881
- return {
4882
- line: util$1.getArg(mapping, 'generatedLine', null),
4883
- column: util$1.getArg(mapping, 'generatedColumn', null),
4884
- lastColumn: util$1.getArg(mapping, 'lastGeneratedColumn', null)
4885
- };
4886
- }
4887
- }
4888
-
4889
- return {
4890
- line: null,
4891
- column: null,
4892
- lastColumn: null
4893
- };
4894
- };
4895
-
4896
- sourceMapConsumer.BasicSourceMapConsumer = BasicSourceMapConsumer;
4897
-
4898
- /**
4899
- * An IndexedSourceMapConsumer instance represents a parsed source map which
4900
- * we can query for information. It differs from BasicSourceMapConsumer in
4901
- * that it takes "indexed" source maps (i.e. ones with a "sections" field) as
4902
- * input.
4903
- *
4904
- * The first parameter is a raw source map (either as a JSON string, or already
4905
- * parsed to an object). According to the spec for indexed source maps, they
4906
- * have the following attributes:
4907
- *
4908
- * - version: Which version of the source map spec this map is following.
4909
- * - file: Optional. The generated file this source map is associated with.
4910
- * - sections: A list of section definitions.
4911
- *
4912
- * Each value under the "sections" field has two fields:
4913
- * - offset: The offset into the original specified at which this section
4914
- * begins to apply, defined as an object with a "line" and "column"
4915
- * field.
4916
- * - map: A source map definition. This source map could also be indexed,
4917
- * but doesn't have to be.
4918
- *
4919
- * Instead of the "map" field, it's also possible to have a "url" field
4920
- * specifying a URL to retrieve a source map from, but that's currently
4921
- * unsupported.
4922
- *
4923
- * Here's an example source map, taken from the source map spec[0], but
4924
- * modified to omit a section which uses the "url" field.
4925
- *
4926
- * {
4927
- * version : 3,
4928
- * file: "app.js",
4929
- * sections: [{
4930
- * offset: {line:100, column:10},
4931
- * map: {
4932
- * version : 3,
4933
- * file: "section.js",
4934
- * sources: ["foo.js", "bar.js"],
4935
- * names: ["src", "maps", "are", "fun"],
4936
- * mappings: "AAAA,E;;ABCDE;"
4937
- * }
4938
- * }],
4939
- * }
4940
- *
4941
- * The second parameter, if given, is a string whose value is the URL
4942
- * at which the source map was found. This URL is used to compute the
4943
- * sources array.
4944
- *
4945
- * [0]: https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit#heading=h.535es3xeprgt
4946
- */
4947
- function IndexedSourceMapConsumer(aSourceMap, aSourceMapURL) {
4948
- var sourceMap = aSourceMap;
4949
- if (typeof aSourceMap === 'string') {
4950
- sourceMap = util$1.parseSourceMapInput(aSourceMap);
4951
- }
4952
-
4953
- var version = util$1.getArg(sourceMap, 'version');
4954
- var sections = util$1.getArg(sourceMap, 'sections');
4955
-
4956
- if (version != this._version) {
4957
- throw new Error('Unsupported version: ' + version);
4958
- }
4959
-
4960
- this._sources = new ArraySet();
4961
- this._names = new ArraySet();
4962
-
4963
- var lastOffset = {
4964
- line: -1,
4965
- column: 0
4966
- };
4967
- this._sections = sections.map(function (s) {
4968
- if (s.url) {
4969
- // The url field will require support for asynchronicity.
4970
- // See https://github.com/mozilla/source-map/issues/16
4971
- throw new Error('Support for url field in sections not implemented.');
4972
- }
4973
- var offset = util$1.getArg(s, 'offset');
4974
- var offsetLine = util$1.getArg(offset, 'line');
4975
- var offsetColumn = util$1.getArg(offset, 'column');
4976
-
4977
- if (offsetLine < lastOffset.line ||
4978
- (offsetLine === lastOffset.line && offsetColumn < lastOffset.column)) {
4979
- throw new Error('Section offsets must be ordered and non-overlapping.');
4980
- }
4981
- lastOffset = offset;
4982
-
4983
- return {
4984
- generatedOffset: {
4985
- // The offset fields are 0-based, but we use 1-based indices when
4986
- // encoding/decoding from VLQ.
4987
- generatedLine: offsetLine + 1,
4988
- generatedColumn: offsetColumn + 1
4989
- },
4990
- consumer: new SourceMapConsumer$1(util$1.getArg(s, 'map'), aSourceMapURL)
4991
- }
4992
- });
4993
- }
4994
-
4995
- IndexedSourceMapConsumer.prototype = Object.create(SourceMapConsumer$1.prototype);
4996
- IndexedSourceMapConsumer.prototype.constructor = SourceMapConsumer$1;
4997
-
4998
- /**
4999
- * The version of the source mapping spec that we are consuming.
5000
- */
5001
- IndexedSourceMapConsumer.prototype._version = 3;
5002
-
5003
- /**
5004
- * The list of original sources.
5005
- */
5006
- Object.defineProperty(IndexedSourceMapConsumer.prototype, 'sources', {
5007
- get: function () {
5008
- var sources = [];
5009
- for (var i = 0; i < this._sections.length; i++) {
5010
- for (var j = 0; j < this._sections[i].consumer.sources.length; j++) {
5011
- sources.push(this._sections[i].consumer.sources[j]);
5012
- }
5013
- }
5014
- return sources;
5015
- }
5016
- });
5017
-
5018
- /**
5019
- * Returns the original source, line, and column information for the generated
5020
- * source's line and column positions provided. The only argument is an object
5021
- * with the following properties:
5022
- *
5023
- * - line: The line number in the generated source. The line number
5024
- * is 1-based.
5025
- * - column: The column number in the generated source. The column
5026
- * number is 0-based.
5027
- *
5028
- * and an object is returned with the following properties:
5029
- *
5030
- * - source: The original source file, or null.
5031
- * - line: The line number in the original source, or null. The
5032
- * line number is 1-based.
5033
- * - column: The column number in the original source, or null. The
5034
- * column number is 0-based.
5035
- * - name: The original identifier, or null.
5036
- */
5037
- IndexedSourceMapConsumer.prototype.originalPositionFor =
5038
- function IndexedSourceMapConsumer_originalPositionFor(aArgs) {
5039
- var needle = {
5040
- generatedLine: util$1.getArg(aArgs, 'line'),
5041
- generatedColumn: util$1.getArg(aArgs, 'column')
5042
- };
5043
-
5044
- // Find the section containing the generated position we're trying to map
5045
- // to an original position.
5046
- var sectionIndex = binarySearch.search(needle, this._sections,
5047
- function(needle, section) {
5048
- var cmp = needle.generatedLine - section.generatedOffset.generatedLine;
5049
- if (cmp) {
5050
- return cmp;
5051
- }
5052
-
5053
- return (needle.generatedColumn -
5054
- section.generatedOffset.generatedColumn);
5055
- });
5056
- var section = this._sections[sectionIndex];
5057
-
5058
- if (!section) {
5059
- return {
5060
- source: null,
5061
- line: null,
5062
- column: null,
5063
- name: null
5064
- };
5065
- }
5066
-
5067
- return section.consumer.originalPositionFor({
5068
- line: needle.generatedLine -
5069
- (section.generatedOffset.generatedLine - 1),
5070
- column: needle.generatedColumn -
5071
- (section.generatedOffset.generatedLine === needle.generatedLine
5072
- ? section.generatedOffset.generatedColumn - 1
5073
- : 0),
5074
- bias: aArgs.bias
5075
- });
5076
- };
5077
-
5078
- /**
5079
- * Return true if we have the source content for every source in the source
5080
- * map, false otherwise.
5081
- */
5082
- IndexedSourceMapConsumer.prototype.hasContentsOfAllSources =
5083
- function IndexedSourceMapConsumer_hasContentsOfAllSources() {
5084
- return this._sections.every(function (s) {
5085
- return s.consumer.hasContentsOfAllSources();
5086
- });
5087
- };
5088
-
5089
- /**
5090
- * Returns the original source content. The only argument is the url of the
5091
- * original source file. Returns null if no original source content is
5092
- * available.
5093
- */
5094
- IndexedSourceMapConsumer.prototype.sourceContentFor =
5095
- function IndexedSourceMapConsumer_sourceContentFor(aSource, nullOnMissing) {
5096
- for (var i = 0; i < this._sections.length; i++) {
5097
- var section = this._sections[i];
5098
-
5099
- var content = section.consumer.sourceContentFor(aSource, true);
5100
- if (content) {
5101
- return content;
5102
- }
5103
- }
5104
- if (nullOnMissing) {
5105
- return null;
5106
- }
5107
- else {
5108
- throw new Error('"' + aSource + '" is not in the SourceMap.');
5109
- }
5110
- };
5111
-
5112
- /**
5113
- * Returns the generated line and column information for the original source,
5114
- * line, and column positions provided. The only argument is an object with
5115
- * the following properties:
5116
- *
5117
- * - source: The filename of the original source.
5118
- * - line: The line number in the original source. The line number
5119
- * is 1-based.
5120
- * - column: The column number in the original source. The column
5121
- * number is 0-based.
5122
- *
5123
- * and an object is returned with the following properties:
5124
- *
5125
- * - line: The line number in the generated source, or null. The
5126
- * line number is 1-based.
5127
- * - column: The column number in the generated source, or null.
5128
- * The column number is 0-based.
5129
- */
5130
- IndexedSourceMapConsumer.prototype.generatedPositionFor =
5131
- function IndexedSourceMapConsumer_generatedPositionFor(aArgs) {
5132
- for (var i = 0; i < this._sections.length; i++) {
5133
- var section = this._sections[i];
5134
-
5135
- // Only consider this section if the requested source is in the list of
5136
- // sources of the consumer.
5137
- if (section.consumer._findSourceIndex(util$1.getArg(aArgs, 'source')) === -1) {
5138
- continue;
5139
- }
5140
- var generatedPosition = section.consumer.generatedPositionFor(aArgs);
5141
- if (generatedPosition) {
5142
- var ret = {
5143
- line: generatedPosition.line +
5144
- (section.generatedOffset.generatedLine - 1),
5145
- column: generatedPosition.column +
5146
- (section.generatedOffset.generatedLine === generatedPosition.line
5147
- ? section.generatedOffset.generatedColumn - 1
5148
- : 0)
5149
- };
5150
- return ret;
5151
- }
5152
- }
5153
-
5154
- return {
5155
- line: null,
5156
- column: null
5157
- };
5158
- };
5159
-
5160
- /**
5161
- * Parse the mappings in a string in to a data structure which we can easily
5162
- * query (the ordered arrays in the `this.__generatedMappings` and
5163
- * `this.__originalMappings` properties).
5164
- */
5165
- IndexedSourceMapConsumer.prototype._parseMappings =
5166
- function IndexedSourceMapConsumer_parseMappings(aStr, aSourceRoot) {
5167
- this.__generatedMappings = [];
5168
- this.__originalMappings = [];
5169
- for (var i = 0; i < this._sections.length; i++) {
5170
- var section = this._sections[i];
5171
- var sectionMappings = section.consumer._generatedMappings;
5172
- for (var j = 0; j < sectionMappings.length; j++) {
5173
- var mapping = sectionMappings[j];
5174
-
5175
- var source = section.consumer._sources.at(mapping.source);
5176
- source = util$1.computeSourceURL(section.consumer.sourceRoot, source, this._sourceMapURL);
5177
- this._sources.add(source);
5178
- source = this._sources.indexOf(source);
5179
-
5180
- var name = null;
5181
- if (mapping.name) {
5182
- name = section.consumer._names.at(mapping.name);
5183
- this._names.add(name);
5184
- name = this._names.indexOf(name);
5185
- }
5186
-
5187
- // The mappings coming from the consumer for the section have
5188
- // generated positions relative to the start of the section, so we
5189
- // need to offset them to be relative to the start of the concatenated
5190
- // generated file.
5191
- var adjustedMapping = {
5192
- source: source,
5193
- generatedLine: mapping.generatedLine +
5194
- (section.generatedOffset.generatedLine - 1),
5195
- generatedColumn: mapping.generatedColumn +
5196
- (section.generatedOffset.generatedLine === mapping.generatedLine
5197
- ? section.generatedOffset.generatedColumn - 1
5198
- : 0),
5199
- originalLine: mapping.originalLine,
5200
- originalColumn: mapping.originalColumn,
5201
- name: name
5202
- };
5203
-
5204
- this.__generatedMappings.push(adjustedMapping);
5205
- if (typeof adjustedMapping.originalLine === 'number') {
5206
- this.__originalMappings.push(adjustedMapping);
5207
- }
5208
- }
5209
- }
5210
-
5211
- quickSort(this.__generatedMappings, util$1.compareByGeneratedPositionsDeflated);
5212
- quickSort(this.__originalMappings, util$1.compareByOriginalPositions);
5213
- };
5214
-
5215
- sourceMapConsumer.IndexedSourceMapConsumer = IndexedSourceMapConsumer;
5216
-
5217
- /* -*- Mode: js; js-indent-level: 2; -*- */
5218
-
5219
- /*
5220
- * Copyright 2011 Mozilla Foundation and contributors
5221
- * Licensed under the New BSD license. See LICENSE or:
5222
- * http://opensource.org/licenses/BSD-3-Clause
5223
- */
5224
-
5225
- var SourceMapGenerator = sourceMapGenerator.SourceMapGenerator;
5226
- var util = util$5;
5227
-
5228
- // Matches a Windows-style `\r\n` newline or a `\n` newline used by all other
5229
- // operating systems these days (capturing the result).
5230
- var REGEX_NEWLINE = /(\r?\n)/;
5231
-
5232
- // Newline character code for charCodeAt() comparisons
5233
- var NEWLINE_CODE = 10;
5234
-
5235
- // Private symbol for identifying `SourceNode`s when multiple versions of
5236
- // the source-map library are loaded. This MUST NOT CHANGE across
5237
- // versions!
5238
- var isSourceNode = "$$$isSourceNode$$$";
5239
-
5240
- /**
5241
- * SourceNodes provide a way to abstract over interpolating/concatenating
5242
- * snippets of generated JavaScript source code while maintaining the line and
5243
- * column information associated with the original source code.
5244
- *
5245
- * @param aLine The original line number.
5246
- * @param aColumn The original column number.
5247
- * @param aSource The original source's filename.
5248
- * @param aChunks Optional. An array of strings which are snippets of
5249
- * generated JS, or other SourceNodes.
5250
- * @param aName The original identifier.
5251
- */
5252
- function SourceNode(aLine, aColumn, aSource, aChunks, aName) {
5253
- this.children = [];
5254
- this.sourceContents = {};
5255
- this.line = aLine == null ? null : aLine;
5256
- this.column = aColumn == null ? null : aColumn;
5257
- this.source = aSource == null ? null : aSource;
5258
- this.name = aName == null ? null : aName;
5259
- this[isSourceNode] = true;
5260
- if (aChunks != null) this.add(aChunks);
5261
- }
5262
-
5263
- /**
5264
- * Creates a SourceNode from generated code and a SourceMapConsumer.
5265
- *
5266
- * @param aGeneratedCode The generated code
5267
- * @param aSourceMapConsumer The SourceMap for the generated code
5268
- * @param aRelativePath Optional. The path that relative sources in the
5269
- * SourceMapConsumer should be relative to.
5270
- */
5271
- SourceNode.fromStringWithSourceMap =
5272
- function SourceNode_fromStringWithSourceMap(aGeneratedCode, aSourceMapConsumer, aRelativePath) {
5273
- // The SourceNode we want to fill with the generated code
5274
- // and the SourceMap
5275
- var node = new SourceNode();
5276
-
5277
- // All even indices of this array are one line of the generated code,
5278
- // while all odd indices are the newlines between two adjacent lines
5279
- // (since `REGEX_NEWLINE` captures its match).
5280
- // Processed fragments are accessed by calling `shiftNextLine`.
5281
- var remainingLines = aGeneratedCode.split(REGEX_NEWLINE);
5282
- var remainingLinesIndex = 0;
5283
- var shiftNextLine = function() {
5284
- var lineContents = getNextLine();
5285
- // The last line of a file might not have a newline.
5286
- var newLine = getNextLine() || "";
5287
- return lineContents + newLine;
5288
-
5289
- function getNextLine() {
5290
- return remainingLinesIndex < remainingLines.length ?
5291
- remainingLines[remainingLinesIndex++] : undefined;
5292
- }
5293
- };
5294
-
5295
- // We need to remember the position of "remainingLines"
5296
- var lastGeneratedLine = 1, lastGeneratedColumn = 0;
5297
-
5298
- // The generate SourceNodes we need a code range.
5299
- // To extract it current and last mapping is used.
5300
- // Here we store the last mapping.
5301
- var lastMapping = null;
5302
-
5303
- aSourceMapConsumer.eachMapping(function (mapping) {
5304
- if (lastMapping !== null) {
5305
- // We add the code from "lastMapping" to "mapping":
5306
- // First check if there is a new line in between.
5307
- if (lastGeneratedLine < mapping.generatedLine) {
5308
- // Associate first line with "lastMapping"
5309
- addMappingWithCode(lastMapping, shiftNextLine());
5310
- lastGeneratedLine++;
5311
- lastGeneratedColumn = 0;
5312
- // The remaining code is added without mapping
5313
- } else {
5314
- // There is no new line in between.
5315
- // Associate the code between "lastGeneratedColumn" and
5316
- // "mapping.generatedColumn" with "lastMapping"
5317
- var nextLine = remainingLines[remainingLinesIndex] || '';
5318
- var code = nextLine.substr(0, mapping.generatedColumn -
5319
- lastGeneratedColumn);
5320
- remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn -
5321
- lastGeneratedColumn);
5322
- lastGeneratedColumn = mapping.generatedColumn;
5323
- addMappingWithCode(lastMapping, code);
5324
- // No more remaining code, continue
5325
- lastMapping = mapping;
5326
- return;
5327
- }
5328
- }
5329
- // We add the generated code until the first mapping
5330
- // to the SourceNode without any mapping.
5331
- // Each line is added as separate string.
5332
- while (lastGeneratedLine < mapping.generatedLine) {
5333
- node.add(shiftNextLine());
5334
- lastGeneratedLine++;
5335
- }
5336
- if (lastGeneratedColumn < mapping.generatedColumn) {
5337
- var nextLine = remainingLines[remainingLinesIndex] || '';
5338
- node.add(nextLine.substr(0, mapping.generatedColumn));
5339
- remainingLines[remainingLinesIndex] = nextLine.substr(mapping.generatedColumn);
5340
- lastGeneratedColumn = mapping.generatedColumn;
5341
- }
5342
- lastMapping = mapping;
5343
- }, this);
5344
- // We have processed all mappings.
5345
- if (remainingLinesIndex < remainingLines.length) {
5346
- if (lastMapping) {
5347
- // Associate the remaining code in the current line with "lastMapping"
5348
- addMappingWithCode(lastMapping, shiftNextLine());
5349
- }
5350
- // and add the remaining lines without any mapping
5351
- node.add(remainingLines.splice(remainingLinesIndex).join(""));
5352
- }
5353
-
5354
- // Copy sourcesContent into SourceNode
5355
- aSourceMapConsumer.sources.forEach(function (sourceFile) {
5356
- var content = aSourceMapConsumer.sourceContentFor(sourceFile);
5357
- if (content != null) {
5358
- if (aRelativePath != null) {
5359
- sourceFile = util.join(aRelativePath, sourceFile);
5360
- }
5361
- node.setSourceContent(sourceFile, content);
5362
- }
5363
- });
5364
-
5365
- return node;
5366
-
5367
- function addMappingWithCode(mapping, code) {
5368
- if (mapping === null || mapping.source === undefined) {
5369
- node.add(code);
5370
- } else {
5371
- var source = aRelativePath
5372
- ? util.join(aRelativePath, mapping.source)
5373
- : mapping.source;
5374
- node.add(new SourceNode(mapping.originalLine,
5375
- mapping.originalColumn,
5376
- source,
5377
- code,
5378
- mapping.name));
5379
- }
5380
- }
5381
- };
5382
-
5383
- /**
5384
- * Add a chunk of generated JS to this source node.
5385
- *
5386
- * @param aChunk A string snippet of generated JS code, another instance of
5387
- * SourceNode, or an array where each member is one of those things.
5388
- */
5389
- SourceNode.prototype.add = function SourceNode_add(aChunk) {
5390
- if (Array.isArray(aChunk)) {
5391
- aChunk.forEach(function (chunk) {
5392
- this.add(chunk);
5393
- }, this);
5394
- }
5395
- else if (aChunk[isSourceNode] || typeof aChunk === "string") {
5396
- if (aChunk) {
5397
- this.children.push(aChunk);
5398
- }
5399
- }
5400
- else {
5401
- throw new TypeError(
5402
- "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
5403
- );
5404
- }
5405
- return this;
5406
- };
5407
-
5408
- /**
5409
- * Add a chunk of generated JS to the beginning of this source node.
5410
- *
5411
- * @param aChunk A string snippet of generated JS code, another instance of
5412
- * SourceNode, or an array where each member is one of those things.
5413
- */
5414
- SourceNode.prototype.prepend = function SourceNode_prepend(aChunk) {
5415
- if (Array.isArray(aChunk)) {
5416
- for (var i = aChunk.length-1; i >= 0; i--) {
5417
- this.prepend(aChunk[i]);
5418
- }
5419
- }
5420
- else if (aChunk[isSourceNode] || typeof aChunk === "string") {
5421
- this.children.unshift(aChunk);
5422
- }
5423
- else {
5424
- throw new TypeError(
5425
- "Expected a SourceNode, string, or an array of SourceNodes and strings. Got " + aChunk
5426
- );
5427
- }
5428
- return this;
5429
- };
5430
-
5431
- /**
5432
- * Walk over the tree of JS snippets in this node and its children. The
5433
- * walking function is called once for each snippet of JS and is passed that
5434
- * snippet and the its original associated source's line/column location.
5435
- *
5436
- * @param aFn The traversal function.
5437
- */
5438
- SourceNode.prototype.walk = function SourceNode_walk(aFn) {
5439
- var chunk;
5440
- for (var i = 0, len = this.children.length; i < len; i++) {
5441
- chunk = this.children[i];
5442
- if (chunk[isSourceNode]) {
5443
- chunk.walk(aFn);
5444
- }
5445
- else {
5446
- if (chunk !== '') {
5447
- aFn(chunk, { source: this.source,
5448
- line: this.line,
5449
- column: this.column,
5450
- name: this.name });
5451
- }
5452
- }
5453
- }
5454
- };
5455
-
5456
- /**
5457
- * Like `String.prototype.join` except for SourceNodes. Inserts `aStr` between
5458
- * each of `this.children`.
5459
- *
5460
- * @param aSep The separator.
5461
- */
5462
- SourceNode.prototype.join = function SourceNode_join(aSep) {
5463
- var newChildren;
5464
- var i;
5465
- var len = this.children.length;
5466
- if (len > 0) {
5467
- newChildren = [];
5468
- for (i = 0; i < len-1; i++) {
5469
- newChildren.push(this.children[i]);
5470
- newChildren.push(aSep);
5471
- }
5472
- newChildren.push(this.children[i]);
5473
- this.children = newChildren;
5474
- }
5475
- return this;
5476
- };
5477
-
5478
- /**
5479
- * Call String.prototype.replace on the very right-most source snippet. Useful
5480
- * for trimming whitespace from the end of a source node, etc.
5481
- *
5482
- * @param aPattern The pattern to replace.
5483
- * @param aReplacement The thing to replace the pattern with.
5484
- */
5485
- SourceNode.prototype.replaceRight = function SourceNode_replaceRight(aPattern, aReplacement) {
5486
- var lastChild = this.children[this.children.length - 1];
5487
- if (lastChild[isSourceNode]) {
5488
- lastChild.replaceRight(aPattern, aReplacement);
5489
- }
5490
- else if (typeof lastChild === 'string') {
5491
- this.children[this.children.length - 1] = lastChild.replace(aPattern, aReplacement);
5492
- }
5493
- else {
5494
- this.children.push(''.replace(aPattern, aReplacement));
5495
- }
5496
- return this;
5497
- };
5498
-
5499
- /**
5500
- * Set the source content for a source file. This will be added to the SourceMapGenerator
5501
- * in the sourcesContent field.
5502
- *
5503
- * @param aSourceFile The filename of the source file
5504
- * @param aSourceContent The content of the source file
5505
- */
5506
- SourceNode.prototype.setSourceContent =
5507
- function SourceNode_setSourceContent(aSourceFile, aSourceContent) {
5508
- this.sourceContents[util.toSetString(aSourceFile)] = aSourceContent;
5509
- };
5510
-
5511
- /**
5512
- * Walk over the tree of SourceNodes. The walking function is called for each
5513
- * source file content and is passed the filename and source content.
5514
- *
5515
- * @param aFn The traversal function.
5516
- */
5517
- SourceNode.prototype.walkSourceContents =
5518
- function SourceNode_walkSourceContents(aFn) {
5519
- for (var i = 0, len = this.children.length; i < len; i++) {
5520
- if (this.children[i][isSourceNode]) {
5521
- this.children[i].walkSourceContents(aFn);
5522
- }
5523
- }
5524
-
5525
- var sources = Object.keys(this.sourceContents);
5526
- for (var i = 0, len = sources.length; i < len; i++) {
5527
- aFn(util.fromSetString(sources[i]), this.sourceContents[sources[i]]);
5528
- }
5529
- };
5530
-
5531
- /**
5532
- * Return the string representation of this source node. Walks over the tree
5533
- * and concatenates all the various snippets together to one string.
5534
- */
5535
- SourceNode.prototype.toString = function SourceNode_toString() {
5536
- var str = "";
5537
- this.walk(function (chunk) {
5538
- str += chunk;
5539
- });
5540
- return str;
5541
- };
5542
-
5543
- /**
5544
- * Returns the string representation of this source node along with a source
5545
- * map.
5546
- */
5547
- SourceNode.prototype.toStringWithSourceMap = function SourceNode_toStringWithSourceMap(aArgs) {
5548
- var generated = {
5549
- code: "",
5550
- line: 1,
5551
- column: 0
5552
- };
5553
- var map = new SourceMapGenerator(aArgs);
5554
- var sourceMappingActive = false;
5555
- var lastOriginalSource = null;
5556
- var lastOriginalLine = null;
5557
- var lastOriginalColumn = null;
5558
- var lastOriginalName = null;
5559
- this.walk(function (chunk, original) {
5560
- generated.code += chunk;
5561
- if (original.source !== null
5562
- && original.line !== null
5563
- && original.column !== null) {
5564
- if(lastOriginalSource !== original.source
5565
- || lastOriginalLine !== original.line
5566
- || lastOriginalColumn !== original.column
5567
- || lastOriginalName !== original.name) {
5568
- map.addMapping({
5569
- source: original.source,
5570
- original: {
5571
- line: original.line,
5572
- column: original.column
5573
- },
5574
- generated: {
5575
- line: generated.line,
5576
- column: generated.column
5577
- },
5578
- name: original.name
5579
- });
5580
- }
5581
- lastOriginalSource = original.source;
5582
- lastOriginalLine = original.line;
5583
- lastOriginalColumn = original.column;
5584
- lastOriginalName = original.name;
5585
- sourceMappingActive = true;
5586
- } else if (sourceMappingActive) {
5587
- map.addMapping({
5588
- generated: {
5589
- line: generated.line,
5590
- column: generated.column
5591
- }
5592
- });
5593
- lastOriginalSource = null;
5594
- sourceMappingActive = false;
5595
- }
5596
- for (var idx = 0, length = chunk.length; idx < length; idx++) {
5597
- if (chunk.charCodeAt(idx) === NEWLINE_CODE) {
5598
- generated.line++;
5599
- generated.column = 0;
5600
- // Mappings end at eol
5601
- if (idx + 1 === length) {
5602
- lastOriginalSource = null;
5603
- sourceMappingActive = false;
5604
- } else if (sourceMappingActive) {
5605
- map.addMapping({
5606
- source: original.source,
5607
- original: {
5608
- line: original.line,
5609
- column: original.column
5610
- },
5611
- generated: {
5612
- line: generated.line,
5613
- column: generated.column
5614
- },
5615
- name: original.name
5616
- });
5617
- }
5618
- } else {
5619
- generated.column++;
5620
- }
5621
- }
5622
- });
5623
- this.walkSourceContents(function (sourceFile, sourceContent) {
5624
- map.setSourceContent(sourceFile, sourceContent);
5625
- });
5626
-
5627
- return { code: generated.code, map: map };
5628
- };
5629
-
5630
- /*
5631
- * Copyright 2009-2011 Mozilla Foundation and contributors
5632
- * Licensed under the New BSD license. See LICENSE.txt or:
5633
- * http://opensource.org/licenses/BSD-3-Clause
5634
- */
5635
- var SourceMapConsumer = sourceMapConsumer.SourceMapConsumer;
5636
-
5637
- const lineSplitRE = /\r?\n/;
5638
- function getOriginalPos(map, { line, column }) {
5639
- return new Promise((resolve) => {
5640
- if (!map)
5641
- return resolve(null);
5642
- const consumer = new SourceMapConsumer(map);
5643
- const pos = consumer.originalPositionFor({ line, column });
5644
- if (pos.line != null && pos.column != null)
5645
- resolve(pos);
5646
- else
5647
- resolve(null);
5648
- });
5649
- }
5650
- async function interpretSourcePos(stackFrames, ctx) {
5651
- var _a, _b, _c;
5652
- for (const frame of stackFrames) {
5653
- if ("sourcePos" in frame)
5654
- continue;
5655
- const ssrTransformResult = (_a = ctx.server.moduleGraph.getModuleById(frame.file)) == null ? void 0 : _a.ssrTransformResult;
5656
- const fetchResult = (_c = (_b = ctx.vitenode) == null ? void 0 : _b.fetchCache.get(frame.file)) == null ? void 0 : _c.result;
5657
- const map = (fetchResult == null ? void 0 : fetchResult.map) || (ssrTransformResult == null ? void 0 : ssrTransformResult.map);
5658
- if (!map)
5659
- continue;
5660
- const sourcePos = await getOriginalPos(map, frame);
5661
- if (sourcePos)
5662
- frame.sourcePos = sourcePos;
5663
- }
5664
- return stackFrames;
5665
- }
5666
- const stackIgnorePatterns = [
5667
- "node:internal",
5668
- "/vitest/dist/",
5669
- "/node_modules/chai/",
5670
- "/node_modules/tinypool/",
5671
- "/node_modules/tinyspy/"
5672
- ];
5673
- function extractLocation(urlLike) {
5674
- if (!urlLike.includes(":"))
5675
- return [urlLike];
5676
- const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
5677
- const parts = regExp.exec(urlLike.replace(/[()]/g, ""));
5678
- if (!parts)
5679
- return [urlLike];
5680
- return [parts[1], parts[2] || void 0, parts[3] || void 0];
5681
- }
5682
- function parseStacktrace(e, full = false) {
5683
- if (!e)
5684
- return [];
5685
- if (e.stacks)
5686
- return e.stacks;
5687
- const stackStr = e.stack || e.stackStr || "";
5688
- const stackFrames = stackStr.split("\n").map((raw) => {
5689
- let line = raw.trim();
5690
- if (line.includes("(eval "))
5691
- line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
5692
- let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
5693
- const location = sanitizedLine.match(/ (\(.+\)$)/);
5694
- sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
5695
- const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
5696
- let method = location && sanitizedLine || "";
5697
- let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
5698
- if (!file || !lineNumber || !columnNumber)
5699
- return null;
5700
- if (method.startsWith("async "))
5701
- method = method.slice(6);
5702
- if (file.startsWith("file://"))
5703
- file = file.slice(7);
5704
- if (!full && stackIgnorePatterns.some((p) => file && file.includes(p)))
5705
- return null;
5706
- return {
5707
- method,
5708
- file: slash(file),
5709
- line: parseInt(lineNumber),
5710
- column: parseInt(columnNumber)
5711
- };
5712
- }).filter(notNullish);
5713
- e.stacks = stackFrames;
5714
- return stackFrames;
5715
- }
5716
- function posToNumber(source, pos) {
5717
- if (typeof pos === "number")
5718
- return pos;
5719
- const lines = source.split(lineSplitRE);
5720
- const { line, column } = pos;
5721
- let start = 0;
5722
- if (line > lines.length)
5723
- return source.length;
5724
- for (let i = 0; i < line - 1; i++)
5725
- start += lines[i].length + 1;
5726
- return start + column;
5727
- }
5728
- function numberToPos(source, offset) {
5729
- if (typeof offset !== "number")
5730
- return offset;
5731
- if (offset > source.length) {
5732
- throw new Error(
5733
- `offset is longer than source length! offset ${offset} > length ${source.length}`
5734
- );
5735
- }
5736
- const lines = source.split(lineSplitRE);
5737
- let counted = 0;
5738
- let line = 0;
5739
- let column = 0;
5740
- for (; line < lines.length; line++) {
5741
- const lineLength = lines[line].length + 1;
5742
- if (counted + lineLength >= offset) {
5743
- column = offset - counted + 1;
5744
- break;
5745
- }
5746
- counted += lineLength;
5747
- }
5748
- return { line: line + 1, column };
5749
- }
5750
-
5751
- function Diff() {}
5752
- Diff.prototype = {
5753
- diff: function diff(oldString, newString) {
5754
- var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
5755
- var callback = options.callback;
5756
-
5757
- if (typeof options === 'function') {
5758
- callback = options;
5759
- options = {};
5760
- }
5761
-
5762
- this.options = options;
5763
- var self = this;
5764
-
5765
- function done(value) {
5766
- if (callback) {
5767
- setTimeout(function () {
5768
- callback(undefined, value);
5769
- }, 0);
5770
- return true;
5771
- } else {
5772
- return value;
5773
- }
5774
- } // Allow subclasses to massage the input prior to running
5775
-
5776
-
5777
- oldString = this.castInput(oldString);
5778
- newString = this.castInput(newString);
5779
- oldString = this.removeEmpty(this.tokenize(oldString));
5780
- newString = this.removeEmpty(this.tokenize(newString));
5781
- var newLen = newString.length,
5782
- oldLen = oldString.length;
5783
- var editLength = 1;
5784
- var maxEditLength = newLen + oldLen;
5785
-
5786
- if (options.maxEditLength) {
5787
- maxEditLength = Math.min(maxEditLength, options.maxEditLength);
5788
- }
5789
-
5790
- var bestPath = [{
5791
- newPos: -1,
5792
- components: []
5793
- }]; // Seed editLength = 0, i.e. the content starts with the same values
5794
-
5795
- var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
5796
-
5797
- if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
5798
- // Identity per the equality and tokenizer
5799
- return done([{
5800
- value: this.join(newString),
5801
- count: newString.length
5802
- }]);
5803
- } // Main worker method. checks all permutations of a given edit length for acceptance.
5804
-
5805
-
5806
- function execEditLength() {
5807
- for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
5808
- var basePath = void 0;
5809
-
5810
- var addPath = bestPath[diagonalPath - 1],
5811
- removePath = bestPath[diagonalPath + 1],
5812
- _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
5813
-
5814
- if (addPath) {
5815
- // No one else is going to attempt to use this value, clear it
5816
- bestPath[diagonalPath - 1] = undefined;
5817
- }
5818
-
5819
- var canAdd = addPath && addPath.newPos + 1 < newLen,
5820
- canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
5821
-
5822
- if (!canAdd && !canRemove) {
5823
- // If this path is a terminal then prune
5824
- bestPath[diagonalPath] = undefined;
5825
- continue;
5826
- } // Select the diagonal that we want to branch from. We select the prior
5827
- // path whose position in the new string is the farthest from the origin
5828
- // and does not pass the bounds of the diff graph
5829
-
5830
-
5831
- if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
5832
- basePath = clonePath(removePath);
5833
- self.pushComponent(basePath.components, undefined, true);
5834
- } else {
5835
- basePath = addPath; // No need to clone, we've pulled it from the list
5836
-
5837
- basePath.newPos++;
5838
- self.pushComponent(basePath.components, true, undefined);
5839
- }
5840
-
5841
- _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
5842
-
5843
- if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
5844
- return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
5845
- } else {
5846
- // Otherwise track this path as a potential candidate and continue.
5847
- bestPath[diagonalPath] = basePath;
5848
- }
5849
- }
5850
-
5851
- editLength++;
5852
- } // Performs the length of edit iteration. Is a bit fugly as this has to support the
5853
- // sync and async mode which is never fun. Loops over execEditLength until a value
5854
- // is produced, or until the edit length exceeds options.maxEditLength (if given),
5855
- // in which case it will return undefined.
5856
-
5857
-
5858
- if (callback) {
5859
- (function exec() {
5860
- setTimeout(function () {
5861
- if (editLength > maxEditLength) {
5862
- return callback();
5863
- }
5864
-
5865
- if (!execEditLength()) {
5866
- exec();
5867
- }
5868
- }, 0);
5869
- })();
5870
- } else {
5871
- while (editLength <= maxEditLength) {
5872
- var ret = execEditLength();
5873
-
5874
- if (ret) {
5875
- return ret;
5876
- }
5877
- }
5878
- }
5879
- },
5880
- pushComponent: function pushComponent(components, added, removed) {
5881
- var last = components[components.length - 1];
5882
-
5883
- if (last && last.added === added && last.removed === removed) {
5884
- // We need to clone here as the component clone operation is just
5885
- // as shallow array clone
5886
- components[components.length - 1] = {
5887
- count: last.count + 1,
5888
- added: added,
5889
- removed: removed
5890
- };
5891
- } else {
5892
- components.push({
5893
- count: 1,
5894
- added: added,
5895
- removed: removed
5896
- });
5897
- }
5898
- },
5899
- extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
5900
- var newLen = newString.length,
5901
- oldLen = oldString.length,
5902
- newPos = basePath.newPos,
5903
- oldPos = newPos - diagonalPath,
5904
- commonCount = 0;
5905
-
5906
- while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
5907
- newPos++;
5908
- oldPos++;
5909
- commonCount++;
5910
- }
5911
-
5912
- if (commonCount) {
5913
- basePath.components.push({
5914
- count: commonCount
5915
- });
5916
- }
5917
-
5918
- basePath.newPos = newPos;
5919
- return oldPos;
5920
- },
5921
- equals: function equals(left, right) {
5922
- if (this.options.comparator) {
5923
- return this.options.comparator(left, right);
5924
- } else {
5925
- return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
5926
- }
5927
- },
5928
- removeEmpty: function removeEmpty(array) {
5929
- var ret = [];
5930
-
5931
- for (var i = 0; i < array.length; i++) {
5932
- if (array[i]) {
5933
- ret.push(array[i]);
5934
- }
5935
- }
5936
-
5937
- return ret;
5938
- },
5939
- castInput: function castInput(value) {
5940
- return value;
5941
- },
5942
- tokenize: function tokenize(value) {
5943
- return value.split('');
5944
- },
5945
- join: function join(chars) {
5946
- return chars.join('');
5947
- }
5948
- };
5949
-
5950
- function buildValues(diff, components, newString, oldString, useLongestToken) {
5951
- var componentPos = 0,
5952
- componentLen = components.length,
5953
- newPos = 0,
5954
- oldPos = 0;
5955
-
5956
- for (; componentPos < componentLen; componentPos++) {
5957
- var component = components[componentPos];
5958
-
5959
- if (!component.removed) {
5960
- if (!component.added && useLongestToken) {
5961
- var value = newString.slice(newPos, newPos + component.count);
5962
- value = value.map(function (value, i) {
5963
- var oldValue = oldString[oldPos + i];
5964
- return oldValue.length > value.length ? oldValue : value;
5965
- });
5966
- component.value = diff.join(value);
5967
- } else {
5968
- component.value = diff.join(newString.slice(newPos, newPos + component.count));
5969
- }
5970
-
5971
- newPos += component.count; // Common case
5972
-
5973
- if (!component.added) {
5974
- oldPos += component.count;
5975
- }
5976
- } else {
5977
- component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
5978
- oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
5979
- // The diffing algorithm is tied to add then remove output and this is the simplest
5980
- // route to get the desired output with minimal overhead.
5981
-
5982
- if (componentPos && components[componentPos - 1].added) {
5983
- var tmp = components[componentPos - 1];
5984
- components[componentPos - 1] = components[componentPos];
5985
- components[componentPos] = tmp;
5986
- }
5987
- }
5988
- } // Special case handle for when one terminal is ignored (i.e. whitespace).
5989
- // For this case we merge the terminal into the prior string and drop the change.
5990
- // This is only available for string mode.
5991
-
5992
-
5993
- var lastComponent = components[componentLen - 1];
5994
-
5995
- if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
5996
- components[componentLen - 2].value += lastComponent.value;
5997
- components.pop();
5998
- }
2575
+ if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
2576
+ components[componentLen - 2].value += lastComponent.value;
2577
+ components.pop();
2578
+ }
5999
2579
 
6000
2580
  return components;
6001
2581
  }
@@ -6463,74 +3043,78 @@ const wrapAnsi256 = (offset = 0) => code => `\u001B[${38 + offset};5;${code}m`;
6463
3043
 
6464
3044
  const wrapAnsi16m = (offset = 0) => (red, green, blue) => `\u001B[${38 + offset};2;${red};${green};${blue}m`;
6465
3045
 
3046
+ const styles = {
3047
+ modifier: {
3048
+ reset: [0, 0],
3049
+ // 21 isn't widely supported and 22 does the same thing
3050
+ bold: [1, 22],
3051
+ dim: [2, 22],
3052
+ italic: [3, 23],
3053
+ underline: [4, 24],
3054
+ overline: [53, 55],
3055
+ inverse: [7, 27],
3056
+ hidden: [8, 28],
3057
+ strikethrough: [9, 29],
3058
+ },
3059
+ color: {
3060
+ black: [30, 39],
3061
+ red: [31, 39],
3062
+ green: [32, 39],
3063
+ yellow: [33, 39],
3064
+ blue: [34, 39],
3065
+ magenta: [35, 39],
3066
+ cyan: [36, 39],
3067
+ white: [37, 39],
3068
+
3069
+ // Bright color
3070
+ blackBright: [90, 39],
3071
+ gray: [90, 39], // Alias of `blackBright`
3072
+ grey: [90, 39], // Alias of `blackBright`
3073
+ redBright: [91, 39],
3074
+ greenBright: [92, 39],
3075
+ yellowBright: [93, 39],
3076
+ blueBright: [94, 39],
3077
+ magentaBright: [95, 39],
3078
+ cyanBright: [96, 39],
3079
+ whiteBright: [97, 39],
3080
+ },
3081
+ bgColor: {
3082
+ bgBlack: [40, 49],
3083
+ bgRed: [41, 49],
3084
+ bgGreen: [42, 49],
3085
+ bgYellow: [43, 49],
3086
+ bgBlue: [44, 49],
3087
+ bgMagenta: [45, 49],
3088
+ bgCyan: [46, 49],
3089
+ bgWhite: [47, 49],
3090
+
3091
+ // Bright color
3092
+ bgBlackBright: [100, 49],
3093
+ bgGray: [100, 49], // Alias of `bgBlackBright`
3094
+ bgGrey: [100, 49], // Alias of `bgBlackBright`
3095
+ bgRedBright: [101, 49],
3096
+ bgGreenBright: [102, 49],
3097
+ bgYellowBright: [103, 49],
3098
+ bgBlueBright: [104, 49],
3099
+ bgMagentaBright: [105, 49],
3100
+ bgCyanBright: [106, 49],
3101
+ bgWhiteBright: [107, 49],
3102
+ },
3103
+ };
3104
+
3105
+ Object.keys(styles.modifier);
3106
+ const foregroundColorNames = Object.keys(styles.color);
3107
+ const backgroundColorNames = Object.keys(styles.bgColor);
3108
+ [...foregroundColorNames, ...backgroundColorNames];
3109
+
6466
3110
  function assembleStyles() {
6467
3111
  const codes = new Map();
6468
- const styles = {
6469
- modifier: {
6470
- reset: [0, 0],
6471
- // 21 isn't widely supported and 22 does the same thing
6472
- bold: [1, 22],
6473
- dim: [2, 22],
6474
- italic: [3, 23],
6475
- underline: [4, 24],
6476
- overline: [53, 55],
6477
- inverse: [7, 27],
6478
- hidden: [8, 28],
6479
- strikethrough: [9, 29]
6480
- },
6481
- color: {
6482
- black: [30, 39],
6483
- red: [31, 39],
6484
- green: [32, 39],
6485
- yellow: [33, 39],
6486
- blue: [34, 39],
6487
- magenta: [35, 39],
6488
- cyan: [36, 39],
6489
- white: [37, 39],
6490
-
6491
- // Bright color
6492
- blackBright: [90, 39],
6493
- redBright: [91, 39],
6494
- greenBright: [92, 39],
6495
- yellowBright: [93, 39],
6496
- blueBright: [94, 39],
6497
- magentaBright: [95, 39],
6498
- cyanBright: [96, 39],
6499
- whiteBright: [97, 39]
6500
- },
6501
- bgColor: {
6502
- bgBlack: [40, 49],
6503
- bgRed: [41, 49],
6504
- bgGreen: [42, 49],
6505
- bgYellow: [43, 49],
6506
- bgBlue: [44, 49],
6507
- bgMagenta: [45, 49],
6508
- bgCyan: [46, 49],
6509
- bgWhite: [47, 49],
6510
-
6511
- // Bright color
6512
- bgBlackBright: [100, 49],
6513
- bgRedBright: [101, 49],
6514
- bgGreenBright: [102, 49],
6515
- bgYellowBright: [103, 49],
6516
- bgBlueBright: [104, 49],
6517
- bgMagentaBright: [105, 49],
6518
- bgCyanBright: [106, 49],
6519
- bgWhiteBright: [107, 49]
6520
- }
6521
- };
6522
-
6523
- // Alias bright black as gray (and grey)
6524
- styles.color.gray = styles.color.blackBright;
6525
- styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
6526
- styles.color.grey = styles.color.blackBright;
6527
- styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
6528
3112
 
6529
3113
  for (const [groupName, group] of Object.entries(styles)) {
6530
3114
  for (const [styleName, style] of Object.entries(group)) {
6531
3115
  styles[styleName] = {
6532
3116
  open: `\u001B[${style[0]}m`,
6533
- close: `\u001B[${style[1]}m`
3117
+ close: `\u001B[${style[1]}m`,
6534
3118
  };
6535
3119
 
6536
3120
  group[styleName] = styles[styleName];
@@ -6540,13 +3124,13 @@ function assembleStyles() {
6540
3124
 
6541
3125
  Object.defineProperty(styles, groupName, {
6542
3126
  value: group,
6543
- enumerable: false
3127
+ enumerable: false,
6544
3128
  });
6545
3129
  }
6546
3130
 
6547
3131
  Object.defineProperty(styles, 'codes', {
6548
3132
  value: codes,
6549
- enumerable: false
3133
+ enumerable: false,
6550
3134
  });
6551
3135
 
6552
3136
  styles.color.close = '\u001B[39m';
@@ -6577,39 +3161,41 @@ function assembleStyles() {
6577
3161
  return Math.round(((red - 8) / 247) * 24) + 232;
6578
3162
  }
6579
3163
 
6580
- return 16 +
6581
- (36 * Math.round(red / 255 * 5)) +
6582
- (6 * Math.round(green / 255 * 5)) +
6583
- Math.round(blue / 255 * 5);
3164
+ return 16
3165
+ + (36 * Math.round(red / 255 * 5))
3166
+ + (6 * Math.round(green / 255 * 5))
3167
+ + Math.round(blue / 255 * 5);
6584
3168
  },
6585
- enumerable: false
3169
+ enumerable: false,
6586
3170
  },
6587
3171
  hexToRgb: {
6588
3172
  value: hex => {
6589
- const matches = /(?<colorString>[a-f\d]{6}|[a-f\d]{3})/i.exec(hex.toString(16));
3173
+ const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
6590
3174
  if (!matches) {
6591
3175
  return [0, 0, 0];
6592
3176
  }
6593
3177
 
6594
- let {colorString} = matches.groups;
3178
+ let [colorString] = matches;
6595
3179
 
6596
3180
  if (colorString.length === 3) {
6597
- colorString = colorString.split('').map(character => character + character).join('');
3181
+ colorString = [...colorString].map(character => character + character).join('');
6598
3182
  }
6599
3183
 
6600
3184
  const integer = Number.parseInt(colorString, 16);
6601
3185
 
6602
3186
  return [
3187
+ /* eslint-disable no-bitwise */
6603
3188
  (integer >> 16) & 0xFF,
6604
3189
  (integer >> 8) & 0xFF,
6605
- integer & 0xFF
3190
+ integer & 0xFF,
3191
+ /* eslint-enable no-bitwise */
6606
3192
  ];
6607
3193
  },
6608
- enumerable: false
3194
+ enumerable: false,
6609
3195
  },
6610
3196
  hexToAnsi256: {
6611
3197
  value: hex => styles.rgbToAnsi256(...styles.hexToRgb(hex)),
6612
- enumerable: false
3198
+ enumerable: false,
6613
3199
  },
6614
3200
  ansi256ToAnsi: {
6615
3201
  value: code => {
@@ -6645,6 +3231,7 @@ function assembleStyles() {
6645
3231
  return 30;
6646
3232
  }
6647
3233
 
3234
+ // eslint-disable-next-line no-bitwise
6648
3235
  let result = 30 + ((Math.round(blue) << 2) | (Math.round(green) << 1) | Math.round(red));
6649
3236
 
6650
3237
  if (value === 2) {
@@ -6653,16 +3240,16 @@ function assembleStyles() {
6653
3240
 
6654
3241
  return result;
6655
3242
  },
6656
- enumerable: false
3243
+ enumerable: false,
6657
3244
  },
6658
3245
  rgbToAnsi: {
6659
3246
  value: (red, green, blue) => styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
6660
- enumerable: false
3247
+ enumerable: false,
6661
3248
  },
6662
3249
  hexToAnsi: {
6663
3250
  value: hex => styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
6664
- enumerable: false
6665
- }
3251
+ enumerable: false,
3252
+ },
6666
3253
  });
6667
3254
 
6668
3255
  return styles;
@@ -7433,17 +4020,17 @@ function diff(a, b, options) {
7433
4020
  }
7434
4021
 
7435
4022
  var matcherUtils = /*#__PURE__*/Object.freeze({
7436
- __proto__: null,
7437
- EXPECTED_COLOR: EXPECTED_COLOR,
7438
- RECEIVED_COLOR: RECEIVED_COLOR,
7439
- INVERTED_COLOR: INVERTED_COLOR,
7440
- BOLD_WEIGHT: BOLD_WEIGHT,
7441
- DIM_COLOR: DIM_COLOR,
7442
- matcherHint: matcherHint,
7443
- stringify: stringify,
7444
- printReceived: printReceived,
7445
- printExpected: printExpected,
7446
- diff: diff
4023
+ __proto__: null,
4024
+ EXPECTED_COLOR: EXPECTED_COLOR,
4025
+ RECEIVED_COLOR: RECEIVED_COLOR,
4026
+ INVERTED_COLOR: INVERTED_COLOR,
4027
+ BOLD_WEIGHT: BOLD_WEIGHT,
4028
+ DIM_COLOR: DIM_COLOR,
4029
+ matcherHint: matcherHint,
4030
+ stringify: stringify,
4031
+ printReceived: printReceived,
4032
+ printExpected: printExpected,
4033
+ diff: diff
7447
4034
  });
7448
4035
 
7449
- export { plugins_1 as a, posToNumber as b, stripAnsi as c, cliTruncate as d, stringWidth as e, format_1 as f, getOriginalPos as g, ansiStyles as h, interpretSourcePos as i, sliceAnsi as j, lineSplitRE as l, matcherUtils as m, numberToPos as n, parseStacktrace as p, stringify as s, unifiedDiff as u };
4036
+ export { stringify as a, safeClearTimeout as b, stripAnsi as c, safeSetInterval as d, safeClearInterval as e, format_1 as f, cliTruncate as g, stringWidth as h, ansiStyles as i, sliceAnsi as j, matcherUtils as m, plugins_1 as p, safeSetTimeout as s, unifiedDiff as u };