vitest 0.34.0 → 0.34.2
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/LICENSE.md +28 -0
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +1 -1
- package/dist/child.js +11 -6
- package/dist/{chunk-api-setup.644415c3.js → chunk-api-setup.cc5282f7.js} +25 -15
- package/dist/{chunk-install-pkg.dd70081b.js → chunk-install-pkg.7e19b3a0.js} +6 -3
- package/dist/{chunk-integrations-globals.877c84db.js → chunk-integrations-globals.522ae1ae.js} +4 -3
- package/dist/cli.js +6 -3
- package/dist/config.d.ts +1 -1
- package/dist/coverage.d.ts +1 -1
- package/dist/entry-vm.js +4 -3
- package/dist/entry.js +4 -3
- package/dist/environments.d.ts +1 -1
- package/dist/environments.js +11 -2
- package/dist/execute.d.ts +139 -0
- package/dist/execute.js +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.js +5 -4
- package/dist/loader.js +9 -528
- package/dist/node.d.ts +2 -2
- package/dist/node.js +6 -3
- package/dist/runners.d.ts +1 -1
- package/dist/runners.js +3 -2
- package/dist/{types-3c7dbfa5.d.ts → types-63abf2e0.d.ts} +63 -2
- package/dist/{vendor-environments.443ecd82.js → vendor-environments.37f266a9.js} +13 -6
- package/dist/{vendor-execute.9ab1c1a7.js → vendor-execute.4fc8203a.js} +409 -206
- package/dist/vendor-index.0b5b3600.js +2062 -0
- package/dist/{vendor-index.eff408fd.js → vendor-index.b5efbd68.js} +1 -1
- package/dist/{vendor-node.00226ab1.js → vendor-node.7b1bd3c5.js} +196 -122
- package/dist/vendor-tasks.f9d75aed.js +14 -0
- package/dist/{vendor-vi.271667ef.js → vendor-vi.f8055ff2.js} +2 -1
- package/dist/vm.js +14 -6
- package/dist/worker.js +12 -6
- package/package.json +7 -7
- package/dist/vendor-source-map.e6c1997b.js +0 -747
|
@@ -1,747 +0,0 @@
|
|
|
1
|
-
import { getNames, getTests } from '@vitest/runner/utils';
|
|
2
|
-
import '@vitest/utils';
|
|
3
|
-
|
|
4
|
-
function hasFailedSnapshot(suite) {
|
|
5
|
-
return getTests(suite).some((s) => {
|
|
6
|
-
var _a, _b;
|
|
7
|
-
return (_b = (_a = s.result) == null ? void 0 : _a.errors) == null ? void 0 : _b.some((e) => typeof (e == null ? void 0 : e.message) === "string" && e.message.match(/Snapshot .* mismatched/));
|
|
8
|
-
});
|
|
9
|
-
}
|
|
10
|
-
function getFullName(task, separator = " > ") {
|
|
11
|
-
return getNames(task).join(separator);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function notNullish(v) {
|
|
15
|
-
return v != null;
|
|
16
|
-
}
|
|
17
|
-
function isPrimitive(value) {
|
|
18
|
-
return value === null || typeof value !== "function" && typeof value !== "object";
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function normalizeWindowsPath(input = "") {
|
|
22
|
-
if (!input || !input.includes("\\")) {
|
|
23
|
-
return input;
|
|
24
|
-
}
|
|
25
|
-
return input.replace(/\\/g, "/");
|
|
26
|
-
}
|
|
27
|
-
const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
|
|
28
|
-
function cwd() {
|
|
29
|
-
if (typeof process !== "undefined") {
|
|
30
|
-
return process.cwd().replace(/\\/g, "/");
|
|
31
|
-
}
|
|
32
|
-
return "/";
|
|
33
|
-
}
|
|
34
|
-
const resolve$2 = function(...arguments_) {
|
|
35
|
-
arguments_ = arguments_.map((argument) => normalizeWindowsPath(argument));
|
|
36
|
-
let resolvedPath = "";
|
|
37
|
-
let resolvedAbsolute = false;
|
|
38
|
-
for (let index = arguments_.length - 1; index >= -1 && !resolvedAbsolute; index--) {
|
|
39
|
-
const path = index >= 0 ? arguments_[index] : cwd();
|
|
40
|
-
if (!path || path.length === 0) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
resolvedPath = `${path}/${resolvedPath}`;
|
|
44
|
-
resolvedAbsolute = isAbsolute(path);
|
|
45
|
-
}
|
|
46
|
-
resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute);
|
|
47
|
-
if (resolvedAbsolute && !isAbsolute(resolvedPath)) {
|
|
48
|
-
return `/${resolvedPath}`;
|
|
49
|
-
}
|
|
50
|
-
return resolvedPath.length > 0 ? resolvedPath : ".";
|
|
51
|
-
};
|
|
52
|
-
function normalizeString(path, allowAboveRoot) {
|
|
53
|
-
let res = "";
|
|
54
|
-
let lastSegmentLength = 0;
|
|
55
|
-
let lastSlash = -1;
|
|
56
|
-
let dots = 0;
|
|
57
|
-
let char = null;
|
|
58
|
-
for (let index = 0; index <= path.length; ++index) {
|
|
59
|
-
if (index < path.length) {
|
|
60
|
-
char = path[index];
|
|
61
|
-
} else if (char === "/") {
|
|
62
|
-
break;
|
|
63
|
-
} else {
|
|
64
|
-
char = "/";
|
|
65
|
-
}
|
|
66
|
-
if (char === "/") {
|
|
67
|
-
if (lastSlash === index - 1 || dots === 1)
|
|
68
|
-
;
|
|
69
|
-
else if (dots === 2) {
|
|
70
|
-
if (res.length < 2 || lastSegmentLength !== 2 || res[res.length - 1] !== "." || res[res.length - 2] !== ".") {
|
|
71
|
-
if (res.length > 2) {
|
|
72
|
-
const lastSlashIndex = res.lastIndexOf("/");
|
|
73
|
-
if (lastSlashIndex === -1) {
|
|
74
|
-
res = "";
|
|
75
|
-
lastSegmentLength = 0;
|
|
76
|
-
} else {
|
|
77
|
-
res = res.slice(0, lastSlashIndex);
|
|
78
|
-
lastSegmentLength = res.length - 1 - res.lastIndexOf("/");
|
|
79
|
-
}
|
|
80
|
-
lastSlash = index;
|
|
81
|
-
dots = 0;
|
|
82
|
-
continue;
|
|
83
|
-
} else if (res.length > 0) {
|
|
84
|
-
res = "";
|
|
85
|
-
lastSegmentLength = 0;
|
|
86
|
-
lastSlash = index;
|
|
87
|
-
dots = 0;
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
if (allowAboveRoot) {
|
|
92
|
-
res += res.length > 0 ? "/.." : "..";
|
|
93
|
-
lastSegmentLength = 2;
|
|
94
|
-
}
|
|
95
|
-
} else {
|
|
96
|
-
if (res.length > 0) {
|
|
97
|
-
res += `/${path.slice(lastSlash + 1, index)}`;
|
|
98
|
-
} else {
|
|
99
|
-
res = path.slice(lastSlash + 1, index);
|
|
100
|
-
}
|
|
101
|
-
lastSegmentLength = index - lastSlash - 1;
|
|
102
|
-
}
|
|
103
|
-
lastSlash = index;
|
|
104
|
-
dots = 0;
|
|
105
|
-
} else if (char === "." && dots !== -1) {
|
|
106
|
-
++dots;
|
|
107
|
-
} else {
|
|
108
|
-
dots = -1;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return res;
|
|
112
|
-
}
|
|
113
|
-
const isAbsolute = function(p) {
|
|
114
|
-
return _IS_ABSOLUTE_RE.test(p);
|
|
115
|
-
};
|
|
116
|
-
const comma = ",".charCodeAt(0);
|
|
117
|
-
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
118
|
-
const intToChar = new Uint8Array(64);
|
|
119
|
-
const charToInt = new Uint8Array(128);
|
|
120
|
-
for (let i = 0; i < chars.length; i++) {
|
|
121
|
-
const c = chars.charCodeAt(i);
|
|
122
|
-
intToChar[i] = c;
|
|
123
|
-
charToInt[c] = i;
|
|
124
|
-
}
|
|
125
|
-
function decode(mappings) {
|
|
126
|
-
const state = new Int32Array(5);
|
|
127
|
-
const decoded = [];
|
|
128
|
-
let index = 0;
|
|
129
|
-
do {
|
|
130
|
-
const semi = indexOf(mappings, index);
|
|
131
|
-
const line = [];
|
|
132
|
-
let sorted = true;
|
|
133
|
-
let lastCol = 0;
|
|
134
|
-
state[0] = 0;
|
|
135
|
-
for (let i = index; i < semi; i++) {
|
|
136
|
-
let seg;
|
|
137
|
-
i = decodeInteger(mappings, i, state, 0);
|
|
138
|
-
const col = state[0];
|
|
139
|
-
if (col < lastCol)
|
|
140
|
-
sorted = false;
|
|
141
|
-
lastCol = col;
|
|
142
|
-
if (hasMoreVlq(mappings, i, semi)) {
|
|
143
|
-
i = decodeInteger(mappings, i, state, 1);
|
|
144
|
-
i = decodeInteger(mappings, i, state, 2);
|
|
145
|
-
i = decodeInteger(mappings, i, state, 3);
|
|
146
|
-
if (hasMoreVlq(mappings, i, semi)) {
|
|
147
|
-
i = decodeInteger(mappings, i, state, 4);
|
|
148
|
-
seg = [col, state[1], state[2], state[3], state[4]];
|
|
149
|
-
} else {
|
|
150
|
-
seg = [col, state[1], state[2], state[3]];
|
|
151
|
-
}
|
|
152
|
-
} else {
|
|
153
|
-
seg = [col];
|
|
154
|
-
}
|
|
155
|
-
line.push(seg);
|
|
156
|
-
}
|
|
157
|
-
if (!sorted)
|
|
158
|
-
sort(line);
|
|
159
|
-
decoded.push(line);
|
|
160
|
-
index = semi + 1;
|
|
161
|
-
} while (index <= mappings.length);
|
|
162
|
-
return decoded;
|
|
163
|
-
}
|
|
164
|
-
function indexOf(mappings, index) {
|
|
165
|
-
const idx = mappings.indexOf(";", index);
|
|
166
|
-
return idx === -1 ? mappings.length : idx;
|
|
167
|
-
}
|
|
168
|
-
function decodeInteger(mappings, pos, state, j) {
|
|
169
|
-
let value = 0;
|
|
170
|
-
let shift = 0;
|
|
171
|
-
let integer = 0;
|
|
172
|
-
do {
|
|
173
|
-
const c = mappings.charCodeAt(pos++);
|
|
174
|
-
integer = charToInt[c];
|
|
175
|
-
value |= (integer & 31) << shift;
|
|
176
|
-
shift += 5;
|
|
177
|
-
} while (integer & 32);
|
|
178
|
-
const shouldNegate = value & 1;
|
|
179
|
-
value >>>= 1;
|
|
180
|
-
if (shouldNegate) {
|
|
181
|
-
value = -2147483648 | -value;
|
|
182
|
-
}
|
|
183
|
-
state[j] += value;
|
|
184
|
-
return pos;
|
|
185
|
-
}
|
|
186
|
-
function hasMoreVlq(mappings, i, length) {
|
|
187
|
-
if (i >= length)
|
|
188
|
-
return false;
|
|
189
|
-
return mappings.charCodeAt(i) !== comma;
|
|
190
|
-
}
|
|
191
|
-
function sort(line) {
|
|
192
|
-
line.sort(sortComparator$1);
|
|
193
|
-
}
|
|
194
|
-
function sortComparator$1(a, b) {
|
|
195
|
-
return a[0] - b[0];
|
|
196
|
-
}
|
|
197
|
-
const schemeRegex = /^[\w+.-]+:\/\//;
|
|
198
|
-
const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
|
|
199
|
-
const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
|
|
200
|
-
var UrlType;
|
|
201
|
-
(function(UrlType2) {
|
|
202
|
-
UrlType2[UrlType2["Empty"] = 1] = "Empty";
|
|
203
|
-
UrlType2[UrlType2["Hash"] = 2] = "Hash";
|
|
204
|
-
UrlType2[UrlType2["Query"] = 3] = "Query";
|
|
205
|
-
UrlType2[UrlType2["RelativePath"] = 4] = "RelativePath";
|
|
206
|
-
UrlType2[UrlType2["AbsolutePath"] = 5] = "AbsolutePath";
|
|
207
|
-
UrlType2[UrlType2["SchemeRelative"] = 6] = "SchemeRelative";
|
|
208
|
-
UrlType2[UrlType2["Absolute"] = 7] = "Absolute";
|
|
209
|
-
})(UrlType || (UrlType = {}));
|
|
210
|
-
function isAbsoluteUrl(input) {
|
|
211
|
-
return schemeRegex.test(input);
|
|
212
|
-
}
|
|
213
|
-
function isSchemeRelativeUrl(input) {
|
|
214
|
-
return input.startsWith("//");
|
|
215
|
-
}
|
|
216
|
-
function isAbsolutePath(input) {
|
|
217
|
-
return input.startsWith("/");
|
|
218
|
-
}
|
|
219
|
-
function isFileUrl(input) {
|
|
220
|
-
return input.startsWith("file:");
|
|
221
|
-
}
|
|
222
|
-
function isRelative(input) {
|
|
223
|
-
return /^[.?#]/.test(input);
|
|
224
|
-
}
|
|
225
|
-
function parseAbsoluteUrl(input) {
|
|
226
|
-
const match = urlRegex.exec(input);
|
|
227
|
-
return makeUrl(match[1], match[2] || "", match[3], match[4] || "", match[5] || "/", match[6] || "", match[7] || "");
|
|
228
|
-
}
|
|
229
|
-
function parseFileUrl(input) {
|
|
230
|
-
const match = fileRegex.exec(input);
|
|
231
|
-
const path = match[2];
|
|
232
|
-
return makeUrl("file:", "", match[1] || "", "", isAbsolutePath(path) ? path : "/" + path, match[3] || "", match[4] || "");
|
|
233
|
-
}
|
|
234
|
-
function makeUrl(scheme, user, host, port, path, query, hash) {
|
|
235
|
-
return {
|
|
236
|
-
scheme,
|
|
237
|
-
user,
|
|
238
|
-
host,
|
|
239
|
-
port,
|
|
240
|
-
path,
|
|
241
|
-
query,
|
|
242
|
-
hash,
|
|
243
|
-
type: UrlType.Absolute
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
function parseUrl(input) {
|
|
247
|
-
if (isSchemeRelativeUrl(input)) {
|
|
248
|
-
const url2 = parseAbsoluteUrl("http:" + input);
|
|
249
|
-
url2.scheme = "";
|
|
250
|
-
url2.type = UrlType.SchemeRelative;
|
|
251
|
-
return url2;
|
|
252
|
-
}
|
|
253
|
-
if (isAbsolutePath(input)) {
|
|
254
|
-
const url2 = parseAbsoluteUrl("http://foo.com" + input);
|
|
255
|
-
url2.scheme = "";
|
|
256
|
-
url2.host = "";
|
|
257
|
-
url2.type = UrlType.AbsolutePath;
|
|
258
|
-
return url2;
|
|
259
|
-
}
|
|
260
|
-
if (isFileUrl(input))
|
|
261
|
-
return parseFileUrl(input);
|
|
262
|
-
if (isAbsoluteUrl(input))
|
|
263
|
-
return parseAbsoluteUrl(input);
|
|
264
|
-
const url = parseAbsoluteUrl("http://foo.com/" + input);
|
|
265
|
-
url.scheme = "";
|
|
266
|
-
url.host = "";
|
|
267
|
-
url.type = input ? input.startsWith("?") ? UrlType.Query : input.startsWith("#") ? UrlType.Hash : UrlType.RelativePath : UrlType.Empty;
|
|
268
|
-
return url;
|
|
269
|
-
}
|
|
270
|
-
function stripPathFilename(path) {
|
|
271
|
-
if (path.endsWith("/.."))
|
|
272
|
-
return path;
|
|
273
|
-
const index = path.lastIndexOf("/");
|
|
274
|
-
return path.slice(0, index + 1);
|
|
275
|
-
}
|
|
276
|
-
function mergePaths(url, base) {
|
|
277
|
-
normalizePath(base, base.type);
|
|
278
|
-
if (url.path === "/") {
|
|
279
|
-
url.path = base.path;
|
|
280
|
-
} else {
|
|
281
|
-
url.path = stripPathFilename(base.path) + url.path;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
function normalizePath(url, type) {
|
|
285
|
-
const rel = type <= UrlType.RelativePath;
|
|
286
|
-
const pieces = url.path.split("/");
|
|
287
|
-
let pointer = 1;
|
|
288
|
-
let positive = 0;
|
|
289
|
-
let addTrailingSlash = false;
|
|
290
|
-
for (let i = 1; i < pieces.length; i++) {
|
|
291
|
-
const piece = pieces[i];
|
|
292
|
-
if (!piece) {
|
|
293
|
-
addTrailingSlash = true;
|
|
294
|
-
continue;
|
|
295
|
-
}
|
|
296
|
-
addTrailingSlash = false;
|
|
297
|
-
if (piece === ".")
|
|
298
|
-
continue;
|
|
299
|
-
if (piece === "..") {
|
|
300
|
-
if (positive) {
|
|
301
|
-
addTrailingSlash = true;
|
|
302
|
-
positive--;
|
|
303
|
-
pointer--;
|
|
304
|
-
} else if (rel) {
|
|
305
|
-
pieces[pointer++] = piece;
|
|
306
|
-
}
|
|
307
|
-
continue;
|
|
308
|
-
}
|
|
309
|
-
pieces[pointer++] = piece;
|
|
310
|
-
positive++;
|
|
311
|
-
}
|
|
312
|
-
let path = "";
|
|
313
|
-
for (let i = 1; i < pointer; i++) {
|
|
314
|
-
path += "/" + pieces[i];
|
|
315
|
-
}
|
|
316
|
-
if (!path || addTrailingSlash && !path.endsWith("/..")) {
|
|
317
|
-
path += "/";
|
|
318
|
-
}
|
|
319
|
-
url.path = path;
|
|
320
|
-
}
|
|
321
|
-
function resolve$1(input, base) {
|
|
322
|
-
if (!input && !base)
|
|
323
|
-
return "";
|
|
324
|
-
const url = parseUrl(input);
|
|
325
|
-
let inputType = url.type;
|
|
326
|
-
if (base && inputType !== UrlType.Absolute) {
|
|
327
|
-
const baseUrl = parseUrl(base);
|
|
328
|
-
const baseType = baseUrl.type;
|
|
329
|
-
switch (inputType) {
|
|
330
|
-
case UrlType.Empty:
|
|
331
|
-
url.hash = baseUrl.hash;
|
|
332
|
-
case UrlType.Hash:
|
|
333
|
-
url.query = baseUrl.query;
|
|
334
|
-
case UrlType.Query:
|
|
335
|
-
case UrlType.RelativePath:
|
|
336
|
-
mergePaths(url, baseUrl);
|
|
337
|
-
case UrlType.AbsolutePath:
|
|
338
|
-
url.user = baseUrl.user;
|
|
339
|
-
url.host = baseUrl.host;
|
|
340
|
-
url.port = baseUrl.port;
|
|
341
|
-
case UrlType.SchemeRelative:
|
|
342
|
-
url.scheme = baseUrl.scheme;
|
|
343
|
-
}
|
|
344
|
-
if (baseType > inputType)
|
|
345
|
-
inputType = baseType;
|
|
346
|
-
}
|
|
347
|
-
normalizePath(url, inputType);
|
|
348
|
-
const queryHash = url.query + url.hash;
|
|
349
|
-
switch (inputType) {
|
|
350
|
-
case UrlType.Hash:
|
|
351
|
-
case UrlType.Query:
|
|
352
|
-
return queryHash;
|
|
353
|
-
case UrlType.RelativePath: {
|
|
354
|
-
const path = url.path.slice(1);
|
|
355
|
-
if (!path)
|
|
356
|
-
return queryHash || ".";
|
|
357
|
-
if (isRelative(base || input) && !isRelative(path)) {
|
|
358
|
-
return "./" + path + queryHash;
|
|
359
|
-
}
|
|
360
|
-
return path + queryHash;
|
|
361
|
-
}
|
|
362
|
-
case UrlType.AbsolutePath:
|
|
363
|
-
return url.path + queryHash;
|
|
364
|
-
default:
|
|
365
|
-
return url.scheme + "//" + url.user + url.host + url.port + url.path + queryHash;
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
function resolve(input, base) {
|
|
369
|
-
if (base && !base.endsWith("/"))
|
|
370
|
-
base += "/";
|
|
371
|
-
return resolve$1(input, base);
|
|
372
|
-
}
|
|
373
|
-
function stripFilename(path) {
|
|
374
|
-
if (!path)
|
|
375
|
-
return "";
|
|
376
|
-
const index = path.lastIndexOf("/");
|
|
377
|
-
return path.slice(0, index + 1);
|
|
378
|
-
}
|
|
379
|
-
const COLUMN = 0;
|
|
380
|
-
const SOURCES_INDEX = 1;
|
|
381
|
-
const SOURCE_LINE = 2;
|
|
382
|
-
const SOURCE_COLUMN = 3;
|
|
383
|
-
const NAMES_INDEX = 4;
|
|
384
|
-
const REV_GENERATED_LINE = 1;
|
|
385
|
-
const REV_GENERATED_COLUMN = 2;
|
|
386
|
-
function maybeSort(mappings, owned) {
|
|
387
|
-
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
388
|
-
if (unsortedIndex === mappings.length)
|
|
389
|
-
return mappings;
|
|
390
|
-
if (!owned)
|
|
391
|
-
mappings = mappings.slice();
|
|
392
|
-
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
393
|
-
mappings[i] = sortSegments(mappings[i], owned);
|
|
394
|
-
}
|
|
395
|
-
return mappings;
|
|
396
|
-
}
|
|
397
|
-
function nextUnsortedSegmentLine(mappings, start) {
|
|
398
|
-
for (let i = start; i < mappings.length; i++) {
|
|
399
|
-
if (!isSorted(mappings[i]))
|
|
400
|
-
return i;
|
|
401
|
-
}
|
|
402
|
-
return mappings.length;
|
|
403
|
-
}
|
|
404
|
-
function isSorted(line) {
|
|
405
|
-
for (let j = 1; j < line.length; j++) {
|
|
406
|
-
if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
|
407
|
-
return false;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
return true;
|
|
411
|
-
}
|
|
412
|
-
function sortSegments(line, owned) {
|
|
413
|
-
if (!owned)
|
|
414
|
-
line = line.slice();
|
|
415
|
-
return line.sort(sortComparator);
|
|
416
|
-
}
|
|
417
|
-
function sortComparator(a, b) {
|
|
418
|
-
return a[COLUMN] - b[COLUMN];
|
|
419
|
-
}
|
|
420
|
-
let found = false;
|
|
421
|
-
function binarySearch(haystack, needle, low, high) {
|
|
422
|
-
while (low <= high) {
|
|
423
|
-
const mid = low + (high - low >> 1);
|
|
424
|
-
const cmp = haystack[mid][COLUMN] - needle;
|
|
425
|
-
if (cmp === 0) {
|
|
426
|
-
found = true;
|
|
427
|
-
return mid;
|
|
428
|
-
}
|
|
429
|
-
if (cmp < 0) {
|
|
430
|
-
low = mid + 1;
|
|
431
|
-
} else {
|
|
432
|
-
high = mid - 1;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
found = false;
|
|
436
|
-
return low - 1;
|
|
437
|
-
}
|
|
438
|
-
function upperBound(haystack, needle, index) {
|
|
439
|
-
for (let i = index + 1; i < haystack.length; index = i++) {
|
|
440
|
-
if (haystack[i][COLUMN] !== needle)
|
|
441
|
-
break;
|
|
442
|
-
}
|
|
443
|
-
return index;
|
|
444
|
-
}
|
|
445
|
-
function lowerBound(haystack, needle, index) {
|
|
446
|
-
for (let i = index - 1; i >= 0; index = i--) {
|
|
447
|
-
if (haystack[i][COLUMN] !== needle)
|
|
448
|
-
break;
|
|
449
|
-
}
|
|
450
|
-
return index;
|
|
451
|
-
}
|
|
452
|
-
function memoizedState() {
|
|
453
|
-
return {
|
|
454
|
-
lastKey: -1,
|
|
455
|
-
lastNeedle: -1,
|
|
456
|
-
lastIndex: -1
|
|
457
|
-
};
|
|
458
|
-
}
|
|
459
|
-
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
460
|
-
const { lastKey, lastNeedle, lastIndex } = state;
|
|
461
|
-
let low = 0;
|
|
462
|
-
let high = haystack.length - 1;
|
|
463
|
-
if (key === lastKey) {
|
|
464
|
-
if (needle === lastNeedle) {
|
|
465
|
-
found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
|
|
466
|
-
return lastIndex;
|
|
467
|
-
}
|
|
468
|
-
if (needle >= lastNeedle) {
|
|
469
|
-
low = lastIndex === -1 ? 0 : lastIndex;
|
|
470
|
-
} else {
|
|
471
|
-
high = lastIndex;
|
|
472
|
-
}
|
|
473
|
-
}
|
|
474
|
-
state.lastKey = key;
|
|
475
|
-
state.lastNeedle = needle;
|
|
476
|
-
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
477
|
-
}
|
|
478
|
-
function buildBySources(decoded, memos) {
|
|
479
|
-
const sources = memos.map(buildNullArray);
|
|
480
|
-
for (let i = 0; i < decoded.length; i++) {
|
|
481
|
-
const line = decoded[i];
|
|
482
|
-
for (let j = 0; j < line.length; j++) {
|
|
483
|
-
const seg = line[j];
|
|
484
|
-
if (seg.length === 1)
|
|
485
|
-
continue;
|
|
486
|
-
const sourceIndex = seg[SOURCES_INDEX];
|
|
487
|
-
const sourceLine = seg[SOURCE_LINE];
|
|
488
|
-
const sourceColumn = seg[SOURCE_COLUMN];
|
|
489
|
-
const originalSource = sources[sourceIndex];
|
|
490
|
-
const originalLine = originalSource[sourceLine] || (originalSource[sourceLine] = []);
|
|
491
|
-
const memo = memos[sourceIndex];
|
|
492
|
-
const index = upperBound(originalLine, sourceColumn, memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine));
|
|
493
|
-
insert(originalLine, memo.lastIndex = index + 1, [sourceColumn, i, seg[COLUMN]]);
|
|
494
|
-
}
|
|
495
|
-
}
|
|
496
|
-
return sources;
|
|
497
|
-
}
|
|
498
|
-
function insert(array, index, value) {
|
|
499
|
-
for (let i = array.length; i > index; i--) {
|
|
500
|
-
array[i] = array[i - 1];
|
|
501
|
-
}
|
|
502
|
-
array[index] = value;
|
|
503
|
-
}
|
|
504
|
-
function buildNullArray() {
|
|
505
|
-
return { __proto__: null };
|
|
506
|
-
}
|
|
507
|
-
const LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
508
|
-
const COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
509
|
-
const LEAST_UPPER_BOUND = -1;
|
|
510
|
-
const GREATEST_LOWER_BOUND = 1;
|
|
511
|
-
let decodedMappings;
|
|
512
|
-
let originalPositionFor;
|
|
513
|
-
let generatedPositionFor;
|
|
514
|
-
class TraceMap {
|
|
515
|
-
constructor(map, mapUrl) {
|
|
516
|
-
const isString = typeof map === "string";
|
|
517
|
-
if (!isString && map._decodedMemo)
|
|
518
|
-
return map;
|
|
519
|
-
const parsed = isString ? JSON.parse(map) : map;
|
|
520
|
-
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
521
|
-
this.version = version;
|
|
522
|
-
this.file = file;
|
|
523
|
-
this.names = names;
|
|
524
|
-
this.sourceRoot = sourceRoot;
|
|
525
|
-
this.sources = sources;
|
|
526
|
-
this.sourcesContent = sourcesContent;
|
|
527
|
-
const from = resolve(sourceRoot || "", stripFilename(mapUrl));
|
|
528
|
-
this.resolvedSources = sources.map((s) => resolve(s || "", from));
|
|
529
|
-
const { mappings } = parsed;
|
|
530
|
-
if (typeof mappings === "string") {
|
|
531
|
-
this._encoded = mappings;
|
|
532
|
-
this._decoded = void 0;
|
|
533
|
-
} else {
|
|
534
|
-
this._encoded = void 0;
|
|
535
|
-
this._decoded = maybeSort(mappings, isString);
|
|
536
|
-
}
|
|
537
|
-
this._decodedMemo = memoizedState();
|
|
538
|
-
this._bySources = void 0;
|
|
539
|
-
this._bySourceMemos = void 0;
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
(() => {
|
|
543
|
-
decodedMappings = (map) => {
|
|
544
|
-
return map._decoded || (map._decoded = decode(map._encoded));
|
|
545
|
-
};
|
|
546
|
-
originalPositionFor = (map, { line, column, bias }) => {
|
|
547
|
-
line--;
|
|
548
|
-
if (line < 0)
|
|
549
|
-
throw new Error(LINE_GTR_ZERO);
|
|
550
|
-
if (column < 0)
|
|
551
|
-
throw new Error(COL_GTR_EQ_ZERO);
|
|
552
|
-
const decoded = decodedMappings(map);
|
|
553
|
-
if (line >= decoded.length)
|
|
554
|
-
return OMapping(null, null, null, null);
|
|
555
|
-
const segments = decoded[line];
|
|
556
|
-
const index = traceSegmentInternal(segments, map._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
|
|
557
|
-
if (index === -1)
|
|
558
|
-
return OMapping(null, null, null, null);
|
|
559
|
-
const segment = segments[index];
|
|
560
|
-
if (segment.length === 1)
|
|
561
|
-
return OMapping(null, null, null, null);
|
|
562
|
-
const { names, resolvedSources } = map;
|
|
563
|
-
return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
|
|
564
|
-
};
|
|
565
|
-
generatedPositionFor = (map, { source, line, column, bias }) => {
|
|
566
|
-
return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
|
|
567
|
-
};
|
|
568
|
-
function generatedPosition(map, source, line, column, bias, all) {
|
|
569
|
-
line--;
|
|
570
|
-
if (line < 0)
|
|
571
|
-
throw new Error(LINE_GTR_ZERO);
|
|
572
|
-
if (column < 0)
|
|
573
|
-
throw new Error(COL_GTR_EQ_ZERO);
|
|
574
|
-
const { sources, resolvedSources } = map;
|
|
575
|
-
let sourceIndex = sources.indexOf(source);
|
|
576
|
-
if (sourceIndex === -1)
|
|
577
|
-
sourceIndex = resolvedSources.indexOf(source);
|
|
578
|
-
if (sourceIndex === -1)
|
|
579
|
-
return all ? [] : GMapping(null, null);
|
|
580
|
-
const generated = map._bySources || (map._bySources = buildBySources(decodedMappings(map), map._bySourceMemos = sources.map(memoizedState)));
|
|
581
|
-
const segments = generated[sourceIndex][line];
|
|
582
|
-
if (segments == null)
|
|
583
|
-
return all ? [] : GMapping(null, null);
|
|
584
|
-
const memo = map._bySourceMemos[sourceIndex];
|
|
585
|
-
if (all)
|
|
586
|
-
return sliceGeneratedPositions(segments, memo, line, column, bias);
|
|
587
|
-
const index = traceSegmentInternal(segments, memo, line, column, bias);
|
|
588
|
-
if (index === -1)
|
|
589
|
-
return GMapping(null, null);
|
|
590
|
-
const segment = segments[index];
|
|
591
|
-
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
|
592
|
-
}
|
|
593
|
-
})();
|
|
594
|
-
function OMapping(source, line, column, name) {
|
|
595
|
-
return { source, line, column, name };
|
|
596
|
-
}
|
|
597
|
-
function GMapping(line, column) {
|
|
598
|
-
return { line, column };
|
|
599
|
-
}
|
|
600
|
-
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
601
|
-
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
602
|
-
if (found) {
|
|
603
|
-
index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
|
|
604
|
-
} else if (bias === LEAST_UPPER_BOUND)
|
|
605
|
-
index++;
|
|
606
|
-
if (index === -1 || index === segments.length)
|
|
607
|
-
return -1;
|
|
608
|
-
return index;
|
|
609
|
-
}
|
|
610
|
-
function sliceGeneratedPositions(segments, memo, line, column, bias) {
|
|
611
|
-
let min = traceSegmentInternal(segments, memo, line, column, GREATEST_LOWER_BOUND);
|
|
612
|
-
if (!found && bias === LEAST_UPPER_BOUND)
|
|
613
|
-
min++;
|
|
614
|
-
if (min === -1 || min === segments.length)
|
|
615
|
-
return [];
|
|
616
|
-
const matchedColumn = found ? column : segments[min][COLUMN];
|
|
617
|
-
if (!found)
|
|
618
|
-
min = lowerBound(segments, matchedColumn, min);
|
|
619
|
-
const max = upperBound(segments, matchedColumn, min);
|
|
620
|
-
const result = [];
|
|
621
|
-
for (; min <= max; min++) {
|
|
622
|
-
const segment = segments[min];
|
|
623
|
-
result.push(GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]));
|
|
624
|
-
}
|
|
625
|
-
return result;
|
|
626
|
-
}
|
|
627
|
-
const CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+:\d+|\(native\))/m;
|
|
628
|
-
const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code])?$/;
|
|
629
|
-
const stackIgnorePatterns = [
|
|
630
|
-
"node:internal",
|
|
631
|
-
/\/packages\/\w+\/dist\//,
|
|
632
|
-
/\/@vitest\/\w+\/dist\//,
|
|
633
|
-
"/vitest/dist/",
|
|
634
|
-
"/vitest/src/",
|
|
635
|
-
"/vite-node/dist/",
|
|
636
|
-
"/vite-node/src/",
|
|
637
|
-
"/node_modules/chai/",
|
|
638
|
-
"/node_modules/tinypool/",
|
|
639
|
-
"/node_modules/tinyspy/",
|
|
640
|
-
"/deps/chai.js",
|
|
641
|
-
/__vitest_browser__/
|
|
642
|
-
];
|
|
643
|
-
function extractLocation(urlLike) {
|
|
644
|
-
if (!urlLike.includes(":"))
|
|
645
|
-
return [urlLike];
|
|
646
|
-
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
|
647
|
-
const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
|
|
648
|
-
if (!parts)
|
|
649
|
-
return [urlLike];
|
|
650
|
-
let url = parts[1];
|
|
651
|
-
if (url.startsWith("http:") || url.startsWith("https:")) {
|
|
652
|
-
const urlObj = new URL(url);
|
|
653
|
-
url = urlObj.pathname;
|
|
654
|
-
}
|
|
655
|
-
if (url.startsWith("/@fs/")) {
|
|
656
|
-
url = url.slice(typeof process !== "undefined" && process.platform === "win32" ? 5 : 4);
|
|
657
|
-
}
|
|
658
|
-
return [url, parts[2] || void 0, parts[3] || void 0];
|
|
659
|
-
}
|
|
660
|
-
function parseSingleFFOrSafariStack(raw) {
|
|
661
|
-
let line = raw.trim();
|
|
662
|
-
if (SAFARI_NATIVE_CODE_REGEXP.test(line))
|
|
663
|
-
return null;
|
|
664
|
-
if (line.includes(" > eval"))
|
|
665
|
-
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
|
|
666
|
-
if (!line.includes("@") && !line.includes(":"))
|
|
667
|
-
return null;
|
|
668
|
-
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(?:@)/;
|
|
669
|
-
const matches = line.match(functionNameRegex);
|
|
670
|
-
const functionName = matches && matches[1] ? matches[1] : void 0;
|
|
671
|
-
const [url, lineNumber, columnNumber] = extractLocation(line.replace(functionNameRegex, ""));
|
|
672
|
-
if (!url || !lineNumber || !columnNumber)
|
|
673
|
-
return null;
|
|
674
|
-
return {
|
|
675
|
-
file: url,
|
|
676
|
-
method: functionName || "",
|
|
677
|
-
line: Number.parseInt(lineNumber),
|
|
678
|
-
column: Number.parseInt(columnNumber)
|
|
679
|
-
};
|
|
680
|
-
}
|
|
681
|
-
function parseSingleStack(raw) {
|
|
682
|
-
const line = raw.trim();
|
|
683
|
-
if (!CHROME_IE_STACK_REGEXP.test(line))
|
|
684
|
-
return parseSingleFFOrSafariStack(line);
|
|
685
|
-
return parseSingleV8Stack(line);
|
|
686
|
-
}
|
|
687
|
-
function parseSingleV8Stack(raw) {
|
|
688
|
-
let line = raw.trim();
|
|
689
|
-
if (!CHROME_IE_STACK_REGEXP.test(line))
|
|
690
|
-
return null;
|
|
691
|
-
if (line.includes("(eval "))
|
|
692
|
-
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
|
693
|
-
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
|
694
|
-
const location = sanitizedLine.match(/ (\(.+\)$)/);
|
|
695
|
-
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
|
696
|
-
const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
|
|
697
|
-
let method = location && sanitizedLine || "";
|
|
698
|
-
let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
|
|
699
|
-
if (!file || !lineNumber || !columnNumber)
|
|
700
|
-
return null;
|
|
701
|
-
if (method.startsWith("async "))
|
|
702
|
-
method = method.slice(6);
|
|
703
|
-
if (file.startsWith("file://"))
|
|
704
|
-
file = file.slice(7);
|
|
705
|
-
file = resolve$2(file);
|
|
706
|
-
return {
|
|
707
|
-
method,
|
|
708
|
-
file,
|
|
709
|
-
line: Number.parseInt(lineNumber),
|
|
710
|
-
column: Number.parseInt(columnNumber)
|
|
711
|
-
};
|
|
712
|
-
}
|
|
713
|
-
function parseStacktrace(stack, options = {}) {
|
|
714
|
-
const { ignoreStackEntries = stackIgnorePatterns } = options;
|
|
715
|
-
let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
|
|
716
|
-
if (ignoreStackEntries.length)
|
|
717
|
-
stacks = stacks.filter((stack2) => !ignoreStackEntries.some((p) => stack2.file.match(p)));
|
|
718
|
-
return stacks.map((stack2) => {
|
|
719
|
-
var _a;
|
|
720
|
-
const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
|
|
721
|
-
if (!map || typeof map !== "object" || !map.version)
|
|
722
|
-
return stack2;
|
|
723
|
-
const traceMap = new TraceMap(map);
|
|
724
|
-
const { line, column } = originalPositionFor(traceMap, stack2);
|
|
725
|
-
if (line != null && column != null)
|
|
726
|
-
return { ...stack2, line, column };
|
|
727
|
-
return stack2;
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
function parseFFOrSafariStackTrace(stack) {
|
|
731
|
-
return stack.split("\n").map((line) => parseSingleFFOrSafariStack(line)).filter(notNullish);
|
|
732
|
-
}
|
|
733
|
-
function parseV8Stacktrace(stack) {
|
|
734
|
-
return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
|
|
735
|
-
}
|
|
736
|
-
function parseErrorStacktrace(e, options = {}) {
|
|
737
|
-
if (!e || isPrimitive(e))
|
|
738
|
-
return [];
|
|
739
|
-
if (e.stacks)
|
|
740
|
-
return e.stacks;
|
|
741
|
-
const stackStr = e.stack || e.stackStr || "";
|
|
742
|
-
const stackFrames = parseStacktrace(stackStr, options);
|
|
743
|
-
e.stacks = stackFrames;
|
|
744
|
-
return stackFrames;
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
export { TraceMap as T, parseSingleStack as a, generatedPositionFor as b, getFullName as g, hasFailedSnapshot as h, parseErrorStacktrace as p };
|