@vitest/utils 4.0.0-beta.10 → 4.0.0-beta.12
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 -154
- package/dist/constants.d.ts +21 -0
- package/dist/constants.js +49 -0
- package/dist/diff.js +5 -4
- package/dist/display.d.ts +28 -0
- package/dist/display.js +727 -0
- package/dist/error.d.ts +2 -3
- package/dist/error.js +6 -126
- package/dist/helpers.d.ts +6 -2
- package/dist/helpers.js +295 -1
- package/dist/highlight.d.ts +9 -0
- package/dist/highlight.js +538 -0
- package/dist/index.d.ts +4 -79
- package/dist/index.js +0 -632
- package/dist/offset.d.ts +5 -0
- package/dist/offset.js +32 -0
- package/dist/serialize.d.ts +3 -0
- package/dist/serialize.js +118 -0
- package/dist/source-map.d.ts +31 -120
- package/dist/source-map.js +160 -535
- package/dist/timers.d.ts +18 -0
- package/dist/timers.js +32 -0
- package/package.json +30 -6
- package/dist/chunk-helpers.js +0 -329
package/dist/source-map.js
CHANGED
|
@@ -1,404 +1,114 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { r as resolve
|
|
1
|
+
import { isPrimitive, notNullish } from './helpers.js';
|
|
2
|
+
import { r as resolve } from './chunk-pathe.M-eThtNZ.js';
|
|
3
|
+
import './constants.js';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
// src/vlq.ts
|
|
6
|
+
var comma = ",".charCodeAt(0);
|
|
7
|
+
var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
8
|
+
var intToChar = new Uint8Array(64);
|
|
9
|
+
var charToInt = new Uint8Array(128);
|
|
8
10
|
for (let i = 0; i < chars.length; i++) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
const c = chars.charCodeAt(i);
|
|
12
|
+
intToChar[i] = c;
|
|
13
|
+
charToInt[c] = i;
|
|
12
14
|
}
|
|
13
15
|
function decodeInteger(reader, relative) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
16
|
+
let value = 0;
|
|
17
|
+
let shift = 0;
|
|
18
|
+
let integer = 0;
|
|
19
|
+
do {
|
|
20
|
+
const c = reader.next();
|
|
21
|
+
integer = charToInt[c];
|
|
22
|
+
value |= (integer & 31) << shift;
|
|
23
|
+
shift += 5;
|
|
24
|
+
} while (integer & 32);
|
|
25
|
+
const shouldNegate = value & 1;
|
|
26
|
+
value >>>= 1;
|
|
27
|
+
if (shouldNegate) {
|
|
28
|
+
value = -2147483648 | -value;
|
|
29
|
+
}
|
|
30
|
+
return relative + value;
|
|
29
31
|
}
|
|
30
32
|
function hasMoreVlq(reader, max) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return reader.peek() !== comma;
|
|
34
|
-
}
|
|
35
|
-
class StringReader {
|
|
36
|
-
constructor(buffer) {
|
|
37
|
-
this.pos = 0;
|
|
38
|
-
this.buffer = buffer;
|
|
39
|
-
}
|
|
40
|
-
next() {
|
|
41
|
-
return this.buffer.charCodeAt(this.pos++);
|
|
42
|
-
}
|
|
43
|
-
peek() {
|
|
44
|
-
return this.buffer.charCodeAt(this.pos);
|
|
45
|
-
}
|
|
46
|
-
indexOf(char) {
|
|
47
|
-
const { buffer, pos } = this;
|
|
48
|
-
const idx = buffer.indexOf(char, pos);
|
|
49
|
-
return idx === -1 ? buffer.length : idx;
|
|
50
|
-
}
|
|
33
|
+
if (reader.pos >= max) return false;
|
|
34
|
+
return reader.peek() !== comma;
|
|
51
35
|
}
|
|
36
|
+
var StringReader = class {
|
|
37
|
+
constructor(buffer) {
|
|
38
|
+
this.pos = 0;
|
|
39
|
+
this.buffer = buffer;
|
|
40
|
+
}
|
|
41
|
+
next() {
|
|
42
|
+
return this.buffer.charCodeAt(this.pos++);
|
|
43
|
+
}
|
|
44
|
+
peek() {
|
|
45
|
+
return this.buffer.charCodeAt(this.pos);
|
|
46
|
+
}
|
|
47
|
+
indexOf(char) {
|
|
48
|
+
const { buffer, pos } = this;
|
|
49
|
+
const idx = buffer.indexOf(char, pos);
|
|
50
|
+
return idx === -1 ? buffer.length : idx;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
52
53
|
|
|
54
|
+
// src/sourcemap-codec.ts
|
|
53
55
|
function decode(mappings) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
else {
|
|
83
|
-
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
seg = [genColumn];
|
|
88
|
-
}
|
|
89
|
-
line.push(seg);
|
|
90
|
-
reader.pos++;
|
|
56
|
+
const { length } = mappings;
|
|
57
|
+
const reader = new StringReader(mappings);
|
|
58
|
+
const decoded = [];
|
|
59
|
+
let genColumn = 0;
|
|
60
|
+
let sourcesIndex = 0;
|
|
61
|
+
let sourceLine = 0;
|
|
62
|
+
let sourceColumn = 0;
|
|
63
|
+
let namesIndex = 0;
|
|
64
|
+
do {
|
|
65
|
+
const semi = reader.indexOf(";");
|
|
66
|
+
const line = [];
|
|
67
|
+
let sorted = true;
|
|
68
|
+
let lastCol = 0;
|
|
69
|
+
genColumn = 0;
|
|
70
|
+
while (reader.pos < semi) {
|
|
71
|
+
let seg;
|
|
72
|
+
genColumn = decodeInteger(reader, genColumn);
|
|
73
|
+
if (genColumn < lastCol) sorted = false;
|
|
74
|
+
lastCol = genColumn;
|
|
75
|
+
if (hasMoreVlq(reader, semi)) {
|
|
76
|
+
sourcesIndex = decodeInteger(reader, sourcesIndex);
|
|
77
|
+
sourceLine = decodeInteger(reader, sourceLine);
|
|
78
|
+
sourceColumn = decodeInteger(reader, sourceColumn);
|
|
79
|
+
if (hasMoreVlq(reader, semi)) {
|
|
80
|
+
namesIndex = decodeInteger(reader, namesIndex);
|
|
81
|
+
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
|
|
82
|
+
} else {
|
|
83
|
+
seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
|
|
91
84
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return decoded;
|
|
98
|
-
}
|
|
99
|
-
function sort(line) {
|
|
100
|
-
line.sort(sortComparator$1);
|
|
101
|
-
}
|
|
102
|
-
function sortComparator$1(a, b) {
|
|
103
|
-
return a[0] - b[0];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Matches the scheme of a URL, eg "http://"
|
|
107
|
-
const schemeRegex = /^[\w+.-]+:\/\//;
|
|
108
|
-
/**
|
|
109
|
-
* Matches the parts of a URL:
|
|
110
|
-
* 1. Scheme, including ":", guaranteed.
|
|
111
|
-
* 2. User/password, including "@", optional.
|
|
112
|
-
* 3. Host, guaranteed.
|
|
113
|
-
* 4. Port, including ":", optional.
|
|
114
|
-
* 5. Path, including "/", optional.
|
|
115
|
-
* 6. Query, including "?", optional.
|
|
116
|
-
* 7. Hash, including "#", optional.
|
|
117
|
-
*/
|
|
118
|
-
const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
|
|
119
|
-
/**
|
|
120
|
-
* File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
|
|
121
|
-
* with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
|
|
122
|
-
*
|
|
123
|
-
* 1. Host, optional.
|
|
124
|
-
* 2. Path, which may include "/", guaranteed.
|
|
125
|
-
* 3. Query, including "?", optional.
|
|
126
|
-
* 4. Hash, including "#", optional.
|
|
127
|
-
*/
|
|
128
|
-
const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
|
|
129
|
-
var UrlType;
|
|
130
|
-
(function (UrlType) {
|
|
131
|
-
UrlType[UrlType["Empty"] = 1] = "Empty";
|
|
132
|
-
UrlType[UrlType["Hash"] = 2] = "Hash";
|
|
133
|
-
UrlType[UrlType["Query"] = 3] = "Query";
|
|
134
|
-
UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
|
|
135
|
-
UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
|
|
136
|
-
UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
|
|
137
|
-
UrlType[UrlType["Absolute"] = 7] = "Absolute";
|
|
138
|
-
})(UrlType || (UrlType = {}));
|
|
139
|
-
function isAbsoluteUrl(input) {
|
|
140
|
-
return schemeRegex.test(input);
|
|
141
|
-
}
|
|
142
|
-
function isSchemeRelativeUrl(input) {
|
|
143
|
-
return input.startsWith('//');
|
|
144
|
-
}
|
|
145
|
-
function isAbsolutePath(input) {
|
|
146
|
-
return input.startsWith('/');
|
|
147
|
-
}
|
|
148
|
-
function isFileUrl(input) {
|
|
149
|
-
return input.startsWith('file:');
|
|
150
|
-
}
|
|
151
|
-
function isRelative(input) {
|
|
152
|
-
return /^[.?#]/.test(input);
|
|
153
|
-
}
|
|
154
|
-
function parseAbsoluteUrl(input) {
|
|
155
|
-
const match = urlRegex.exec(input);
|
|
156
|
-
return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
|
|
157
|
-
}
|
|
158
|
-
function parseFileUrl(input) {
|
|
159
|
-
const match = fileRegex.exec(input);
|
|
160
|
-
const path = match[2];
|
|
161
|
-
return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
|
|
162
|
-
}
|
|
163
|
-
function makeUrl(scheme, user, host, port, path, query, hash) {
|
|
164
|
-
return {
|
|
165
|
-
scheme,
|
|
166
|
-
user,
|
|
167
|
-
host,
|
|
168
|
-
port,
|
|
169
|
-
path,
|
|
170
|
-
query,
|
|
171
|
-
hash,
|
|
172
|
-
type: UrlType.Absolute,
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
function parseUrl(input) {
|
|
176
|
-
if (isSchemeRelativeUrl(input)) {
|
|
177
|
-
const url = parseAbsoluteUrl('http:' + input);
|
|
178
|
-
url.scheme = '';
|
|
179
|
-
url.type = UrlType.SchemeRelative;
|
|
180
|
-
return url;
|
|
181
|
-
}
|
|
182
|
-
if (isAbsolutePath(input)) {
|
|
183
|
-
const url = parseAbsoluteUrl('http://foo.com' + input);
|
|
184
|
-
url.scheme = '';
|
|
185
|
-
url.host = '';
|
|
186
|
-
url.type = UrlType.AbsolutePath;
|
|
187
|
-
return url;
|
|
188
|
-
}
|
|
189
|
-
if (isFileUrl(input))
|
|
190
|
-
return parseFileUrl(input);
|
|
191
|
-
if (isAbsoluteUrl(input))
|
|
192
|
-
return parseAbsoluteUrl(input);
|
|
193
|
-
const url = parseAbsoluteUrl('http://foo.com/' + input);
|
|
194
|
-
url.scheme = '';
|
|
195
|
-
url.host = '';
|
|
196
|
-
url.type = input
|
|
197
|
-
? input.startsWith('?')
|
|
198
|
-
? UrlType.Query
|
|
199
|
-
: input.startsWith('#')
|
|
200
|
-
? UrlType.Hash
|
|
201
|
-
: UrlType.RelativePath
|
|
202
|
-
: UrlType.Empty;
|
|
203
|
-
return url;
|
|
204
|
-
}
|
|
205
|
-
function stripPathFilename(path) {
|
|
206
|
-
// If a path ends with a parent directory "..", then it's a relative path with excess parent
|
|
207
|
-
// paths. It's not a file, so we can't strip it.
|
|
208
|
-
if (path.endsWith('/..'))
|
|
209
|
-
return path;
|
|
210
|
-
const index = path.lastIndexOf('/');
|
|
211
|
-
return path.slice(0, index + 1);
|
|
212
|
-
}
|
|
213
|
-
function mergePaths(url, base) {
|
|
214
|
-
normalizePath(base, base.type);
|
|
215
|
-
// If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
|
|
216
|
-
// path).
|
|
217
|
-
if (url.path === '/') {
|
|
218
|
-
url.path = base.path;
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
// Resolution happens relative to the base path's directory, not the file.
|
|
222
|
-
url.path = stripPathFilename(base.path) + url.path;
|
|
85
|
+
} else {
|
|
86
|
+
seg = [genColumn];
|
|
87
|
+
}
|
|
88
|
+
line.push(seg);
|
|
89
|
+
reader.pos++;
|
|
223
90
|
}
|
|
91
|
+
if (!sorted) sort(line);
|
|
92
|
+
decoded.push(line);
|
|
93
|
+
reader.pos = semi + 1;
|
|
94
|
+
} while (reader.pos <= length);
|
|
95
|
+
return decoded;
|
|
224
96
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
* "foo/.". We need to normalize to a standard representation.
|
|
228
|
-
*/
|
|
229
|
-
function normalizePath(url, type) {
|
|
230
|
-
const rel = type <= UrlType.RelativePath;
|
|
231
|
-
const pieces = url.path.split('/');
|
|
232
|
-
// We need to preserve the first piece always, so that we output a leading slash. The item at
|
|
233
|
-
// pieces[0] is an empty string.
|
|
234
|
-
let pointer = 1;
|
|
235
|
-
// Positive is the number of real directories we've output, used for popping a parent directory.
|
|
236
|
-
// Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
|
|
237
|
-
let positive = 0;
|
|
238
|
-
// We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
|
|
239
|
-
// generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
|
|
240
|
-
// real directory, we won't need to append, unless the other conditions happen again.
|
|
241
|
-
let addTrailingSlash = false;
|
|
242
|
-
for (let i = 1; i < pieces.length; i++) {
|
|
243
|
-
const piece = pieces[i];
|
|
244
|
-
// An empty directory, could be a trailing slash, or just a double "//" in the path.
|
|
245
|
-
if (!piece) {
|
|
246
|
-
addTrailingSlash = true;
|
|
247
|
-
continue;
|
|
248
|
-
}
|
|
249
|
-
// If we encounter a real directory, then we don't need to append anymore.
|
|
250
|
-
addTrailingSlash = false;
|
|
251
|
-
// A current directory, which we can always drop.
|
|
252
|
-
if (piece === '.')
|
|
253
|
-
continue;
|
|
254
|
-
// A parent directory, we need to see if there are any real directories we can pop. Else, we
|
|
255
|
-
// have an excess of parents, and we'll need to keep the "..".
|
|
256
|
-
if (piece === '..') {
|
|
257
|
-
if (positive) {
|
|
258
|
-
addTrailingSlash = true;
|
|
259
|
-
positive--;
|
|
260
|
-
pointer--;
|
|
261
|
-
}
|
|
262
|
-
else if (rel) {
|
|
263
|
-
// If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
|
|
264
|
-
// URL, protocol relative URL, or an absolute path, we don't need to keep excess.
|
|
265
|
-
pieces[pointer++] = piece;
|
|
266
|
-
}
|
|
267
|
-
continue;
|
|
268
|
-
}
|
|
269
|
-
// We've encountered a real directory. Move it to the next insertion pointer, which accounts for
|
|
270
|
-
// any popped or dropped directories.
|
|
271
|
-
pieces[pointer++] = piece;
|
|
272
|
-
positive++;
|
|
273
|
-
}
|
|
274
|
-
let path = '';
|
|
275
|
-
for (let i = 1; i < pointer; i++) {
|
|
276
|
-
path += '/' + pieces[i];
|
|
277
|
-
}
|
|
278
|
-
if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
|
|
279
|
-
path += '/';
|
|
280
|
-
}
|
|
281
|
-
url.path = path;
|
|
97
|
+
function sort(line) {
|
|
98
|
+
line.sort(sortComparator);
|
|
282
99
|
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
*/
|
|
286
|
-
function resolve(input, base) {
|
|
287
|
-
if (!input && !base)
|
|
288
|
-
return '';
|
|
289
|
-
const url = parseUrl(input);
|
|
290
|
-
let inputType = url.type;
|
|
291
|
-
if (base && inputType !== UrlType.Absolute) {
|
|
292
|
-
const baseUrl = parseUrl(base);
|
|
293
|
-
const baseType = baseUrl.type;
|
|
294
|
-
switch (inputType) {
|
|
295
|
-
case UrlType.Empty:
|
|
296
|
-
url.hash = baseUrl.hash;
|
|
297
|
-
// fall through
|
|
298
|
-
case UrlType.Hash:
|
|
299
|
-
url.query = baseUrl.query;
|
|
300
|
-
// fall through
|
|
301
|
-
case UrlType.Query:
|
|
302
|
-
case UrlType.RelativePath:
|
|
303
|
-
mergePaths(url, baseUrl);
|
|
304
|
-
// fall through
|
|
305
|
-
case UrlType.AbsolutePath:
|
|
306
|
-
// The host, user, and port are joined, you can't copy one without the others.
|
|
307
|
-
url.user = baseUrl.user;
|
|
308
|
-
url.host = baseUrl.host;
|
|
309
|
-
url.port = baseUrl.port;
|
|
310
|
-
// fall through
|
|
311
|
-
case UrlType.SchemeRelative:
|
|
312
|
-
// The input doesn't have a schema at least, so we need to copy at least that over.
|
|
313
|
-
url.scheme = baseUrl.scheme;
|
|
314
|
-
}
|
|
315
|
-
if (baseType > inputType)
|
|
316
|
-
inputType = baseType;
|
|
317
|
-
}
|
|
318
|
-
normalizePath(url, inputType);
|
|
319
|
-
const queryHash = url.query + url.hash;
|
|
320
|
-
switch (inputType) {
|
|
321
|
-
// This is impossible, because of the empty checks at the start of the function.
|
|
322
|
-
// case UrlType.Empty:
|
|
323
|
-
case UrlType.Hash:
|
|
324
|
-
case UrlType.Query:
|
|
325
|
-
return queryHash;
|
|
326
|
-
case UrlType.RelativePath: {
|
|
327
|
-
// The first char is always a "/", and we need it to be relative.
|
|
328
|
-
const path = url.path.slice(1);
|
|
329
|
-
if (!path)
|
|
330
|
-
return queryHash || '.';
|
|
331
|
-
if (isRelative(base || input) && !isRelative(path)) {
|
|
332
|
-
// If base started with a leading ".", or there is no base and input started with a ".",
|
|
333
|
-
// then we need to ensure that the relative path starts with a ".". We don't know if
|
|
334
|
-
// relative starts with a "..", though, so check before prepending.
|
|
335
|
-
return './' + path + queryHash;
|
|
336
|
-
}
|
|
337
|
-
return path + queryHash;
|
|
338
|
-
}
|
|
339
|
-
case UrlType.AbsolutePath:
|
|
340
|
-
return url.path + queryHash;
|
|
341
|
-
default:
|
|
342
|
-
return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
|
|
343
|
-
}
|
|
100
|
+
function sortComparator(a, b) {
|
|
101
|
+
return a[0] - b[0];
|
|
344
102
|
}
|
|
345
103
|
|
|
346
104
|
// src/trace-mapping.ts
|
|
347
105
|
|
|
348
|
-
// src/strip-filename.ts
|
|
349
|
-
function stripFilename(path) {
|
|
350
|
-
if (!path) return "";
|
|
351
|
-
const index = path.lastIndexOf("/");
|
|
352
|
-
return path.slice(0, index + 1);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
// src/resolve.ts
|
|
356
|
-
function resolver(mapUrl, sourceRoot) {
|
|
357
|
-
const from = stripFilename(mapUrl);
|
|
358
|
-
const prefix = sourceRoot ? sourceRoot + "/" : "";
|
|
359
|
-
return (source) => resolve(prefix + (source || ""), from);
|
|
360
|
-
}
|
|
361
|
-
|
|
362
106
|
// src/sourcemap-segment.ts
|
|
363
107
|
var COLUMN = 0;
|
|
364
108
|
var SOURCES_INDEX = 1;
|
|
365
109
|
var SOURCE_LINE = 2;
|
|
366
110
|
var SOURCE_COLUMN = 3;
|
|
367
111
|
var NAMES_INDEX = 4;
|
|
368
|
-
var REV_GENERATED_LINE = 1;
|
|
369
|
-
var REV_GENERATED_COLUMN = 2;
|
|
370
|
-
|
|
371
|
-
// src/sort.ts
|
|
372
|
-
function maybeSort(mappings, owned) {
|
|
373
|
-
const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
|
|
374
|
-
if (unsortedIndex === mappings.length) return mappings;
|
|
375
|
-
if (!owned) mappings = mappings.slice();
|
|
376
|
-
for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
|
|
377
|
-
mappings[i] = sortSegments(mappings[i], owned);
|
|
378
|
-
}
|
|
379
|
-
return mappings;
|
|
380
|
-
}
|
|
381
|
-
function nextUnsortedSegmentLine(mappings, start) {
|
|
382
|
-
for (let i = start; i < mappings.length; i++) {
|
|
383
|
-
if (!isSorted(mappings[i])) return i;
|
|
384
|
-
}
|
|
385
|
-
return mappings.length;
|
|
386
|
-
}
|
|
387
|
-
function isSorted(line) {
|
|
388
|
-
for (let j = 1; j < line.length; j++) {
|
|
389
|
-
if (line[j][COLUMN] < line[j - 1][COLUMN]) {
|
|
390
|
-
return false;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
return true;
|
|
394
|
-
}
|
|
395
|
-
function sortSegments(line, owned) {
|
|
396
|
-
if (!owned) line = line.slice();
|
|
397
|
-
return line.sort(sortComparator);
|
|
398
|
-
}
|
|
399
|
-
function sortComparator(a, b) {
|
|
400
|
-
return a[COLUMN] - b[COLUMN];
|
|
401
|
-
}
|
|
402
112
|
|
|
403
113
|
// src/binary-search.ts
|
|
404
114
|
var found = false;
|
|
@@ -431,13 +141,6 @@ function lowerBound(haystack, needle, index) {
|
|
|
431
141
|
}
|
|
432
142
|
return index;
|
|
433
143
|
}
|
|
434
|
-
function memoizedState() {
|
|
435
|
-
return {
|
|
436
|
-
lastKey: -1,
|
|
437
|
-
lastNeedle: -1,
|
|
438
|
-
lastIndex: -1
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
144
|
function memoizedBinarySearch(haystack, needle, state, key) {
|
|
442
145
|
const { lastKey, lastNeedle, lastIndex } = state;
|
|
443
146
|
let low = 0;
|
|
@@ -458,83 +161,11 @@ function memoizedBinarySearch(haystack, needle, state, key) {
|
|
|
458
161
|
return state.lastIndex = binarySearch(haystack, needle, low, high);
|
|
459
162
|
}
|
|
460
163
|
|
|
461
|
-
// src/by-source.ts
|
|
462
|
-
function buildBySources(decoded, memos) {
|
|
463
|
-
const sources = memos.map(buildNullArray);
|
|
464
|
-
for (let i = 0; i < decoded.length; i++) {
|
|
465
|
-
const line = decoded[i];
|
|
466
|
-
for (let j = 0; j < line.length; j++) {
|
|
467
|
-
const seg = line[j];
|
|
468
|
-
if (seg.length === 1) continue;
|
|
469
|
-
const sourceIndex2 = seg[SOURCES_INDEX];
|
|
470
|
-
const sourceLine = seg[SOURCE_LINE];
|
|
471
|
-
const sourceColumn = seg[SOURCE_COLUMN];
|
|
472
|
-
const originalSource = sources[sourceIndex2];
|
|
473
|
-
const originalLine = originalSource[sourceLine] || (originalSource[sourceLine] = []);
|
|
474
|
-
const memo = memos[sourceIndex2];
|
|
475
|
-
let index = upperBound(
|
|
476
|
-
originalLine,
|
|
477
|
-
sourceColumn,
|
|
478
|
-
memoizedBinarySearch(originalLine, sourceColumn, memo, sourceLine)
|
|
479
|
-
);
|
|
480
|
-
memo.lastIndex = ++index;
|
|
481
|
-
insert(originalLine, index, [sourceColumn, i, seg[COLUMN]]);
|
|
482
|
-
}
|
|
483
|
-
}
|
|
484
|
-
return sources;
|
|
485
|
-
}
|
|
486
|
-
function insert(array, index, value) {
|
|
487
|
-
for (let i = array.length; i > index; i--) {
|
|
488
|
-
array[i] = array[i - 1];
|
|
489
|
-
}
|
|
490
|
-
array[index] = value;
|
|
491
|
-
}
|
|
492
|
-
function buildNullArray() {
|
|
493
|
-
return { __proto__: null };
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// src/types.ts
|
|
497
|
-
function parse(map) {
|
|
498
|
-
return typeof map === "string" ? JSON.parse(map) : map;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
164
|
// src/trace-mapping.ts
|
|
502
165
|
var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
|
|
503
166
|
var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
|
|
504
167
|
var LEAST_UPPER_BOUND = -1;
|
|
505
168
|
var GREATEST_LOWER_BOUND = 1;
|
|
506
|
-
var TraceMap = class {
|
|
507
|
-
constructor(map, mapUrl) {
|
|
508
|
-
const isString = typeof map === "string";
|
|
509
|
-
if (!isString && map._decodedMemo) return map;
|
|
510
|
-
const parsed = parse(map);
|
|
511
|
-
const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
|
|
512
|
-
this.version = version;
|
|
513
|
-
this.file = file;
|
|
514
|
-
this.names = names || [];
|
|
515
|
-
this.sourceRoot = sourceRoot;
|
|
516
|
-
this.sources = sources;
|
|
517
|
-
this.sourcesContent = sourcesContent;
|
|
518
|
-
this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
|
|
519
|
-
const resolve = resolver(mapUrl, sourceRoot);
|
|
520
|
-
this.resolvedSources = sources.map(resolve);
|
|
521
|
-
const { mappings } = parsed;
|
|
522
|
-
if (typeof mappings === "string") {
|
|
523
|
-
this._encoded = mappings;
|
|
524
|
-
this._decoded = void 0;
|
|
525
|
-
} else if (Array.isArray(mappings)) {
|
|
526
|
-
this._encoded = void 0;
|
|
527
|
-
this._decoded = maybeSort(mappings, isString);
|
|
528
|
-
} else if (parsed.sections) {
|
|
529
|
-
throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
|
|
530
|
-
} else {
|
|
531
|
-
throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
|
|
532
|
-
}
|
|
533
|
-
this._decodedMemo = memoizedState();
|
|
534
|
-
this._bySources = void 0;
|
|
535
|
-
this._bySourceMemos = void 0;
|
|
536
|
-
}
|
|
537
|
-
};
|
|
538
169
|
function cast(map) {
|
|
539
170
|
return map;
|
|
540
171
|
}
|
|
@@ -568,46 +199,9 @@ function originalPositionFor(map, needle) {
|
|
|
568
199
|
segment.length === 5 ? names[segment[NAMES_INDEX]] : null
|
|
569
200
|
);
|
|
570
201
|
}
|
|
571
|
-
function generatedPositionFor(map, needle) {
|
|
572
|
-
const { source, line, column, bias } = needle;
|
|
573
|
-
return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
|
|
574
|
-
}
|
|
575
|
-
function eachMapping(map, cb) {
|
|
576
|
-
const decoded = decodedMappings(map);
|
|
577
|
-
const { names, resolvedSources } = map;
|
|
578
|
-
for (let i = 0; i < decoded.length; i++) {
|
|
579
|
-
const line = decoded[i];
|
|
580
|
-
for (let j = 0; j < line.length; j++) {
|
|
581
|
-
const seg = line[j];
|
|
582
|
-
const generatedLine = i + 1;
|
|
583
|
-
const generatedColumn = seg[0];
|
|
584
|
-
let source = null;
|
|
585
|
-
let originalLine = null;
|
|
586
|
-
let originalColumn = null;
|
|
587
|
-
let name = null;
|
|
588
|
-
if (seg.length !== 1) {
|
|
589
|
-
source = resolvedSources[seg[1]];
|
|
590
|
-
originalLine = seg[2] + 1;
|
|
591
|
-
originalColumn = seg[3];
|
|
592
|
-
}
|
|
593
|
-
if (seg.length === 5) name = names[seg[4]];
|
|
594
|
-
cb({
|
|
595
|
-
generatedLine,
|
|
596
|
-
generatedColumn,
|
|
597
|
-
source,
|
|
598
|
-
originalLine,
|
|
599
|
-
originalColumn,
|
|
600
|
-
name
|
|
601
|
-
});
|
|
602
|
-
}
|
|
603
|
-
}
|
|
604
|
-
}
|
|
605
202
|
function OMapping(source, line, column, name) {
|
|
606
203
|
return { source, line, column, name };
|
|
607
204
|
}
|
|
608
|
-
function GMapping(line, column) {
|
|
609
|
-
return { line, column };
|
|
610
|
-
}
|
|
611
205
|
function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
612
206
|
let index = memoizedBinarySearch(segments, column, memo, line);
|
|
613
207
|
if (found) {
|
|
@@ -616,27 +210,6 @@ function traceSegmentInternal(segments, memo, line, column, bias) {
|
|
|
616
210
|
if (index === -1 || index === segments.length) return -1;
|
|
617
211
|
return index;
|
|
618
212
|
}
|
|
619
|
-
function generatedPosition(map, source, line, column, bias, all) {
|
|
620
|
-
var _a;
|
|
621
|
-
line--;
|
|
622
|
-
if (line < 0) throw new Error(LINE_GTR_ZERO);
|
|
623
|
-
if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
|
|
624
|
-
const { sources, resolvedSources } = map;
|
|
625
|
-
let sourceIndex2 = sources.indexOf(source);
|
|
626
|
-
if (sourceIndex2 === -1) sourceIndex2 = resolvedSources.indexOf(source);
|
|
627
|
-
if (sourceIndex2 === -1) return all ? [] : GMapping(null, null);
|
|
628
|
-
const generated = (_a = cast(map))._bySources || (_a._bySources = buildBySources(
|
|
629
|
-
decodedMappings(map),
|
|
630
|
-
cast(map)._bySourceMemos = sources.map(memoizedState)
|
|
631
|
-
));
|
|
632
|
-
const segments = generated[sourceIndex2][line];
|
|
633
|
-
if (segments == null) return all ? [] : GMapping(null, null);
|
|
634
|
-
const memo = cast(map)._bySourceMemos[sourceIndex2];
|
|
635
|
-
const index = traceSegmentInternal(segments, memo, line, column, bias);
|
|
636
|
-
if (index === -1) return GMapping(null, null);
|
|
637
|
-
const segment = segments[index];
|
|
638
|
-
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
|
639
|
-
}
|
|
640
213
|
|
|
641
214
|
const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
|
|
642
215
|
const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
|
|
@@ -700,14 +273,35 @@ function parseSingleFFOrSafariStack(raw) {
|
|
|
700
273
|
if (line.includes(" > eval")) {
|
|
701
274
|
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
|
|
702
275
|
}
|
|
703
|
-
|
|
276
|
+
// Early return for lines that don't look like Firefox/Safari stack traces
|
|
277
|
+
// Firefox/Safari stack traces must contain '@' and should have location info after it
|
|
278
|
+
if (!line.includes("@")) {
|
|
704
279
|
return null;
|
|
705
280
|
}
|
|
706
|
-
//
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
281
|
+
// Find the correct @ that separates function name from location
|
|
282
|
+
// For cases like '@https://@fs/path' or 'functionName@https://@fs/path'
|
|
283
|
+
// we need to find the first @ that precedes a valid location (containing :)
|
|
284
|
+
let atIndex = -1;
|
|
285
|
+
let locationPart = "";
|
|
286
|
+
let functionName;
|
|
287
|
+
// Try each @ from left to right to find the one that gives us a valid location
|
|
288
|
+
for (let i = 0; i < line.length; i++) {
|
|
289
|
+
if (line[i] === "@") {
|
|
290
|
+
const candidateLocation = line.slice(i + 1);
|
|
291
|
+
// Minimum length 3 for valid location: 1 for filename + 1 for colon + 1 for line number (e.g., "a:1")
|
|
292
|
+
if (candidateLocation.includes(":") && candidateLocation.length >= 3) {
|
|
293
|
+
atIndex = i;
|
|
294
|
+
locationPart = candidateLocation;
|
|
295
|
+
functionName = i > 0 ? line.slice(0, i) : undefined;
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
// Validate we found a valid location with minimum length (filename:line format)
|
|
301
|
+
if (atIndex === -1 || !locationPart.includes(":") || locationPart.length < 3) {
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
const [url, lineNumber, columnNumber] = extractLocation(locationPart);
|
|
711
305
|
if (!url || !lineNumber || !columnNumber) {
|
|
712
306
|
return null;
|
|
713
307
|
}
|
|
@@ -756,9 +350,9 @@ function parseSingleV8Stack(raw) {
|
|
|
756
350
|
file = file.slice(7);
|
|
757
351
|
}
|
|
758
352
|
// normalize Windows path (\ -> /)
|
|
759
|
-
file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve
|
|
353
|
+
file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve(file);
|
|
760
354
|
if (method) {
|
|
761
|
-
method = method.replace(/__vite_ssr_import_\d+__\./g, "");
|
|
355
|
+
method = method.replace(/__vite_ssr_import_\d+__\./g, "").replace(/(Object\.)?__vite_ssr_export_default__\s?/g, "");
|
|
762
356
|
}
|
|
763
357
|
return {
|
|
764
358
|
method,
|
|
@@ -788,17 +382,15 @@ function parseStacktrace(stack, options = {}) {
|
|
|
788
382
|
if (!map || typeof map !== "object" || !map.version) {
|
|
789
383
|
return shouldFilter(ignoreStackEntries, stack.file) ? null : stack;
|
|
790
384
|
}
|
|
791
|
-
const traceMap = new
|
|
792
|
-
const
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
file = file.slice(1);
|
|
801
|
-
}
|
|
385
|
+
const traceMap = new DecodedMap(map, stack.file);
|
|
386
|
+
const position = getOriginalPosition(traceMap, stack);
|
|
387
|
+
if (!position) {
|
|
388
|
+
return stack;
|
|
389
|
+
}
|
|
390
|
+
const { line, column, source, name } = position;
|
|
391
|
+
let file = source || stack.file;
|
|
392
|
+
if (file.match(/\/\w:\//)) {
|
|
393
|
+
file = file.slice(1);
|
|
802
394
|
}
|
|
803
395
|
if (shouldFilter(ignoreStackEntries, file)) {
|
|
804
396
|
return null;
|
|
@@ -849,5 +441,38 @@ function parseErrorStacktrace(e, options = {}) {
|
|
|
849
441
|
e.stacks = stackFrames;
|
|
850
442
|
return stackFrames;
|
|
851
443
|
}
|
|
444
|
+
class DecodedMap {
|
|
445
|
+
_encoded;
|
|
446
|
+
_decoded;
|
|
447
|
+
_decodedMemo;
|
|
448
|
+
url;
|
|
449
|
+
version;
|
|
450
|
+
names = [];
|
|
451
|
+
resolvedSources;
|
|
452
|
+
constructor(map, from) {
|
|
453
|
+
this.map = map;
|
|
454
|
+
const { mappings, names, sources } = map;
|
|
455
|
+
this.version = map.version;
|
|
456
|
+
this.names = names || [];
|
|
457
|
+
this._encoded = mappings || "";
|
|
458
|
+
this._decodedMemo = memoizedState();
|
|
459
|
+
this.url = from;
|
|
460
|
+
this.resolvedSources = (sources || []).map((s) => resolve(s || "", from));
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
function memoizedState() {
|
|
464
|
+
return {
|
|
465
|
+
lastKey: -1,
|
|
466
|
+
lastNeedle: -1,
|
|
467
|
+
lastIndex: -1
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function getOriginalPosition(map, needle) {
|
|
471
|
+
const result = originalPositionFor(map, needle);
|
|
472
|
+
if (result.column == null) {
|
|
473
|
+
return null;
|
|
474
|
+
}
|
|
475
|
+
return result;
|
|
476
|
+
}
|
|
852
477
|
|
|
853
|
-
export {
|
|
478
|
+
export { DecodedMap, createStackString, stackIgnorePatterns as defaultStackIgnorePatterns, getOriginalPosition, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
|