@vitest/utils 2.1.3 → 2.1.4
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/chunk-_commonjsHelpers.js +1 -1
- package/dist/diff.js +36 -36
- package/dist/helpers.d.ts +9 -1
- package/dist/helpers.js +33 -1
- package/dist/index.d.ts +19 -19
- package/dist/index.js +97 -97
- package/dist/source-map.js +101 -101
- package/package.json +4 -4
package/dist/diff.js
CHANGED
@@ -4,42 +4,6 @@ import { g as getDefaultExportFromCjs, s as stringify } from './chunk-_commonjsH
|
|
4
4
|
import { deepClone, getOwnProperties, getType as getType$1 } from './helpers.js';
|
5
5
|
import 'loupe';
|
6
6
|
|
7
|
-
function getType(value) {
|
8
|
-
if (value === void 0) {
|
9
|
-
return "undefined";
|
10
|
-
} else if (value === null) {
|
11
|
-
return "null";
|
12
|
-
} else if (Array.isArray(value)) {
|
13
|
-
return "array";
|
14
|
-
} else if (typeof value === "boolean") {
|
15
|
-
return "boolean";
|
16
|
-
} else if (typeof value === "function") {
|
17
|
-
return "function";
|
18
|
-
} else if (typeof value === "number") {
|
19
|
-
return "number";
|
20
|
-
} else if (typeof value === "string") {
|
21
|
-
return "string";
|
22
|
-
} else if (typeof value === "bigint") {
|
23
|
-
return "bigint";
|
24
|
-
} else if (typeof value === "object") {
|
25
|
-
if (value != null) {
|
26
|
-
if (value.constructor === RegExp) {
|
27
|
-
return "regexp";
|
28
|
-
} else if (value.constructor === Map) {
|
29
|
-
return "map";
|
30
|
-
} else if (value.constructor === Set) {
|
31
|
-
return "set";
|
32
|
-
} else if (value.constructor === Date) {
|
33
|
-
return "date";
|
34
|
-
}
|
35
|
-
}
|
36
|
-
return "object";
|
37
|
-
} else if (typeof value === "symbol") {
|
38
|
-
return "symbol";
|
39
|
-
}
|
40
|
-
throw new Error(`value of unknown type: ${value}`);
|
41
|
-
}
|
42
|
-
|
43
7
|
const DIFF_DELETE = -1;
|
44
8
|
const DIFF_INSERT = 1;
|
45
9
|
const DIFF_EQUAL = 0;
|
@@ -1599,6 +1563,42 @@ function diffLinesRaw(aLines, bLines, options) {
|
|
1599
1563
|
return [diffs, truncated];
|
1600
1564
|
}
|
1601
1565
|
|
1566
|
+
function getType(value) {
|
1567
|
+
if (value === void 0) {
|
1568
|
+
return "undefined";
|
1569
|
+
} else if (value === null) {
|
1570
|
+
return "null";
|
1571
|
+
} else if (Array.isArray(value)) {
|
1572
|
+
return "array";
|
1573
|
+
} else if (typeof value === "boolean") {
|
1574
|
+
return "boolean";
|
1575
|
+
} else if (typeof value === "function") {
|
1576
|
+
return "function";
|
1577
|
+
} else if (typeof value === "number") {
|
1578
|
+
return "number";
|
1579
|
+
} else if (typeof value === "string") {
|
1580
|
+
return "string";
|
1581
|
+
} else if (typeof value === "bigint") {
|
1582
|
+
return "bigint";
|
1583
|
+
} else if (typeof value === "object") {
|
1584
|
+
if (value != null) {
|
1585
|
+
if (value.constructor === RegExp) {
|
1586
|
+
return "regexp";
|
1587
|
+
} else if (value.constructor === Map) {
|
1588
|
+
return "map";
|
1589
|
+
} else if (value.constructor === Set) {
|
1590
|
+
return "set";
|
1591
|
+
} else if (value.constructor === Date) {
|
1592
|
+
return "date";
|
1593
|
+
}
|
1594
|
+
}
|
1595
|
+
return "object";
|
1596
|
+
} else if (typeof value === "symbol") {
|
1597
|
+
return "symbol";
|
1598
|
+
}
|
1599
|
+
throw new Error(`value of unknown type: ${value}`);
|
1600
|
+
}
|
1601
|
+
|
1602
1602
|
function getNewLineSymbol(string) {
|
1603
1603
|
return string.includes("\r\n") ? "\r\n" : "\n";
|
1604
1604
|
}
|
package/dist/helpers.d.ts
CHANGED
@@ -42,5 +42,13 @@ declare function createDefer<T>(): DeferPromise<T>;
|
|
42
42
|
*/
|
43
43
|
declare function getCallLastIndex(code: string): number | null;
|
44
44
|
declare function isNegativeNaN(val: number): boolean;
|
45
|
+
/**
|
46
|
+
* Deep merge :P
|
47
|
+
*
|
48
|
+
* Will merge objects only if they are plain
|
49
|
+
*
|
50
|
+
* Do not merge types - it is very expensive and usually it's better to case a type here
|
51
|
+
*/
|
52
|
+
declare function deepMerge<T extends object = object>(target: T, ...sources: any[]): T;
|
45
53
|
|
46
|
-
export { type DeferPromise, assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
54
|
+
export { type DeferPromise, assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
package/dist/helpers.js
CHANGED
@@ -188,5 +188,37 @@ function isNegativeNaN(val) {
|
|
188
188
|
const isNegative = u32[1] >>> 31 === 1;
|
189
189
|
return isNegative;
|
190
190
|
}
|
191
|
+
function toString(v) {
|
192
|
+
return Object.prototype.toString.call(v);
|
193
|
+
}
|
194
|
+
function isPlainObject(val) {
|
195
|
+
return toString(val) === "[object Object]" && (!val.constructor || val.constructor.name === "Object");
|
196
|
+
}
|
197
|
+
function isMergeableObject(item) {
|
198
|
+
return isPlainObject(item) && !Array.isArray(item);
|
199
|
+
}
|
200
|
+
function deepMerge(target, ...sources) {
|
201
|
+
if (!sources.length) {
|
202
|
+
return target;
|
203
|
+
}
|
204
|
+
const source = sources.shift();
|
205
|
+
if (source === void 0) {
|
206
|
+
return target;
|
207
|
+
}
|
208
|
+
if (isMergeableObject(target) && isMergeableObject(source)) {
|
209
|
+
Object.keys(source).forEach((key) => {
|
210
|
+
const _source = source;
|
211
|
+
if (isMergeableObject(_source[key])) {
|
212
|
+
if (!target[key]) {
|
213
|
+
target[key] = {};
|
214
|
+
}
|
215
|
+
deepMerge(target[key], _source[key]);
|
216
|
+
} else {
|
217
|
+
target[key] = _source[key];
|
218
|
+
}
|
219
|
+
});
|
220
|
+
}
|
221
|
+
return deepMerge(target, ...sources);
|
222
|
+
}
|
191
223
|
|
192
|
-
export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
224
|
+
export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
package/dist/index.d.ts
CHANGED
@@ -1,22 +1,8 @@
|
|
1
|
-
export { DeferPromise, assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
1
|
import { PrettyFormatOptions } from '@vitest/pretty-format';
|
2
|
+
export { DeferPromise, assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
3
3
|
import { Colors } from 'tinyrainbow';
|
4
4
|
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack, SerializedError, TestError } from './types.js';
|
5
5
|
|
6
|
-
interface SafeTimers {
|
7
|
-
nextTick: (cb: () => void) => void;
|
8
|
-
setTimeout: typeof setTimeout;
|
9
|
-
setInterval: typeof setInterval;
|
10
|
-
clearInterval: typeof clearInterval;
|
11
|
-
clearTimeout: typeof clearTimeout;
|
12
|
-
setImmediate: typeof setImmediate;
|
13
|
-
clearImmediate: typeof clearImmediate;
|
14
|
-
}
|
15
|
-
declare function getSafeTimers(): SafeTimers;
|
16
|
-
declare function setSafeTimers(): void;
|
17
|
-
|
18
|
-
declare function shuffle<T>(array: T[], seed?: number): T[];
|
19
|
-
|
20
6
|
type Inspect = (value: unknown, options: Options) => string;
|
21
7
|
interface Options {
|
22
8
|
showHidden: boolean;
|
@@ -40,10 +26,6 @@ declare function format(...args: unknown[]): string;
|
|
40
26
|
declare function inspect(obj: unknown, options?: LoupeOptions): string;
|
41
27
|
declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
|
42
28
|
|
43
|
-
declare const lineSplitRE: RegExp;
|
44
|
-
declare function positionToOffset(source: string, lineNumber: number, columnNumber: number): number;
|
45
|
-
declare function offsetToLineNumber(source: string, offset: number): number;
|
46
|
-
|
47
29
|
interface HighlightOptions {
|
48
30
|
jsx?: boolean;
|
49
31
|
colors?: Colors;
|
@@ -52,4 +34,22 @@ declare function highlight(code: string, options?: HighlightOptions): string;
|
|
52
34
|
|
53
35
|
declare function nanoid(size?: number): string;
|
54
36
|
|
37
|
+
declare const lineSplitRE: RegExp;
|
38
|
+
declare function positionToOffset(source: string, lineNumber: number, columnNumber: number): number;
|
39
|
+
declare function offsetToLineNumber(source: string, offset: number): number;
|
40
|
+
|
41
|
+
declare function shuffle<T>(array: T[], seed?: number): T[];
|
42
|
+
|
43
|
+
interface SafeTimers {
|
44
|
+
nextTick: (cb: () => void) => void;
|
45
|
+
setTimeout: typeof setTimeout;
|
46
|
+
setInterval: typeof setInterval;
|
47
|
+
clearInterval: typeof clearInterval;
|
48
|
+
clearTimeout: typeof clearTimeout;
|
49
|
+
setImmediate: typeof setImmediate;
|
50
|
+
clearImmediate: typeof clearImmediate;
|
51
|
+
}
|
52
|
+
declare function getSafeTimers(): SafeTimers;
|
53
|
+
declare function setSafeTimers(): void;
|
54
|
+
|
55
55
|
export { type SafeTimers, type StringifyOptions, format, getSafeTimers, highlight, inspect, lineSplitRE, nanoid, objDisplay, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle, stringify };
|
package/dist/index.js
CHANGED
@@ -1,104 +1,9 @@
|
|
1
|
-
export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
1
|
import { g as getDefaultExportFromCjs } from './chunk-_commonjsHelpers.js';
|
3
2
|
export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-_commonjsHelpers.js';
|
3
|
+
export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, deepMerge, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
4
4
|
import c from 'tinyrainbow';
|
5
|
-
import 'loupe';
|
6
5
|
import '@vitest/pretty-format';
|
7
|
-
|
8
|
-
const SAFE_TIMERS_SYMBOL = Symbol("vitest:SAFE_TIMERS");
|
9
|
-
function getSafeTimers() {
|
10
|
-
const {
|
11
|
-
setTimeout: safeSetTimeout,
|
12
|
-
setInterval: safeSetInterval,
|
13
|
-
clearInterval: safeClearInterval,
|
14
|
-
clearTimeout: safeClearTimeout,
|
15
|
-
setImmediate: safeSetImmediate,
|
16
|
-
clearImmediate: safeClearImmediate
|
17
|
-
} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis;
|
18
|
-
const { nextTick: safeNextTick } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
|
19
|
-
return {
|
20
|
-
nextTick: safeNextTick,
|
21
|
-
setTimeout: safeSetTimeout,
|
22
|
-
setInterval: safeSetInterval,
|
23
|
-
clearInterval: safeClearInterval,
|
24
|
-
clearTimeout: safeClearTimeout,
|
25
|
-
setImmediate: safeSetImmediate,
|
26
|
-
clearImmediate: safeClearImmediate
|
27
|
-
};
|
28
|
-
}
|
29
|
-
function setSafeTimers() {
|
30
|
-
const {
|
31
|
-
setTimeout: safeSetTimeout,
|
32
|
-
setInterval: safeSetInterval,
|
33
|
-
clearInterval: safeClearInterval,
|
34
|
-
clearTimeout: safeClearTimeout,
|
35
|
-
setImmediate: safeSetImmediate,
|
36
|
-
clearImmediate: safeClearImmediate
|
37
|
-
} = globalThis;
|
38
|
-
const { nextTick: safeNextTick } = globalThis.process || {
|
39
|
-
nextTick: (cb) => cb()
|
40
|
-
};
|
41
|
-
const timers = {
|
42
|
-
nextTick: safeNextTick,
|
43
|
-
setTimeout: safeSetTimeout,
|
44
|
-
setInterval: safeSetInterval,
|
45
|
-
clearInterval: safeClearInterval,
|
46
|
-
clearTimeout: safeClearTimeout,
|
47
|
-
setImmediate: safeSetImmediate,
|
48
|
-
clearImmediate: safeClearImmediate
|
49
|
-
};
|
50
|
-
globalThis[SAFE_TIMERS_SYMBOL] = timers;
|
51
|
-
}
|
52
|
-
|
53
|
-
const RealDate = Date;
|
54
|
-
function random(seed) {
|
55
|
-
const x = Math.sin(seed++) * 1e4;
|
56
|
-
return x - Math.floor(x);
|
57
|
-
}
|
58
|
-
function shuffle(array, seed = RealDate.now()) {
|
59
|
-
let length = array.length;
|
60
|
-
while (length) {
|
61
|
-
const index = Math.floor(random(seed) * length--);
|
62
|
-
const previous = array[length];
|
63
|
-
array[length] = array[index];
|
64
|
-
array[index] = previous;
|
65
|
-
++seed;
|
66
|
-
}
|
67
|
-
return array;
|
68
|
-
}
|
69
|
-
|
70
|
-
const lineSplitRE = /\r?\n/;
|
71
|
-
function positionToOffset(source, lineNumber, columnNumber) {
|
72
|
-
const lines = source.split(lineSplitRE);
|
73
|
-
const nl = /\r\n/.test(source) ? 2 : 1;
|
74
|
-
let start = 0;
|
75
|
-
if (lineNumber > lines.length) {
|
76
|
-
return source.length;
|
77
|
-
}
|
78
|
-
for (let i = 0; i < lineNumber - 1; i++) {
|
79
|
-
start += lines[i].length + nl;
|
80
|
-
}
|
81
|
-
return start + columnNumber;
|
82
|
-
}
|
83
|
-
function offsetToLineNumber(source, offset) {
|
84
|
-
if (offset > source.length) {
|
85
|
-
throw new Error(
|
86
|
-
`offset is longer than source length! offset ${offset} > length ${source.length}`
|
87
|
-
);
|
88
|
-
}
|
89
|
-
const lines = source.split(lineSplitRE);
|
90
|
-
const nl = /\r\n/.test(source) ? 2 : 1;
|
91
|
-
let counted = 0;
|
92
|
-
let line = 0;
|
93
|
-
for (; line < lines.length; line++) {
|
94
|
-
const lineLength = lines[line].length + nl;
|
95
|
-
if (counted + lineLength >= offset) {
|
96
|
-
break;
|
97
|
-
}
|
98
|
-
counted += lineLength;
|
99
|
-
}
|
100
|
-
return line + 1;
|
101
|
-
}
|
6
|
+
import 'loupe';
|
102
7
|
|
103
8
|
var jsTokens_1;
|
104
9
|
var hasRequiredJsTokens;
|
@@ -644,4 +549,99 @@ function nanoid(size = 21) {
|
|
644
549
|
return id;
|
645
550
|
}
|
646
551
|
|
552
|
+
const lineSplitRE = /\r?\n/;
|
553
|
+
function positionToOffset(source, lineNumber, columnNumber) {
|
554
|
+
const lines = source.split(lineSplitRE);
|
555
|
+
const nl = /\r\n/.test(source) ? 2 : 1;
|
556
|
+
let start = 0;
|
557
|
+
if (lineNumber > lines.length) {
|
558
|
+
return source.length;
|
559
|
+
}
|
560
|
+
for (let i = 0; i < lineNumber - 1; i++) {
|
561
|
+
start += lines[i].length + nl;
|
562
|
+
}
|
563
|
+
return start + columnNumber;
|
564
|
+
}
|
565
|
+
function offsetToLineNumber(source, offset) {
|
566
|
+
if (offset > source.length) {
|
567
|
+
throw new Error(
|
568
|
+
`offset is longer than source length! offset ${offset} > length ${source.length}`
|
569
|
+
);
|
570
|
+
}
|
571
|
+
const lines = source.split(lineSplitRE);
|
572
|
+
const nl = /\r\n/.test(source) ? 2 : 1;
|
573
|
+
let counted = 0;
|
574
|
+
let line = 0;
|
575
|
+
for (; line < lines.length; line++) {
|
576
|
+
const lineLength = lines[line].length + nl;
|
577
|
+
if (counted + lineLength >= offset) {
|
578
|
+
break;
|
579
|
+
}
|
580
|
+
counted += lineLength;
|
581
|
+
}
|
582
|
+
return line + 1;
|
583
|
+
}
|
584
|
+
|
585
|
+
const RealDate = Date;
|
586
|
+
function random(seed) {
|
587
|
+
const x = Math.sin(seed++) * 1e4;
|
588
|
+
return x - Math.floor(x);
|
589
|
+
}
|
590
|
+
function shuffle(array, seed = RealDate.now()) {
|
591
|
+
let length = array.length;
|
592
|
+
while (length) {
|
593
|
+
const index = Math.floor(random(seed) * length--);
|
594
|
+
const previous = array[length];
|
595
|
+
array[length] = array[index];
|
596
|
+
array[index] = previous;
|
597
|
+
++seed;
|
598
|
+
}
|
599
|
+
return array;
|
600
|
+
}
|
601
|
+
|
602
|
+
const SAFE_TIMERS_SYMBOL = Symbol("vitest:SAFE_TIMERS");
|
603
|
+
function getSafeTimers() {
|
604
|
+
const {
|
605
|
+
setTimeout: safeSetTimeout,
|
606
|
+
setInterval: safeSetInterval,
|
607
|
+
clearInterval: safeClearInterval,
|
608
|
+
clearTimeout: safeClearTimeout,
|
609
|
+
setImmediate: safeSetImmediate,
|
610
|
+
clearImmediate: safeClearImmediate
|
611
|
+
} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis;
|
612
|
+
const { nextTick: safeNextTick } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
|
613
|
+
return {
|
614
|
+
nextTick: safeNextTick,
|
615
|
+
setTimeout: safeSetTimeout,
|
616
|
+
setInterval: safeSetInterval,
|
617
|
+
clearInterval: safeClearInterval,
|
618
|
+
clearTimeout: safeClearTimeout,
|
619
|
+
setImmediate: safeSetImmediate,
|
620
|
+
clearImmediate: safeClearImmediate
|
621
|
+
};
|
622
|
+
}
|
623
|
+
function setSafeTimers() {
|
624
|
+
const {
|
625
|
+
setTimeout: safeSetTimeout,
|
626
|
+
setInterval: safeSetInterval,
|
627
|
+
clearInterval: safeClearInterval,
|
628
|
+
clearTimeout: safeClearTimeout,
|
629
|
+
setImmediate: safeSetImmediate,
|
630
|
+
clearImmediate: safeClearImmediate
|
631
|
+
} = globalThis;
|
632
|
+
const { nextTick: safeNextTick } = globalThis.process || {
|
633
|
+
nextTick: (cb) => cb()
|
634
|
+
};
|
635
|
+
const timers = {
|
636
|
+
nextTick: safeNextTick,
|
637
|
+
setTimeout: safeSetTimeout,
|
638
|
+
setInterval: safeSetInterval,
|
639
|
+
clearInterval: safeClearInterval,
|
640
|
+
clearTimeout: safeClearTimeout,
|
641
|
+
setImmediate: safeSetImmediate,
|
642
|
+
clearImmediate: safeClearImmediate
|
643
|
+
};
|
644
|
+
globalThis[SAFE_TIMERS_SYMBOL] = timers;
|
645
|
+
}
|
646
|
+
|
647
647
|
export { getSafeTimers, highlight, lineSplitRE, nanoid, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle };
|
package/dist/source-map.js
CHANGED
@@ -1,100 +1,5 @@
|
|
1
1
|
import { notNullish, isPrimitive } from './helpers.js';
|
2
2
|
|
3
|
-
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
4
|
-
function normalizeWindowsPath(input = "") {
|
5
|
-
if (!input) {
|
6
|
-
return input;
|
7
|
-
}
|
8
|
-
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
9
|
-
}
|
10
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
11
|
-
function cwd() {
|
12
|
-
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
13
|
-
return process.cwd().replace(/\\/g, "/");
|
14
|
-
}
|
15
|
-
return "/";
|
16
|
-
}
|
17
|
-
const resolve$2 = function(...arguments_) {
|
18
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
19
|
-
let resolvedPath = "";
|
20
|
-
let resolvedAbsolute = false;
|
21
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
22
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
23
|
-
if (!path || path.length === 0) {
|
24
|
-
continue;
|
25
|
-
}
|
26
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
27
|
-
resolvedAbsolute = isAbsolute(path);
|
28
|
-
}
|
29
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
30
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
31
|
-
return `/${resolvedPath}`;
|
32
|
-
}
|
33
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
34
|
-
};
|
35
|
-
function normalizeString(path, allowAboveRoot) {
|
36
|
-
let res = "";
|
37
|
-
let lastSegmentLength = 0;
|
38
|
-
let lastSlash = -1;
|
39
|
-
let dots = 0;
|
40
|
-
let char = null;
|
41
|
-
for (let index = 0; index <= path.length; ++index) {
|
42
|
-
if (index < path.length) {
|
43
|
-
char = path[index];
|
44
|
-
} else if (char === "/") {
|
45
|
-
break;
|
46
|
-
} else {
|
47
|
-
char = "/";
|
48
|
-
}
|
49
|
-
if (char === "/") {
|
50
|
-
if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
|
51
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
52
|
-
if (res.length > 2) {
|
53
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
54
|
-
if (lastSlashIndex === -1) {
|
55
|
-
res = "";
|
56
|
-
lastSegmentLength = 0;
|
57
|
-
} else {
|
58
|
-
res = res.slice(0, lastSlashIndex);
|
59
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
60
|
-
}
|
61
|
-
lastSlash = index;
|
62
|
-
dots = 0;
|
63
|
-
continue;
|
64
|
-
} else if (res.length > 0) {
|
65
|
-
res = "";
|
66
|
-
lastSegmentLength = 0;
|
67
|
-
lastSlash = index;
|
68
|
-
dots = 0;
|
69
|
-
continue;
|
70
|
-
}
|
71
|
-
}
|
72
|
-
if (allowAboveRoot) {
|
73
|
-
res += res.length > 0 ? "/.." : "..";
|
74
|
-
lastSegmentLength = 2;
|
75
|
-
}
|
76
|
-
} else {
|
77
|
-
if (res.length > 0) {
|
78
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
79
|
-
} else {
|
80
|
-
res = path.slice(lastSlash + 1, index);
|
81
|
-
}
|
82
|
-
lastSegmentLength = index - lastSlash - 1;
|
83
|
-
}
|
84
|
-
lastSlash = index;
|
85
|
-
dots = 0;
|
86
|
-
} else if (char === "." && dots !== -1) {
|
87
|
-
++dots;
|
88
|
-
} else {
|
89
|
-
dots = -1;
|
90
|
-
}
|
91
|
-
}
|
92
|
-
return res;
|
93
|
-
}
|
94
|
-
const isAbsolute = function(p) {
|
95
|
-
return _IS_ABSOLUTE_RE.test(p);
|
96
|
-
};
|
97
|
-
|
98
3
|
const comma = ','.charCodeAt(0);
|
99
4
|
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
100
5
|
const intToChar = new Uint8Array(64); // 64 possible chars.
|
@@ -377,7 +282,7 @@ function normalizePath(url, type) {
|
|
377
282
|
/**
|
378
283
|
* Attempts to resolve `input` URL/path relative to `base`.
|
379
284
|
*/
|
380
|
-
function resolve$
|
285
|
+
function resolve$2(input, base) {
|
381
286
|
if (!input && !base)
|
382
287
|
return '';
|
383
288
|
const url = parseUrl(input);
|
@@ -437,13 +342,13 @@ function resolve$1(input, base) {
|
|
437
342
|
}
|
438
343
|
}
|
439
344
|
|
440
|
-
function resolve(input, base) {
|
345
|
+
function resolve$1(input, base) {
|
441
346
|
// The base is always treated as a directory, if it's not empty.
|
442
347
|
// https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
|
443
348
|
// https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
|
444
349
|
if (base && !base.endsWith('/'))
|
445
350
|
base += '/';
|
446
|
-
return resolve$
|
351
|
+
return resolve$2(input, base);
|
447
352
|
}
|
448
353
|
|
449
354
|
/**
|
@@ -643,8 +548,8 @@ class TraceMap {
|
|
643
548
|
this.sources = sources;
|
644
549
|
this.sourcesContent = sourcesContent;
|
645
550
|
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
|
646
|
-
const from = resolve(sourceRoot || '', stripFilename(mapUrl));
|
647
|
-
this.resolvedSources = sources.map((s) => resolve(s || '', from));
|
551
|
+
const from = resolve$1(sourceRoot || '', stripFilename(mapUrl));
|
552
|
+
this.resolvedSources = sources.map((s) => resolve$1(s || '', from));
|
648
553
|
const { mappings } = parsed;
|
649
554
|
if (typeof mappings === 'string') {
|
650
555
|
this._encoded = mappings;
|
@@ -778,6 +683,101 @@ function generatedPosition(map, source, line, column, bias, all) {
|
|
778
683
|
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
779
684
|
}
|
780
685
|
|
686
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
687
|
+
function normalizeWindowsPath(input = "") {
|
688
|
+
if (!input) {
|
689
|
+
return input;
|
690
|
+
}
|
691
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
692
|
+
}
|
693
|
+
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
694
|
+
function cwd() {
|
695
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
696
|
+
return process.cwd().replace(/\\/g, "/");
|
697
|
+
}
|
698
|
+
return "/";
|
699
|
+
}
|
700
|
+
const resolve = function(...arguments_) {
|
701
|
+
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
702
|
+
let resolvedPath = "";
|
703
|
+
let resolvedAbsolute = false;
|
704
|
+
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
705
|
+
const path = index >= 0 ? arguments_[index] : cwd();
|
706
|
+
if (!path || path.length === 0) {
|
707
|
+
continue;
|
708
|
+
}
|
709
|
+
resolvedPath = `${path}/${resolvedPath}`;
|
710
|
+
resolvedAbsolute = isAbsolute(path);
|
711
|
+
}
|
712
|
+
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
713
|
+
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
714
|
+
return `/${resolvedPath}`;
|
715
|
+
}
|
716
|
+
return resolvedPath.length > 0 ? resolvedPath : ".";
|
717
|
+
};
|
718
|
+
function normalizeString(path, allowAboveRoot) {
|
719
|
+
let res = "";
|
720
|
+
let lastSegmentLength = 0;
|
721
|
+
let lastSlash = -1;
|
722
|
+
let dots = 0;
|
723
|
+
let char = null;
|
724
|
+
for (let index = 0; index <= path.length; ++index) {
|
725
|
+
if (index < path.length) {
|
726
|
+
char = path[index];
|
727
|
+
} else if (char === "/") {
|
728
|
+
break;
|
729
|
+
} else {
|
730
|
+
char = "/";
|
731
|
+
}
|
732
|
+
if (char === "/") {
|
733
|
+
if (lastSlash === index - 1 || dots === 1) ; else if (dots === 2) {
|
734
|
+
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
735
|
+
if (res.length > 2) {
|
736
|
+
const lastSlashIndex = res.lastIndexOf("/");
|
737
|
+
if (lastSlashIndex === -1) {
|
738
|
+
res = "";
|
739
|
+
lastSegmentLength = 0;
|
740
|
+
} else {
|
741
|
+
res = res.slice(0, lastSlashIndex);
|
742
|
+
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
743
|
+
}
|
744
|
+
lastSlash = index;
|
745
|
+
dots = 0;
|
746
|
+
continue;
|
747
|
+
} else if (res.length > 0) {
|
748
|
+
res = "";
|
749
|
+
lastSegmentLength = 0;
|
750
|
+
lastSlash = index;
|
751
|
+
dots = 0;
|
752
|
+
continue;
|
753
|
+
}
|
754
|
+
}
|
755
|
+
if (allowAboveRoot) {
|
756
|
+
res += res.length > 0 ? "/.." : "..";
|
757
|
+
lastSegmentLength = 2;
|
758
|
+
}
|
759
|
+
} else {
|
760
|
+
if (res.length > 0) {
|
761
|
+
res += `/${path.slice(lastSlash + 1, index)}`;
|
762
|
+
} else {
|
763
|
+
res = path.slice(lastSlash + 1, index);
|
764
|
+
}
|
765
|
+
lastSegmentLength = index - lastSlash - 1;
|
766
|
+
}
|
767
|
+
lastSlash = index;
|
768
|
+
dots = 0;
|
769
|
+
} else if (char === "." && dots !== -1) {
|
770
|
+
++dots;
|
771
|
+
} else {
|
772
|
+
dots = -1;
|
773
|
+
}
|
774
|
+
}
|
775
|
+
return res;
|
776
|
+
}
|
777
|
+
const isAbsolute = function(p) {
|
778
|
+
return _IS_ABSOLUTE_RE.test(p);
|
779
|
+
};
|
780
|
+
|
781
781
|
const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
|
782
782
|
const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
|
783
783
|
const stackIgnorePatterns = [
|
@@ -886,7 +886,7 @@ function parseSingleV8Stack(raw) {
|
|
886
886
|
if (file.startsWith("file://")) {
|
887
887
|
file = file.slice(7);
|
888
888
|
}
|
889
|
-
file = resolve
|
889
|
+
file = resolve(file);
|
890
890
|
if (method) {
|
891
891
|
method = method.replace(/__vite_ssr_import_\d+__\./g, "");
|
892
892
|
}
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.1.
|
4
|
+
"version": "2.1.4",
|
5
5
|
"description": "Shared Vitest utility functions",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -60,13 +60,13 @@
|
|
60
60
|
"dist"
|
61
61
|
],
|
62
62
|
"dependencies": {
|
63
|
-
"loupe": "^3.1.
|
63
|
+
"loupe": "^3.1.2",
|
64
64
|
"tinyrainbow": "^1.2.0",
|
65
|
-
"@vitest/pretty-format": "2.1.
|
65
|
+
"@vitest/pretty-format": "2.1.4"
|
66
66
|
},
|
67
67
|
"devDependencies": {
|
68
68
|
"@jridgewell/trace-mapping": "^0.3.25",
|
69
|
-
"@types/estree": "^1.0.
|
69
|
+
"@types/estree": "^1.0.6",
|
70
70
|
"diff-sequences": "^29.6.3",
|
71
71
|
"tinyhighlight": "^0.3.2"
|
72
72
|
},
|