@vitest/utils 1.6.0 → 2.0.0-beta.10
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/ast.js +16 -8
- package/dist/chunk-colors.js +8 -4
- package/dist/chunk-display.js +5 -4
- package/dist/diff.d.ts +2 -2
- package/dist/diff.js +3 -2
- package/dist/error.d.ts +2 -2
- package/dist/error.js +8 -3
- package/dist/helpers.d.ts +2 -1
- package/dist/helpers.js +11 -3
- package/dist/index.d.ts +15 -15
- package/dist/index.js +2 -2
- package/dist/source-map.d.ts +20 -16
- package/dist/source-map.js +96 -78
- package/package.json +6 -3
- /package/dist/{types-9l4niLY8.d.ts → types-DyShQl4f.d.ts} +0 -0
package/dist/ast.js
CHANGED
@@ -55,8 +55,9 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
55
55
|
enter(node, parent) {
|
56
56
|
if (node.type === "ImportDeclaration")
|
57
57
|
return this.skip();
|
58
|
-
if (parent && !(parent.type === "IfStatement" && node === parent.alternate))
|
58
|
+
if (parent && !(parent.type === "IfStatement" && node === parent.alternate)) {
|
59
59
|
parentStack.unshift(parent);
|
60
|
+
}
|
60
61
|
if (node.type === "VariableDeclaration")
|
61
62
|
varKindStack.unshift(node.kind);
|
62
63
|
if (node.type === "CallExpression")
|
@@ -82,14 +83,16 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
82
83
|
}
|
83
84
|
walk(p.type === "AssignmentPattern" ? p.left : p, {
|
84
85
|
enter(child, parent2) {
|
85
|
-
if ((parent2 == null ? void 0 : parent2.type) === "AssignmentPattern" && (parent2 == null ? void 0 : parent2.right) === child)
|
86
|
+
if ((parent2 == null ? void 0 : parent2.type) === "AssignmentPattern" && (parent2 == null ? void 0 : parent2.right) === child) {
|
86
87
|
return this.skip();
|
88
|
+
}
|
87
89
|
if (child.type !== "Identifier")
|
88
90
|
return;
|
89
91
|
if (isStaticPropertyKey(child, parent2))
|
90
92
|
return;
|
91
|
-
if ((parent2 == null ? void 0 : parent2.type) === "TemplateLiteral" && (parent2 == null ? void 0 : parent2.expressions.includes(child)) || (parent2 == null ? void 0 : parent2.type) === "CallExpression" && (parent2 == null ? void 0 : parent2.callee) === child)
|
93
|
+
if ((parent2 == null ? void 0 : parent2.type) === "TemplateLiteral" && (parent2 == null ? void 0 : parent2.expressions.includes(child)) || (parent2 == null ? void 0 : parent2.type) === "CallExpression" && (parent2 == null ? void 0 : parent2.callee) === child) {
|
92
94
|
return;
|
95
|
+
}
|
93
96
|
setScope(node, child.name);
|
94
97
|
}
|
95
98
|
});
|
@@ -108,8 +111,9 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
108
111
|
}
|
109
112
|
},
|
110
113
|
leave(node, parent) {
|
111
|
-
if (parent && !(parent.type === "IfStatement" && node === parent.alternate))
|
114
|
+
if (parent && !(parent.type === "IfStatement" && node === parent.alternate)) {
|
112
115
|
parentStack.shift();
|
116
|
+
}
|
113
117
|
if (node.type === "VariableDeclaration")
|
114
118
|
varKindStack.shift();
|
115
119
|
}
|
@@ -130,8 +134,9 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
130
134
|
});
|
131
135
|
}
|
132
136
|
function isRefIdentifier(id, parent, parentStack) {
|
133
|
-
if (parent.type === "CatchClause" || (parent.type === "VariableDeclarator" || parent.type === "ClassDeclaration") && parent.id === id)
|
137
|
+
if (parent.type === "CatchClause" || (parent.type === "VariableDeclarator" || parent.type === "ClassDeclaration") && parent.id === id) {
|
134
138
|
return false;
|
139
|
+
}
|
135
140
|
if (isFunctionNode(parent)) {
|
136
141
|
if (parent.id === id)
|
137
142
|
return false;
|
@@ -144,10 +149,12 @@ function isRefIdentifier(id, parent, parentStack) {
|
|
144
149
|
return false;
|
145
150
|
if (isNodeInPattern(parent) && parent.value === id)
|
146
151
|
return false;
|
147
|
-
if (parent.type === "ArrayPattern" && !isInDestructuringAssignment(parent, parentStack))
|
152
|
+
if (parent.type === "ArrayPattern" && !isInDestructuringAssignment(parent, parentStack)) {
|
148
153
|
return false;
|
149
|
-
|
154
|
+
}
|
155
|
+
if (parent.type === "MemberExpression" && parent.property === id && !parent.computed) {
|
150
156
|
return false;
|
157
|
+
}
|
151
158
|
if (parent.type === "ExportSpecifier")
|
152
159
|
return false;
|
153
160
|
if (id.name === "arguments")
|
@@ -172,8 +179,9 @@ function findParentScope(parentStack, isVar = false) {
|
|
172
179
|
return parentStack.find(isVar ? isFunctionNode : isBlock);
|
173
180
|
}
|
174
181
|
function isInDestructuringAssignment(parent, parentStack) {
|
175
|
-
if (parent && (parent.type === "Property" || parent.type === "ArrayPattern"))
|
182
|
+
if (parent && (parent.type === "Property" || parent.type === "ArrayPattern")) {
|
176
183
|
return parentStack.some((i) => i.type === "AssignmentExpression");
|
184
|
+
}
|
177
185
|
return false;
|
178
186
|
}
|
179
187
|
|
package/dist/chunk-colors.js
CHANGED
@@ -46,10 +46,14 @@ function getColors() {
|
|
46
46
|
function createColors(isTTY = false) {
|
47
47
|
const enabled = typeof process !== "undefined" && !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && !("GITHUB_ACTIONS" in process.env) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || isTTY && process.env.TERM !== "dumb" || "CI" in process.env);
|
48
48
|
const replaceClose = (string2, close, replace, index) => {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
let result = "";
|
50
|
+
let cursor = 0;
|
51
|
+
do {
|
52
|
+
result += string2.substring(cursor, index) + replace;
|
53
|
+
cursor = index + close.length;
|
54
|
+
index = string2.indexOf(close, cursor);
|
55
|
+
} while (~index);
|
56
|
+
return result + string2.substring(cursor);
|
53
57
|
};
|
54
58
|
const formatter = (open, close, replace = open) => {
|
55
59
|
const fn = (input) => {
|
package/dist/chunk-display.js
CHANGED
@@ -41,12 +41,12 @@ function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
|
|
41
41
|
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(maxDepth / 2)) : result;
|
42
42
|
}
|
43
43
|
|
44
|
-
const formatRegExp = /%[
|
44
|
+
const formatRegExp = /%[sdjifoOc%]/g;
|
45
45
|
function format(...args) {
|
46
46
|
if (typeof args[0] !== "string") {
|
47
47
|
const objects = [];
|
48
48
|
for (let i2 = 0; i2 < args.length; i2++)
|
49
|
-
objects.push(inspect(args[i2], { depth: 0, colors: false
|
49
|
+
objects.push(inspect(args[i2], { depth: 0, colors: false }));
|
50
50
|
return objects.join(" ");
|
51
51
|
}
|
52
52
|
const len = args.length;
|
@@ -65,7 +65,7 @@ function format(...args) {
|
|
65
65
|
if (typeof value === "number" && value === 0 && 1 / value < 0)
|
66
66
|
return "-0";
|
67
67
|
if (typeof value === "object" && value !== null)
|
68
|
-
return inspect(value, { depth: 0, colors: false
|
68
|
+
return inspect(value, { depth: 0, colors: false });
|
69
69
|
return String(value);
|
70
70
|
}
|
71
71
|
case "%d": {
|
@@ -98,8 +98,9 @@ function format(...args) {
|
|
98
98
|
if (
|
99
99
|
// chromium
|
100
100
|
m.includes("circular structure") || m.includes("cyclic structures") || m.includes("cyclic object")
|
101
|
-
)
|
101
|
+
) {
|
102
102
|
return "[Circular]";
|
103
|
+
}
|
103
104
|
throw err;
|
104
105
|
}
|
105
106
|
default:
|
package/dist/diff.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { D as DiffOptions } from './types-
|
2
|
-
export { a as DiffOptionsColor } from './types-
|
1
|
+
import { D as DiffOptions } from './types-DyShQl4f.js';
|
2
|
+
export { a as DiffOptionsColor } from './types-DyShQl4f.js';
|
3
3
|
import 'pretty-format';
|
4
4
|
|
5
5
|
/**
|
package/dist/diff.js
CHANGED
@@ -67,8 +67,9 @@ const diff_commonPrefix = function(text1, text2) {
|
|
67
67
|
return pointermid;
|
68
68
|
};
|
69
69
|
const diff_commonSuffix = function(text1, text2) {
|
70
|
-
if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1))
|
70
|
+
if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) {
|
71
71
|
return 0;
|
72
|
+
}
|
72
73
|
let pointermin = 0;
|
73
74
|
let pointermax = Math.min(text1.length, text2.length);
|
74
75
|
let pointermid = pointermax;
|
@@ -181,7 +182,7 @@ const diff_cleanupSemantic = function(diffs) {
|
|
181
182
|
pointer++;
|
182
183
|
}
|
183
184
|
};
|
184
|
-
const nonAlphaNumericRegex_ = /[^a-
|
185
|
+
const nonAlphaNumericRegex_ = /[^a-z0-9]/i;
|
185
186
|
const whitespaceRegex_ = /\s/;
|
186
187
|
const linebreakRegex_ = /[\r\n]/;
|
187
188
|
const blanklineEndRegex_ = /\n\r?\n$/;
|
package/dist/error.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
import { D as DiffOptions } from './types-
|
1
|
+
import { D as DiffOptions } from './types-DyShQl4f.js';
|
2
2
|
import 'pretty-format';
|
3
3
|
|
4
4
|
declare function serializeError(val: any, seen?: WeakMap<WeakKey, any>): any;
|
5
|
-
declare function processError(err: any, diffOptions?: DiffOptions): any;
|
5
|
+
declare function processError(err: any, diffOptions?: DiffOptions, seen?: WeakSet<WeakKey>): any;
|
6
6
|
declare function replaceAsymmetricMatcher(actual: any, expected: any, actualReplaced?: WeakSet<WeakKey>, expectedReplaced?: WeakSet<WeakKey>): {
|
7
7
|
replacedActual: any;
|
8
8
|
replacedExpected: any;
|
package/dist/error.js
CHANGED
@@ -74,7 +74,7 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
|
74
74
|
function normalizeErrorMessage(message) {
|
75
75
|
return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "");
|
76
76
|
}
|
77
|
-
function processError(err, diffOptions) {
|
77
|
+
function processError(err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
|
78
78
|
if (!err || typeof err !== "object")
|
79
79
|
return { message: err };
|
80
80
|
if (err.stack)
|
@@ -94,8 +94,13 @@ function processError(err, diffOptions) {
|
|
94
94
|
try {
|
95
95
|
if (typeof err.message === "string")
|
96
96
|
err.message = normalizeErrorMessage(err.message);
|
97
|
-
|
98
|
-
|
97
|
+
} catch {
|
98
|
+
}
|
99
|
+
try {
|
100
|
+
if (!seen.has(err) && typeof err.cause === "object") {
|
101
|
+
seen.add(err);
|
102
|
+
err.cause = processError(err.cause, diffOptions, seen);
|
103
|
+
}
|
99
104
|
} catch {
|
100
105
|
}
|
101
106
|
try {
|
package/dist/helpers.d.ts
CHANGED
@@ -31,5 +31,6 @@ declare function createDefer<T>(): DeferPromise<T>;
|
|
31
31
|
* ```
|
32
32
|
*/
|
33
33
|
declare function getCallLastIndex(code: string): number | null;
|
34
|
+
declare function isNegativeNaN(val: number): boolean;
|
34
35
|
|
35
|
-
export { type DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
36
|
+
export { type DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
package/dist/helpers.js
CHANGED
@@ -61,8 +61,7 @@ function clone(val, seen, options = defaultCloneOptions) {
|
|
61
61
|
if (Array.isArray(val)) {
|
62
62
|
out = Array(k = val.length);
|
63
63
|
seen.set(val, out);
|
64
|
-
while (k--)
|
65
|
-
out[k] = clone(val[k], seen, options);
|
64
|
+
while (k--) out[k] = clone(val[k], seen, options);
|
66
65
|
return out;
|
67
66
|
}
|
68
67
|
if (Object.prototype.toString.call(val) === "[object Object]") {
|
@@ -150,5 +149,14 @@ function getCallLastIndex(code) {
|
|
150
149
|
}
|
151
150
|
return null;
|
152
151
|
}
|
152
|
+
function isNegativeNaN(val) {
|
153
|
+
if (!Number.isNaN(val))
|
154
|
+
return false;
|
155
|
+
const f64 = new Float64Array(1);
|
156
|
+
f64[0] = val;
|
157
|
+
const u32 = new Uint32Array(f64.buffer);
|
158
|
+
const isNegative = u32[1] >>> 31 === 1;
|
159
|
+
return isNegative;
|
160
|
+
}
|
153
161
|
|
154
|
-
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
162
|
+
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export { DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
1
|
+
export { DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
2
|
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack } from './types.js';
|
3
3
|
import { PrettyFormatOptions } from 'pretty-format';
|
4
4
|
|
@@ -19,21 +19,21 @@ declare function setSafeTimers(): void;
|
|
19
19
|
|
20
20
|
declare function shuffle<T>(array: T[], seed?: number): T[];
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
breakLength
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
truncate?: number;
|
22
|
+
type Inspect = (value: unknown, options: Options) => string;
|
23
|
+
interface Options {
|
24
|
+
showHidden: boolean;
|
25
|
+
depth: number;
|
26
|
+
colors: boolean;
|
27
|
+
customInspect: boolean;
|
28
|
+
showProxy: boolean;
|
29
|
+
maxArrayLength: number;
|
30
|
+
breakLength: number;
|
31
|
+
truncate: number;
|
32
|
+
seen: unknown[];
|
33
|
+
inspect: Inspect;
|
34
|
+
stylize: (value: string, styleType: string) => string;
|
36
35
|
}
|
36
|
+
type LoupeOptions = Partial<Options>;
|
37
37
|
declare function format(...args: unknown[]): string;
|
38
38
|
declare function inspect(obj: unknown, options?: LoupeOptions): string;
|
39
39
|
declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
|
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
1
|
+
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
2
|
export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-display.js';
|
3
3
|
import { S as SAFE_TIMERS_SYMBOL, g as getColors } from './chunk-colors.js';
|
4
4
|
export { a as SAFE_COLORS_SYMBOL, c as createColors, b as getDefaultColors, s as setupColors } from './chunk-colors.js';
|
@@ -69,7 +69,7 @@ function shuffle(array, seed = RealDate.now()) {
|
|
69
69
|
}
|
70
70
|
|
71
71
|
function createSimpleStackTrace(options) {
|
72
|
-
const { message = "error", stackTraceLimit = 1 } = options || {};
|
72
|
+
const { message = "$$stack trace error", stackTraceLimit = 1 } = options || {};
|
73
73
|
const limit = Error.stackTraceLimit;
|
74
74
|
const prepareStackTrace = Error.prepareStackTrace;
|
75
75
|
Error.stackTraceLimit = stackTraceLimit;
|
package/dist/source-map.d.ts
CHANGED
@@ -14,6 +14,7 @@ interface SourceMapV3 {
|
|
14
14
|
sources: (string | null)[];
|
15
15
|
sourcesContent?: (string | null)[];
|
16
16
|
version: 3;
|
17
|
+
ignoreList?: number[];
|
17
18
|
}
|
18
19
|
interface EncodedSourceMap extends SourceMapV3 {
|
19
20
|
mappings: string;
|
@@ -42,7 +43,12 @@ type InvalidGeneratedMapping = {
|
|
42
43
|
column: null;
|
43
44
|
};
|
44
45
|
type Bias = typeof GREATEST_LOWER_BOUND | typeof LEAST_UPPER_BOUND;
|
45
|
-
type
|
46
|
+
type XInput = {
|
47
|
+
x_google_ignoreList?: SourceMapV3['ignoreList'];
|
48
|
+
};
|
49
|
+
type EncodedSourceMapXInput = EncodedSourceMap & XInput;
|
50
|
+
type DecodedSourceMapXInput = DecodedSourceMap & XInput;
|
51
|
+
type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
|
46
52
|
type Needle = {
|
47
53
|
line: number;
|
48
54
|
column: number;
|
@@ -62,25 +68,12 @@ declare abstract class SourceMap {
|
|
62
68
|
sources: SourceMapV3['sources'];
|
63
69
|
sourcesContent: SourceMapV3['sourcesContent'];
|
64
70
|
resolvedSources: SourceMapV3['sources'];
|
71
|
+
ignoreList: SourceMapV3['ignoreList'];
|
65
72
|
}
|
66
|
-
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;
|
67
|
-
type RoArray<T> = Ro<T>[];
|
68
|
-
type RoObject<T> = {
|
69
|
-
[K in keyof T]: T[K] | Ro<T[K]>;
|
70
|
-
};
|
71
73
|
|
72
74
|
declare const LEAST_UPPER_BOUND = -1;
|
73
75
|
declare const GREATEST_LOWER_BOUND = 1;
|
74
|
-
|
75
|
-
* A higher-level API to find the source/line/column associated with a generated line/column
|
76
|
-
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
77
|
-
* `source-map` library.
|
78
|
-
*/
|
79
|
-
declare let originalPositionFor: (map: TraceMap, needle: Needle) => OriginalMapping | InvalidOriginalMapping;
|
80
|
-
/**
|
81
|
-
* Finds the generated line/column position of the provided source/line/column source position.
|
82
|
-
*/
|
83
|
-
declare let generatedPositionFor: (map: TraceMap, needle: SourceNeedle) => GeneratedMapping | InvalidGeneratedMapping;
|
76
|
+
|
84
77
|
declare class TraceMap implements SourceMap {
|
85
78
|
version: SourceMapV3['version'];
|
86
79
|
file: SourceMapV3['file'];
|
@@ -88,6 +81,7 @@ declare class TraceMap implements SourceMap {
|
|
88
81
|
sourceRoot: SourceMapV3['sourceRoot'];
|
89
82
|
sources: SourceMapV3['sources'];
|
90
83
|
sourcesContent: SourceMapV3['sourcesContent'];
|
84
|
+
ignoreList: SourceMapV3['ignoreList'];
|
91
85
|
resolvedSources: string[];
|
92
86
|
private _encoded;
|
93
87
|
private _decoded;
|
@@ -96,6 +90,16 @@ declare class TraceMap implements SourceMap {
|
|
96
90
|
private _bySourceMemos;
|
97
91
|
constructor(map: SourceMapInput, mapUrl?: string | null);
|
98
92
|
}
|
93
|
+
/**
|
94
|
+
* A higher-level API to find the source/line/column associated with a generated line/column
|
95
|
+
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
96
|
+
* `source-map` library.
|
97
|
+
*/
|
98
|
+
declare function originalPositionFor(map: TraceMap, needle: Needle): OriginalMapping | InvalidOriginalMapping;
|
99
|
+
/**
|
100
|
+
* Finds the generated line/column position of the provided source/line/column source position.
|
101
|
+
*/
|
102
|
+
declare function generatedPositionFor(map: TraceMap, needle: SourceNeedle): GeneratedMapping | InvalidGeneratedMapping;
|
99
103
|
|
100
104
|
interface StackTraceParserOptions {
|
101
105
|
ignoreStackEntries?: (RegExp | string)[];
|
package/dist/source-map.js
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
import { notNullish, isPrimitive } from './helpers.js';
|
2
2
|
|
3
|
+
const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
|
3
4
|
function normalizeWindowsPath(input = "") {
|
4
|
-
if (!input
|
5
|
+
if (!input) {
|
5
6
|
return input;
|
6
7
|
}
|
7
|
-
return input.replace(/\\/g, "/");
|
8
|
+
return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
|
8
9
|
}
|
9
10
|
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
10
11
|
function cwd() {
|
11
|
-
if (typeof process !== "undefined") {
|
12
|
+
if (typeof process !== "undefined" && typeof process.cwd === "function") {
|
12
13
|
return process.cwd().replace(/\\/g, "/");
|
13
14
|
}
|
14
15
|
return "/";
|
@@ -584,8 +585,9 @@ function buildBySources(decoded, memos) {
|
|
584
585
|
// segment should go. Either way, we want to insert after that. And there may be multiple
|
585
586
|
// generated segments associated with an original location, so there may need to move several
|
586
587
|
// indexes before we find where we need to insert.
|
587
|
-
|
588
|
-
|
588
|
+
let index = upperBound(originalLine, sourceColumn, memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine));
|
589
|
+
memo.lastIndex = ++index;
|
590
|
+
insert(originalLine, index, [sourceColumn, i, seg[COLUMN]]);
|
589
591
|
}
|
590
592
|
}
|
591
593
|
return sources;
|
@@ -609,20 +611,6 @@ const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
|
|
609
611
|
const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
|
610
612
|
const LEAST_UPPER_BOUND = -1;
|
611
613
|
const GREATEST_LOWER_BOUND = 1;
|
612
|
-
/**
|
613
|
-
* Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
|
614
|
-
*/
|
615
|
-
let decodedMappings;
|
616
|
-
/**
|
617
|
-
* A higher-level API to find the source/line/column associated with a generated line/column
|
618
|
-
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
619
|
-
* `source-map` library.
|
620
|
-
*/
|
621
|
-
let originalPositionFor;
|
622
|
-
/**
|
623
|
-
* Finds the generated line/column position of the provided source/line/column source position.
|
624
|
-
*/
|
625
|
-
let generatedPositionFor;
|
626
614
|
class TraceMap {
|
627
615
|
constructor(map, mapUrl) {
|
628
616
|
const isString = typeof map === 'string';
|
@@ -636,6 +624,7 @@ class TraceMap {
|
|
636
624
|
this.sourceRoot = sourceRoot;
|
637
625
|
this.sources = sources;
|
638
626
|
this.sourcesContent = sourcesContent;
|
627
|
+
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
|
639
628
|
const from = resolve(sourceRoot || '', stripFilename(mapUrl));
|
640
629
|
this.resolvedSources = sources.map((s) => resolve(s || '', from));
|
641
630
|
const { mappings } = parsed;
|
@@ -652,60 +641,54 @@ class TraceMap {
|
|
652
641
|
this._bySourceMemos = undefined;
|
653
642
|
}
|
654
643
|
}
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
if (index === -1)
|
704
|
-
return GMapping(null, null);
|
705
|
-
const segment = segments[index];
|
706
|
-
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
707
|
-
}
|
708
|
-
})();
|
644
|
+
/**
|
645
|
+
* Typescript doesn't allow friend access to private fields, so this just casts the map into a type
|
646
|
+
* with public access modifiers.
|
647
|
+
*/
|
648
|
+
function cast(map) {
|
649
|
+
return map;
|
650
|
+
}
|
651
|
+
/**
|
652
|
+
* Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
|
653
|
+
*/
|
654
|
+
function decodedMappings(map) {
|
655
|
+
var _a;
|
656
|
+
return ((_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded)));
|
657
|
+
}
|
658
|
+
/**
|
659
|
+
* A higher-level API to find the source/line/column associated with a generated line/column
|
660
|
+
* (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
|
661
|
+
* `source-map` library.
|
662
|
+
*/
|
663
|
+
function originalPositionFor(map, needle) {
|
664
|
+
let { line, column, bias } = needle;
|
665
|
+
line--;
|
666
|
+
if (line < 0)
|
667
|
+
throw new Error(LINE_GTR_ZERO);
|
668
|
+
if (column < 0)
|
669
|
+
throw new Error(COL_GTR_EQ_ZERO);
|
670
|
+
const decoded = decodedMappings(map);
|
671
|
+
// It's common for parent source maps to have pointers to lines that have no
|
672
|
+
// mapping (like a "//# sourceMappingURL=") at the end of the child file.
|
673
|
+
if (line >= decoded.length)
|
674
|
+
return OMapping(null, null, null, null);
|
675
|
+
const segments = decoded[line];
|
676
|
+
const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
|
677
|
+
if (index === -1)
|
678
|
+
return OMapping(null, null, null, null);
|
679
|
+
const segment = segments[index];
|
680
|
+
if (segment.length === 1)
|
681
|
+
return OMapping(null, null, null, null);
|
682
|
+
const { names, resolvedSources } = map;
|
683
|
+
return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
|
684
|
+
}
|
685
|
+
/**
|
686
|
+
* Finds the generated line/column position of the provided source/line/column source position.
|
687
|
+
*/
|
688
|
+
function generatedPositionFor(map, needle) {
|
689
|
+
const { source, line, column, bias } = needle;
|
690
|
+
return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
|
691
|
+
}
|
709
692
|
function OMapping(source, line, column, name) {
|
710
693
|
return { source, line, column, name };
|
711
694
|
}
|
@@ -750,9 +733,35 @@ function sliceGeneratedPositions(segments, memo, line, column, bias) {
|
|
750
733
|
}
|
751
734
|
return result;
|
752
735
|
}
|
736
|
+
function generatedPosition(map, source, line, column, bias, all) {
|
737
|
+
var _a;
|
738
|
+
line--;
|
739
|
+
if (line < 0)
|
740
|
+
throw new Error(LINE_GTR_ZERO);
|
741
|
+
if (column < 0)
|
742
|
+
throw new Error(COL_GTR_EQ_ZERO);
|
743
|
+
const { sources, resolvedSources } = map;
|
744
|
+
let sourceIndex = sources.indexOf(source);
|
745
|
+
if (sourceIndex === -1)
|
746
|
+
sourceIndex = resolvedSources.indexOf(source);
|
747
|
+
if (sourceIndex === -1)
|
748
|
+
return all ? [] : GMapping(null, null);
|
749
|
+
const generated = ((_a = cast(map))._bySources || (_a._bySources = buildBySources(decodedMappings(map), (cast(map)._bySourceMemos = sources.map(memoizedState)))));
|
750
|
+
const segments = generated[sourceIndex][line];
|
751
|
+
if (segments == null)
|
752
|
+
return all ? [] : GMapping(null, null);
|
753
|
+
const memo = cast(map)._bySourceMemos[sourceIndex];
|
754
|
+
if (all)
|
755
|
+
return sliceGeneratedPositions(segments, memo, line, column, bias);
|
756
|
+
const index = traceSegmentInternal(segments, memo, line, column, bias);
|
757
|
+
if (index === -1)
|
758
|
+
return GMapping(null, null);
|
759
|
+
const segment = segments[index];
|
760
|
+
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
761
|
+
}
|
753
762
|
|
754
|
-
const CHROME_IE_STACK_REGEXP = /^\s*at .*(
|
755
|
-
const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(
|
763
|
+
const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
|
764
|
+
const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
|
756
765
|
const stackIgnorePatterns = [
|
757
766
|
"node:internal",
|
758
767
|
/\/packages\/\w+\/dist\//,
|
@@ -764,8 +773,14 @@ const stackIgnorePatterns = [
|
|
764
773
|
"/node_modules/chai/",
|
765
774
|
"/node_modules/tinypool/",
|
766
775
|
"/node_modules/tinyspy/",
|
776
|
+
// browser related deps
|
767
777
|
"/deps/chai.js",
|
768
|
-
/
|
778
|
+
"/deps/vitest___chai.js",
|
779
|
+
"/deps/p-limit.js",
|
780
|
+
/node:\w+/,
|
781
|
+
/__vitest_test__/,
|
782
|
+
/__vitest_browser__/,
|
783
|
+
/\/deps\/vitest_/
|
769
784
|
];
|
770
785
|
function extractLocation(urlLike) {
|
771
786
|
if (!urlLike.includes(":"))
|
@@ -775,12 +790,15 @@ function extractLocation(urlLike) {
|
|
775
790
|
if (!parts)
|
776
791
|
return [urlLike];
|
777
792
|
let url = parts[1];
|
793
|
+
if (url.startsWith("async "))
|
794
|
+
url = url.slice(6);
|
778
795
|
if (url.startsWith("http:") || url.startsWith("https:")) {
|
779
796
|
const urlObj = new URL(url);
|
780
797
|
url = urlObj.pathname;
|
781
798
|
}
|
782
799
|
if (url.startsWith("/@fs/")) {
|
783
|
-
|
800
|
+
const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
|
801
|
+
url = url.slice(isWindows ? 5 : 4);
|
784
802
|
}
|
785
803
|
return [url, parts[2] || void 0, parts[3] || void 0];
|
786
804
|
}
|
@@ -792,7 +810,7 @@ function parseSingleFFOrSafariStack(raw) {
|
|
792
810
|
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
|
793
811
|
if (!line.includes("@") && !line.includes(":"))
|
794
812
|
return null;
|
795
|
-
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(
|
813
|
+
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
|
796
814
|
const matches = line.match(functionNameRegex);
|
797
815
|
const functionName = matches && matches[1] ? matches[1] : void 0;
|
798
816
|
const [url, lineNumber, columnNumber] = extractLocation(line.replace(functionNameRegex, ""));
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "
|
4
|
+
"version": "2.0.0-beta.10",
|
5
5
|
"description": "Shared Vitest utility functions",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -47,6 +47,9 @@
|
|
47
47
|
"types": "./dist/index.d.ts",
|
48
48
|
"typesVersions": {
|
49
49
|
"*": {
|
50
|
+
"ast": [
|
51
|
+
"dist/ast.d.ts"
|
52
|
+
],
|
50
53
|
"source-map": [
|
51
54
|
"dist/source-map.d.ts"
|
52
55
|
]
|
@@ -59,11 +62,11 @@
|
|
59
62
|
"dependencies": {
|
60
63
|
"diff-sequences": "^29.6.3",
|
61
64
|
"estree-walker": "^3.0.3",
|
62
|
-
"loupe": "^
|
65
|
+
"loupe": "^3.1.1",
|
63
66
|
"pretty-format": "^29.7.0"
|
64
67
|
},
|
65
68
|
"devDependencies": {
|
66
|
-
"@jridgewell/trace-mapping": "^0.3.
|
69
|
+
"@jridgewell/trace-mapping": "^0.3.25",
|
67
70
|
"@types/estree": "^1.0.5",
|
68
71
|
"tinyhighlight": "^0.3.2"
|
69
72
|
},
|
File without changes
|