@vitest/utils 4.0.0-beta.2 → 4.0.0-beta.3
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.
- package/dist/diff.d.ts +2 -2
- package/dist/helpers.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/source-map.d.ts +6 -1
- package/dist/source-map.js +237 -288
- package/package.json +3 -3
package/dist/diff.d.ts
CHANGED
|
@@ -95,8 +95,8 @@ declare function diffStringsRaw(a: string, b: string, cleanup: boolean, options?
|
|
|
95
95
|
declare function diff(a: any, b: any, options?: DiffOptions): string | undefined;
|
|
96
96
|
declare function printDiffOrStringify(received: unknown, expected: unknown, options?: DiffOptions): string | undefined;
|
|
97
97
|
declare function replaceAsymmetricMatcher(actual: any, expected: any, actualReplaced?: WeakSet<WeakKey>, expectedReplaced?: WeakSet<WeakKey>): {
|
|
98
|
-
replacedActual: any
|
|
99
|
-
replacedExpected: any
|
|
98
|
+
replacedActual: any;
|
|
99
|
+
replacedExpected: any;
|
|
100
100
|
};
|
|
101
101
|
type PrintLabel = (string: string) => string;
|
|
102
102
|
declare function getLabelPrinter(...strings: Array<string>): PrintLabel;
|
package/dist/helpers.d.ts
CHANGED
|
@@ -28,8 +28,8 @@ declare function clone<T>(val: T, seen: WeakMap<any, any>, options?: CloneOption
|
|
|
28
28
|
declare function noop(): void;
|
|
29
29
|
declare function objectAttr(source: any, path: string, defaultValue?: undefined): any;
|
|
30
30
|
type DeferPromise<T> = Promise<T> & {
|
|
31
|
-
resolve: (value: T | PromiseLike<T>) => void
|
|
32
|
-
reject: (reason?: any) => void
|
|
31
|
+
resolve: (value: T | PromiseLike<T>) => void;
|
|
32
|
+
reject: (reason?: any) => void;
|
|
33
33
|
};
|
|
34
34
|
declare function createDefer<T>(): DeferPromise<T>;
|
|
35
35
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -44,8 +44,8 @@ interface SafeTimers {
|
|
|
44
44
|
// node.js timers
|
|
45
45
|
nextTick?: (cb: () => void) => void;
|
|
46
46
|
setImmediate?: {
|
|
47
|
-
<TArgs extends any[]>(callback: (...args: TArgs) => void, ...args: TArgs): any
|
|
48
|
-
__promisify__: <T = void>(value?: T, options?: any) => Promise<T
|
|
47
|
+
<TArgs extends any[]>(callback: (...args: TArgs) => void, ...args: TArgs): any;
|
|
48
|
+
__promisify__: <T = void>(value?: T, options?: any) => Promise<T>;
|
|
49
49
|
};
|
|
50
50
|
clearImmediate?: (immediateId: any) => void;
|
|
51
51
|
// cross-platform timers
|
package/dist/source-map.d.ts
CHANGED
|
@@ -85,6 +85,11 @@ declare abstract class SourceMap {
|
|
|
85
85
|
resolvedSources: SourceMapV3['sources'];
|
|
86
86
|
ignoreList: SourceMapV3['ignoreList'];
|
|
87
87
|
}
|
|
88
|
+
type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
|
|
89
|
+
type RoArray<T> = Ro<T>[];
|
|
90
|
+
type RoObject<T> = {
|
|
91
|
+
[K in keyof T]: T[K] | Ro<T[K]>;
|
|
92
|
+
};
|
|
88
93
|
|
|
89
94
|
declare const LEAST_UPPER_BOUND = -1;
|
|
90
95
|
declare const GREATEST_LOWER_BOUND = 1;
|
|
@@ -103,7 +108,7 @@ declare class TraceMap implements SourceMap {
|
|
|
103
108
|
private _decodedMemo;
|
|
104
109
|
private _bySources;
|
|
105
110
|
private _bySourceMemos;
|
|
106
|
-
constructor(map: SourceMapInput
|
|
111
|
+
constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
|
|
107
112
|
}
|
|
108
113
|
/**
|
|
109
114
|
* A higher-level API to find the source/line/column associated with a generated line/column
|
package/dist/source-map.js
CHANGED
|
@@ -282,7 +282,7 @@ function normalizePath(url, type) {
|
|
|
282
282
|
/**
|
|
283
283
|
* Attempts to resolve `input` URL/path relative to `base`.
|
|
284
284
|
*/
|
|
285
|
-
function resolve$
|
|
285
|
+
function resolve$1(input, base) {
|
|
286
286
|
if (!input && !base)
|
|
287
287
|
return '';
|
|
288
288
|
const url = parseUrl(input);
|
|
@@ -342,350 +342,299 @@ function resolve$2(input, base) {
|
|
|
342
342
|
}
|
|
343
343
|
}
|
|
344
344
|
|
|
345
|
-
|
|
346
|
-
// The base is always treated as a directory, if it's not empty.
|
|
347
|
-
// https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
|
|
348
|
-
// https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
|
|
349
|
-
if (base && !base.endsWith('/'))
|
|
350
|
-
base += '/';
|
|
351
|
-
return resolve$2(input, base);
|
|
352
|
-
}
|
|
345
|
+
// src/trace-mapping.ts
|
|
353
346
|
|
|
354
|
-
|
|
355
|
-
* Removes everything after the last "/", but leaves the slash.
|
|
356
|
-
*/
|
|
347
|
+
// src/strip-filename.ts
|
|
357
348
|
function stripFilename(path) {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
return path.slice(0, index + 1);
|
|
349
|
+
if (!path) return "";
|
|
350
|
+
const index = path.lastIndexOf("/");
|
|
351
|
+
return path.slice(0, index + 1);
|
|
362
352
|
}
|
|
363
353
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
const
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
const REV_GENERATED_COLUMN = 2;
|
|
354
|
+
// src/resolve.ts
|
|
355
|
+
function resolver(mapUrl, sourceRoot) {
|
|
356
|
+
const from = stripFilename(mapUrl);
|
|
357
|
+
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
358
|
+
return (source) => resolve$1(prefix + (source || ""), from);
|
|
359
|
+
}
|
|
371
360
|
|
|
361
|
+
// src/sourcemap-segment.ts
|
|
362
|
+
var COLUMN = 0;
|
|
363
|
+
var SOURCES_INDEX = 1;
|
|
364
|
+
var SOURCE_LINE = 2;
|
|
365
|
+
var SOURCE_COLUMN = 3;
|
|
366
|
+
var NAMES_INDEX = 4;
|
|
367
|
+
var REV_GENERATED_LINE = 1;
|
|
368
|
+
var REV_GENERATED_COLUMN = 2;
|
|
369
|
+
|
|
370
|
+
// src/sort.ts
|
|
372
371
|
function maybeSort(mappings, owned) {
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
381
|
-
mappings[i] = sortSegments(mappings[i], owned);
|
|
382
|
-
}
|
|
383
|
-
return mappings;
|
|
372
|
+
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
373
|
+
if (unsortedIndex === mappings.length) return mappings;
|
|
374
|
+
if (!owned) mappings = mappings.slice();
|
|
375
|
+
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
376
|
+
mappings[i] = sortSegments(mappings[i], owned);
|
|
377
|
+
}
|
|
378
|
+
return mappings;
|
|
384
379
|
}
|
|
385
380
|
function nextUnsortedSegmentLine(mappings, start) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
return mappings.length;
|
|
381
|
+
for (let i = start; i < mappings.length; i++) {
|
|
382
|
+
if (!isSorted(mappings[i])) return i;
|
|
383
|
+
}
|
|
384
|
+
return mappings.length;
|
|
391
385
|
}
|
|
392
386
|
function isSorted(line) {
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
}
|
|
387
|
+
for (let j = 1; j < line.length; j++) {
|
|
388
|
+
if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
|
389
|
+
return false;
|
|
397
390
|
}
|
|
398
|
-
|
|
391
|
+
}
|
|
392
|
+
return true;
|
|
399
393
|
}
|
|
400
394
|
function sortSegments(line, owned) {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
return line.sort(sortComparator);
|
|
395
|
+
if (!owned) line = line.slice();
|
|
396
|
+
return line.sort(sortComparator);
|
|
404
397
|
}
|
|
405
398
|
function sortComparator(a, b) {
|
|
406
|
-
|
|
399
|
+
return a[COLUMN] - b[COLUMN];
|
|
407
400
|
}
|
|
408
401
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
* A binary search implementation that returns the index if a match is found.
|
|
412
|
-
* If no match is found, then the left-index (the index associated with the item that comes just
|
|
413
|
-
* before the desired index) is returned. To maintain proper sort order, a splice would happen at
|
|
414
|
-
* the next index:
|
|
415
|
-
*
|
|
416
|
-
* ```js
|
|
417
|
-
* const array = [1, 3];
|
|
418
|
-
* const needle = 2;
|
|
419
|
-
* const index = binarySearch(array, needle, (item, needle) => item - needle);
|
|
420
|
-
*
|
|
421
|
-
* assert.equal(index, 0);
|
|
422
|
-
* array.splice(index + 1, 0, needle);
|
|
423
|
-
* assert.deepEqual(array, [1, 2, 3]);
|
|
424
|
-
* ```
|
|
425
|
-
*/
|
|
402
|
+
// src/binary-search.ts
|
|
403
|
+
var found = false;
|
|
426
404
|
function binarySearch(haystack, needle, low, high) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
high = mid - 1;
|
|
439
|
-
}
|
|
405
|
+
while (low <= high) {
|
|
406
|
+
const mid = low + (high - low >> 1);
|
|
407
|
+
const cmp = haystack[mid][COLUMN] - needle;
|
|
408
|
+
if (cmp === 0) {
|
|
409
|
+
found = true;
|
|
410
|
+
return mid;
|
|
411
|
+
}
|
|
412
|
+
if (cmp < 0) {
|
|
413
|
+
low = mid + 1;
|
|
414
|
+
} else {
|
|
415
|
+
high = mid - 1;
|
|
440
416
|
}
|
|
441
|
-
|
|
442
|
-
|
|
417
|
+
}
|
|
418
|
+
found = false;
|
|
419
|
+
return low - 1;
|
|
443
420
|
}
|
|
444
421
|
function upperBound(haystack, needle, index) {
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
return index;
|
|
422
|
+
for (let i = index + 1; i < haystack.length; index = i++) {
|
|
423
|
+
if (haystack[i][COLUMN] !== needle) break;
|
|
424
|
+
}
|
|
425
|
+
return index;
|
|
450
426
|
}
|
|
451
427
|
function lowerBound(haystack, needle, index) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
return index;
|
|
428
|
+
for (let i = index - 1; i >= 0; index = i--) {
|
|
429
|
+
if (haystack[i][COLUMN] !== needle) break;
|
|
430
|
+
}
|
|
431
|
+
return index;
|
|
457
432
|
}
|
|
458
433
|
function memoizedState() {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
434
|
+
return {
|
|
435
|
+
lastKey: -1,
|
|
436
|
+
lastNeedle: -1,
|
|
437
|
+
lastIndex: -1
|
|
438
|
+
};
|
|
464
439
|
}
|
|
465
|
-
/**
|
|
466
|
-
* This overly complicated beast is just to record the last tested line/column and the resulting
|
|
467
|
-
* index, allowing us to skip a few tests if mappings are monotonically increasing.
|
|
468
|
-
*/
|
|
469
440
|
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
else {
|
|
483
|
-
high = lastIndex;
|
|
484
|
-
}
|
|
441
|
+
const { lastKey, lastNeedle, lastIndex } = state;
|
|
442
|
+
let low = 0;
|
|
443
|
+
let high = haystack.length - 1;
|
|
444
|
+
if (key === lastKey) {
|
|
445
|
+
if (needle === lastNeedle) {
|
|
446
|
+
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
447
|
+
return lastIndex;
|
|
448
|
+
}
|
|
449
|
+
if (needle >= lastNeedle) {
|
|
450
|
+
low = lastIndex === -1 ? 0 : lastIndex;
|
|
451
|
+
} else {
|
|
452
|
+
high = lastIndex;
|
|
485
453
|
}
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
454
|
+
}
|
|
455
|
+
state.lastKey = key;
|
|
456
|
+
state.lastNeedle = needle;
|
|
457
|
+
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
489
458
|
}
|
|
490
459
|
|
|
491
|
-
//
|
|
492
|
-
// of generated line/column.
|
|
460
|
+
// src/by-source.ts
|
|
493
461
|
function buildBySources(decoded, memos) {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
insert(originalLine, index, [sourceColumn, i, seg[COLUMN]]);
|
|
514
|
-
}
|
|
462
|
+
const sources = memos.map(buildNullArray);
|
|
463
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
464
|
+
const line = decoded[i];
|
|
465
|
+
for (let j = 0; j < line.length; j++) {
|
|
466
|
+
const seg = line[j];
|
|
467
|
+
if (seg.length === 1) continue;
|
|
468
|
+
const sourceIndex2 = seg[SOURCES_INDEX];
|
|
469
|
+
const sourceLine = seg[SOURCE_LINE];
|
|
470
|
+
const sourceColumn = seg[SOURCE_COLUMN];
|
|
471
|
+
const originalSource = sources[sourceIndex2];
|
|
472
|
+
const originalLine = originalSource[sourceLine] || (originalSource[sourceLine] = []);
|
|
473
|
+
const memo = memos[sourceIndex2];
|
|
474
|
+
let index = upperBound(
|
|
475
|
+
originalLine,
|
|
476
|
+
sourceColumn,
|
|
477
|
+
memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine)
|
|
478
|
+
);
|
|
479
|
+
memo.lastIndex = ++index;
|
|
480
|
+
insert(originalLine, index, [sourceColumn, i, seg[COLUMN]]);
|
|
515
481
|
}
|
|
516
|
-
|
|
482
|
+
}
|
|
483
|
+
return sources;
|
|
517
484
|
}
|
|
518
485
|
function insert(array, index, value) {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
486
|
+
for (let i = array.length; i > index; i--) {
|
|
487
|
+
array[i] = array[i - 1];
|
|
488
|
+
}
|
|
489
|
+
array[index] = value;
|
|
523
490
|
}
|
|
524
|
-
// Null arrays allow us to use ordered index keys without actually allocating contiguous memory like
|
|
525
|
-
// a real array. We use a null-prototype object to avoid prototype pollution and deoptimizations.
|
|
526
|
-
// Numeric properties on objects are magically sorted in ascending order by the engine regardless of
|
|
527
|
-
// the insertion order. So, by setting any numeric keys, even out of order, we'll get ascending
|
|
528
|
-
// order when iterating with for-in.
|
|
529
491
|
function buildNullArray() {
|
|
530
|
-
|
|
492
|
+
return { __proto__: null };
|
|
531
493
|
}
|
|
532
494
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
const GREATEST_LOWER_BOUND = 1;
|
|
537
|
-
class TraceMap {
|
|
538
|
-
constructor(map, mapUrl) {
|
|
539
|
-
const isString = typeof map === 'string';
|
|
540
|
-
if (!isString && map._decodedMemo)
|
|
541
|
-
return map;
|
|
542
|
-
const parsed = (isString ? JSON.parse(map) : map);
|
|
543
|
-
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
544
|
-
this.version = version;
|
|
545
|
-
this.file = file;
|
|
546
|
-
this.names = names || [];
|
|
547
|
-
this.sourceRoot = sourceRoot;
|
|
548
|
-
this.sources = sources;
|
|
549
|
-
this.sourcesContent = sourcesContent;
|
|
550
|
-
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
|
|
551
|
-
const from = resolve$1(sourceRoot || '', stripFilename(mapUrl));
|
|
552
|
-
this.resolvedSources = sources.map((s) => resolve$1(s || '', from));
|
|
553
|
-
const { mappings } = parsed;
|
|
554
|
-
if (typeof mappings === 'string') {
|
|
555
|
-
this._encoded = mappings;
|
|
556
|
-
this._decoded = undefined;
|
|
557
|
-
}
|
|
558
|
-
else {
|
|
559
|
-
this._encoded = undefined;
|
|
560
|
-
this._decoded = maybeSort(mappings, isString);
|
|
561
|
-
}
|
|
562
|
-
this._decodedMemo = memoizedState();
|
|
563
|
-
this._bySources = undefined;
|
|
564
|
-
this._bySourceMemos = undefined;
|
|
565
|
-
}
|
|
495
|
+
// src/types.ts
|
|
496
|
+
function parse(map) {
|
|
497
|
+
return typeof map === "string" ? JSON.parse(map) : map;
|
|
566
498
|
}
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
499
|
+
|
|
500
|
+
// src/trace-mapping.ts
|
|
501
|
+
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
502
|
+
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
503
|
+
var LEAST_UPPER_BOUND = -1;
|
|
504
|
+
var GREATEST_LOWER_BOUND = 1;
|
|
505
|
+
var TraceMap = class {
|
|
506
|
+
constructor(map, mapUrl) {
|
|
507
|
+
const isString = typeof map === "string";
|
|
508
|
+
if (!isString && map._decodedMemo) return map;
|
|
509
|
+
const parsed = parse(map);
|
|
510
|
+
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
511
|
+
this.version = version;
|
|
512
|
+
this.file = file;
|
|
513
|
+
this.names = names || [];
|
|
514
|
+
this.sourceRoot = sourceRoot;
|
|
515
|
+
this.sources = sources;
|
|
516
|
+
this.sourcesContent = sourcesContent;
|
|
517
|
+
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
518
|
+
const resolve = resolver(mapUrl, sourceRoot);
|
|
519
|
+
this.resolvedSources = sources.map(resolve);
|
|
520
|
+
const { mappings } = parsed;
|
|
521
|
+
if (typeof mappings === "string") {
|
|
522
|
+
this._encoded = mappings;
|
|
523
|
+
this._decoded = void 0;
|
|
524
|
+
} else if (Array.isArray(mappings)) {
|
|
525
|
+
this._encoded = void 0;
|
|
526
|
+
this._decoded = maybeSort(mappings, isString);
|
|
527
|
+
} else if (parsed.sections) {
|
|
528
|
+
throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
|
529
|
+
} else {
|
|
530
|
+
throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
|
531
|
+
}
|
|
532
|
+
this._decodedMemo = memoizedState();
|
|
533
|
+
this._bySources = void 0;
|
|
534
|
+
this._bySourceMemos = void 0;
|
|
535
|
+
}
|
|
536
|
+
};
|
|
571
537
|
function cast(map) {
|
|
572
|
-
|
|
538
|
+
return map;
|
|
573
539
|
}
|
|
574
|
-
/**
|
|
575
|
-
* Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
|
|
576
|
-
*/
|
|
577
540
|
function decodedMappings(map) {
|
|
578
|
-
|
|
579
|
-
|
|
541
|
+
var _a;
|
|
542
|
+
return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
|
|
580
543
|
}
|
|
581
|
-
/**
|
|
582
|
-
* A higher-level API to find the source/line/column associated with a generated line/column
|
|
583
|
-
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
|
584
|
-
* `source-map` library.
|
|
585
|
-
*/
|
|
586
544
|
function originalPositionFor(map, needle) {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
545
|
+
let { line, column, bias } = needle;
|
|
546
|
+
line--;
|
|
547
|
+
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
548
|
+
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
549
|
+
const decoded = decodedMappings(map);
|
|
550
|
+
if (line >= decoded.length) return OMapping(null, null, null, null);
|
|
551
|
+
const segments = decoded[line];
|
|
552
|
+
const index = traceSegmentInternal(
|
|
553
|
+
segments,
|
|
554
|
+
cast(map)._decodedMemo,
|
|
555
|
+
line,
|
|
556
|
+
column,
|
|
557
|
+
bias || GREATEST_LOWER_BOUND
|
|
558
|
+
);
|
|
559
|
+
if (index === -1) return OMapping(null, null, null, null);
|
|
560
|
+
const segment = segments[index];
|
|
561
|
+
if (segment.length === 1) return OMapping(null, null, null, null);
|
|
562
|
+
const { names, resolvedSources } = map;
|
|
563
|
+
return OMapping(
|
|
564
|
+
resolvedSources[segment[SOURCES_INDEX]],
|
|
565
|
+
segment[SOURCE_LINE] + 1,
|
|
566
|
+
segment[SOURCE_COLUMN],
|
|
567
|
+
segment.length === 5 ? names[segment[NAMES_INDEX]] : null
|
|
568
|
+
);
|
|
607
569
|
}
|
|
608
|
-
/**
|
|
609
|
-
* Finds the generated line/column position of the provided source/line/column source position.
|
|
610
|
-
*/
|
|
611
570
|
function generatedPositionFor(map, needle) {
|
|
612
|
-
|
|
613
|
-
|
|
571
|
+
const { source, line, column, bias } = needle;
|
|
572
|
+
return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
|
|
614
573
|
}
|
|
615
|
-
/**
|
|
616
|
-
* Iterates each mapping in generated position order.
|
|
617
|
-
*/
|
|
618
574
|
function eachMapping(map, cb) {
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
});
|
|
646
|
-
}
|
|
575
|
+
const decoded = decodedMappings(map);
|
|
576
|
+
const { names, resolvedSources } = map;
|
|
577
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
578
|
+
const line = decoded[i];
|
|
579
|
+
for (let j = 0; j < line.length; j++) {
|
|
580
|
+
const seg = line[j];
|
|
581
|
+
const generatedLine = i + 1;
|
|
582
|
+
const generatedColumn = seg[0];
|
|
583
|
+
let source = null;
|
|
584
|
+
let originalLine = null;
|
|
585
|
+
let originalColumn = null;
|
|
586
|
+
let name = null;
|
|
587
|
+
if (seg.length !== 1) {
|
|
588
|
+
source = resolvedSources[seg[1]];
|
|
589
|
+
originalLine = seg[2] + 1;
|
|
590
|
+
originalColumn = seg[3];
|
|
591
|
+
}
|
|
592
|
+
if (seg.length === 5) name = names[seg[4]];
|
|
593
|
+
cb({
|
|
594
|
+
generatedLine,
|
|
595
|
+
generatedColumn,
|
|
596
|
+
source,
|
|
597
|
+
originalLine,
|
|
598
|
+
originalColumn,
|
|
599
|
+
name
|
|
600
|
+
});
|
|
647
601
|
}
|
|
602
|
+
}
|
|
648
603
|
}
|
|
649
604
|
function OMapping(source, line, column, name) {
|
|
650
|
-
|
|
605
|
+
return { source, line, column, name };
|
|
651
606
|
}
|
|
652
607
|
function GMapping(line, column) {
|
|
653
|
-
|
|
608
|
+
return { line, column };
|
|
654
609
|
}
|
|
655
610
|
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
if (index === -1 || index === segments.length)
|
|
663
|
-
return -1;
|
|
664
|
-
return index;
|
|
611
|
+
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
612
|
+
if (found) {
|
|
613
|
+
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|
614
|
+
} else if (bias === LEAST_UPPER_BOUND) index++;
|
|
615
|
+
if (index === -1 || index === segments.length) return -1;
|
|
616
|
+
return index;
|
|
665
617
|
}
|
|
666
618
|
function generatedPosition(map, source, line, column, bias, all) {
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
return GMapping(null, null);
|
|
687
|
-
const segment = segments[index];
|
|
688
|
-
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
|
619
|
+
var _a;
|
|
620
|
+
line--;
|
|
621
|
+
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
622
|
+
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
623
|
+
const { sources, resolvedSources } = map;
|
|
624
|
+
let sourceIndex2 = sources.indexOf(source);
|
|
625
|
+
if (sourceIndex2 === -1) sourceIndex2 = resolvedSources.indexOf(source);
|
|
626
|
+
if (sourceIndex2 === -1) return all ? [] : GMapping(null, null);
|
|
627
|
+
const generated = (_a = cast(map))._bySources || (_a._bySources = buildBySources(
|
|
628
|
+
decodedMappings(map),
|
|
629
|
+
cast(map)._bySourceMemos = sources.map(memoizedState)
|
|
630
|
+
));
|
|
631
|
+
const segments = generated[sourceIndex2][line];
|
|
632
|
+
if (segments == null) return all ? [] : GMapping(null, null);
|
|
633
|
+
const memo = cast(map)._bySourceMemos[sourceIndex2];
|
|
634
|
+
const index = traceSegmentInternal(segments, memo, line, column, bias);
|
|
635
|
+
if (index === -1) return GMapping(null, null);
|
|
636
|
+
const segment = segments[index];
|
|
637
|
+
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
|
689
638
|
}
|
|
690
639
|
|
|
691
640
|
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitest/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "4.0.0-beta.
|
|
4
|
+
"version": "4.0.0-beta.3",
|
|
5
5
|
"description": "Shared Vitest utility functions",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"loupe": "^3.1.4",
|
|
64
64
|
"tinyrainbow": "^2.0.0",
|
|
65
|
-
"@vitest/pretty-format": "4.0.0-beta.
|
|
65
|
+
"@vitest/pretty-format": "4.0.0-beta.3"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@jridgewell/trace-mapping": "^0.3.
|
|
68
|
+
"@jridgewell/trace-mapping": "^0.3.29",
|
|
69
69
|
"@types/estree": "^1.0.8",
|
|
70
70
|
"diff-sequences": "^29.6.3",
|
|
71
71
|
"tinyhighlight": "^0.3.2"
|