vitest 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.
Files changed (69) hide show
  1. package/LICENSE.md +85 -101
  2. package/dist/browser.d.ts +10 -6
  3. package/dist/browser.js +8 -5
  4. package/dist/chunks/{benchmark.CJUa-Hsa.js → benchmark.DHKMYAts.js} +2 -2
  5. package/dist/chunks/{browser.d.yFAklsD1.d.ts → browser.d.D9YV3JvA.d.ts} +1 -1
  6. package/dist/chunks/{cac.DCxo_nSu.js → cac.r1gel_VZ.js} +18 -11
  7. package/dist/chunks/{cli-api.BJJXh9BV.js → cli-api.CpywZzJV.js} +153 -176
  8. package/dist/chunks/{config.d.B_LthbQq.d.ts → config.d.DGazh2r6.d.ts} +3 -1
  9. package/dist/chunks/{console.7h5kHUIf.js → console.CTJL2nuH.js} +4 -6
  10. package/dist/chunks/{coverage.BCU-r2QL.js → coverage.CiB0fs_7.js} +57 -79
  11. package/dist/chunks/{creator.08Gi-vCA.js → creator.DfXDsUyL.js} +6 -8
  12. package/dist/chunks/{global.d.BK3X7FW1.d.ts → global.d.BcFPD2LN.d.ts} +0 -13
  13. package/dist/chunks/{globals.DG-S3xFe.js → globals.DC4ntO86.js} +8 -6
  14. package/dist/chunks/{index.DIWhzsUh.js → index.Bt-upxGS.js} +6 -12
  15. package/dist/chunks/{index.BIP7prJq.js → index.CHrBLuEH.js} +94 -103
  16. package/dist/chunks/{index.X0nbfr6-.js → index.Dc3xnDvT.js} +48 -289
  17. package/dist/chunks/{index.CMfqw92x.js → index.Dnl38iQ_.js} +2 -2
  18. package/dist/chunks/{index.BjKEiSn0.js → index.uLUz1RDt.js} +3 -3
  19. package/dist/chunks/{inspector.CvQD-Nie.js → inspector.Br76Q2Mb.js} +1 -4
  20. package/dist/chunks/{moduleRunner.d.D9nBoC4p.d.ts → moduleRunner.d.CeYc7nZ0.d.ts} +1 -1
  21. package/dist/chunks/{node.CyipiPvJ.js → node.BwAWWjHZ.js} +3 -4
  22. package/dist/chunks/{plugin.d.BMVSnsGV.d.ts → plugin.d.XreRXLXS.d.ts} +1 -1
  23. package/dist/chunks/{reporters.d.BUWjmRYq.d.ts → reporters.d.CJVTaaWb.d.ts} +54 -13
  24. package/dist/chunks/{resolveSnapshotEnvironment.Bkht6Yor.js → resolveSnapshotEnvironment.BsJpmVZR.js} +7 -8
  25. package/dist/chunks/{rpc.BKr6mtxz.js → rpc.cD77ENhU.js} +13 -14
  26. package/dist/chunks/{setup-common.uiMcU3cv.js → setup-common.BewgbkTd.js} +6 -6
  27. package/dist/chunks/{startModuleRunner.p67gbNo9.js → startModuleRunner.DPBo3mme.js} +65 -56
  28. package/dist/chunks/{test.BiqSKISg.js → test.CTuWuHYH.js} +7 -7
  29. package/dist/chunks/{typechecker.DB-fIMaH.js → typechecker.BfOQ86_a.js} +624 -14
  30. package/dist/chunks/{utils.D2R2NiOH.js → utils.CG9h5ccR.js} +2 -5
  31. package/dist/chunks/{vi.ZPgvtBao.js → vi.B2--mG9U.js} +38 -145
  32. package/dist/{worker.js → chunks/worker.DVTUM2IW.js} +71 -42
  33. package/dist/chunks/{worker.d.BDsXGkwh.d.ts → worker.d.buwuBpBt.d.ts} +2 -77
  34. package/dist/cli.js +7 -5
  35. package/dist/config.d.ts +6 -6
  36. package/dist/coverage.d.ts +5 -5
  37. package/dist/coverage.js +4 -5
  38. package/dist/environments.js +1 -1
  39. package/dist/index.d.ts +8 -8
  40. package/dist/index.js +8 -6
  41. package/dist/module-evaluator.d.ts +3 -3
  42. package/dist/module-evaluator.js +11 -13
  43. package/dist/module-runner.js +5 -5
  44. package/dist/node.d.ts +14 -11
  45. package/dist/node.js +18 -14
  46. package/dist/reporters.d.ts +5 -5
  47. package/dist/reporters.js +7 -5
  48. package/dist/runners.d.ts +1 -1
  49. package/dist/runners.js +9 -7
  50. package/dist/snapshot.js +3 -3
  51. package/dist/suite.js +4 -3
  52. package/dist/{chunks/base.Cjha6usc.js → worker-base.js} +104 -32
  53. package/dist/{chunks/vm.Ca0Y0W5f.js → worker-vm.js} +81 -31
  54. package/dist/workers/runVmTests.js +14 -11
  55. package/package.json +26 -26
  56. package/browser.d.ts +0 -1
  57. package/dist/chunks/moduleTransport.I-bgQy0S.js +0 -19
  58. package/dist/chunks/resolver.Bx6lE0iq.js +0 -119
  59. package/dist/chunks/utils.C2YI6McM.js +0 -52
  60. package/dist/chunks/worker.d.BNcX_2mH.d.ts +0 -8
  61. package/dist/workers/forks.js +0 -67
  62. package/dist/workers/threads.js +0 -55
  63. package/dist/workers/vmForks.js +0 -48
  64. package/dist/workers/vmThreads.js +0 -38
  65. package/dist/workers.d.ts +0 -38
  66. package/dist/workers.js +0 -48
  67. package/execute.d.ts +0 -1
  68. package/utils.d.ts +0 -1
  69. package/workers.d.ts +0 -1
@@ -1,11 +1,10 @@
1
1
  import nodeos__default from 'node:os';
2
2
  import { performance } from 'node:perf_hooks';
3
- import { TraceMap, generatedPositionFor, eachMapping } from '@vitest/utils/source-map';
4
- import { relative, basename, resolve, join } from 'pathe';
3
+ import { relative, basename, resolve as resolve$1, join } from 'pathe';
5
4
  import { x } from 'tinyexec';
6
5
  import { distDir } from '../path.js';
7
6
  import { getTests, generateHash, calculateSuiteHash, someTasksAreOnly, interpretTaskModes } from '@vitest/runner/utils';
8
- import '@vitest/utils';
7
+ import '@vitest/utils/helpers';
9
8
  import { parseAstAsync } from 'vite';
10
9
 
11
10
  const REGEXP_WRAP_PREFIX = "$$vitest:";
@@ -31,9 +30,7 @@ function wrapSerializableConfig(config) {
31
30
  };
32
31
  }
33
32
  function createDefinesScript(define) {
34
- if (!define) return "";
35
- const serializedDefine = serializeDefine(define);
36
- return serializedDefine === "{}" ? "" : `
33
+ return !define || serializeDefine(define) === "{}" ? "" : `
37
34
  const defines = ${serializeDefine(define)}
38
35
  Object.keys(defines).forEach((key) => {
39
36
  const segments = key.split('.')
@@ -123,6 +120,619 @@ function convertTasksToEvents(file, onTask) {
123
120
  };
124
121
  }
125
122
 
123
+ // src/vlq.ts
124
+ var comma = ",".charCodeAt(0);
125
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
126
+ var intToChar = new Uint8Array(64);
127
+ var charToInt = new Uint8Array(128);
128
+ for (let i = 0; i < chars.length; i++) {
129
+ const c = chars.charCodeAt(i);
130
+ intToChar[i] = c;
131
+ charToInt[c] = i;
132
+ }
133
+ function decodeInteger(reader, relative) {
134
+ let value = 0;
135
+ let shift = 0;
136
+ let integer = 0;
137
+ do {
138
+ const c = reader.next();
139
+ integer = charToInt[c];
140
+ value |= (integer & 31) << shift;
141
+ shift += 5;
142
+ } while (integer & 32);
143
+ const shouldNegate = value & 1;
144
+ value >>>= 1;
145
+ if (shouldNegate) {
146
+ value = -2147483648 | -value;
147
+ }
148
+ return relative + value;
149
+ }
150
+ function hasMoreVlq(reader, max) {
151
+ if (reader.pos >= max) return false;
152
+ return reader.peek() !== comma;
153
+ }
154
+ var StringReader = class {
155
+ constructor(buffer) {
156
+ this.pos = 0;
157
+ this.buffer = buffer;
158
+ }
159
+ next() {
160
+ return this.buffer.charCodeAt(this.pos++);
161
+ }
162
+ peek() {
163
+ return this.buffer.charCodeAt(this.pos);
164
+ }
165
+ indexOf(char) {
166
+ const { buffer, pos } = this;
167
+ const idx = buffer.indexOf(char, pos);
168
+ return idx === -1 ? buffer.length : idx;
169
+ }
170
+ };
171
+
172
+ // src/sourcemap-codec.ts
173
+ function decode(mappings) {
174
+ const { length } = mappings;
175
+ const reader = new StringReader(mappings);
176
+ const decoded = [];
177
+ let genColumn = 0;
178
+ let sourcesIndex = 0;
179
+ let sourceLine = 0;
180
+ let sourceColumn = 0;
181
+ let namesIndex = 0;
182
+ do {
183
+ const semi = reader.indexOf(";");
184
+ const line = [];
185
+ let sorted = true;
186
+ let lastCol = 0;
187
+ genColumn = 0;
188
+ while (reader.pos < semi) {
189
+ let seg;
190
+ genColumn = decodeInteger(reader, genColumn);
191
+ if (genColumn < lastCol) sorted = false;
192
+ lastCol = genColumn;
193
+ if (hasMoreVlq(reader, semi)) {
194
+ sourcesIndex = decodeInteger(reader, sourcesIndex);
195
+ sourceLine = decodeInteger(reader, sourceLine);
196
+ sourceColumn = decodeInteger(reader, sourceColumn);
197
+ if (hasMoreVlq(reader, semi)) {
198
+ namesIndex = decodeInteger(reader, namesIndex);
199
+ seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
200
+ } else {
201
+ seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
202
+ }
203
+ } else {
204
+ seg = [genColumn];
205
+ }
206
+ line.push(seg);
207
+ reader.pos++;
208
+ }
209
+ if (!sorted) sort(line);
210
+ decoded.push(line);
211
+ reader.pos = semi + 1;
212
+ } while (reader.pos <= length);
213
+ return decoded;
214
+ }
215
+ function sort(line) {
216
+ line.sort(sortComparator$1);
217
+ }
218
+ function sortComparator$1(a, b) {
219
+ return a[0] - b[0];
220
+ }
221
+
222
+ // Matches the scheme of a URL, eg "http://"
223
+ const schemeRegex = /^[\w+.-]+:\/\//;
224
+ /**
225
+ * Matches the parts of a URL:
226
+ * 1. Scheme, including ":", guaranteed.
227
+ * 2. User/password, including "@", optional.
228
+ * 3. Host, guaranteed.
229
+ * 4. Port, including ":", optional.
230
+ * 5. Path, including "/", optional.
231
+ * 6. Query, including "?", optional.
232
+ * 7. Hash, including "#", optional.
233
+ */
234
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
235
+ /**
236
+ * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
237
+ * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
238
+ *
239
+ * 1. Host, optional.
240
+ * 2. Path, which may include "/", guaranteed.
241
+ * 3. Query, including "?", optional.
242
+ * 4. Hash, including "#", optional.
243
+ */
244
+ const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
245
+ function isAbsoluteUrl(input) {
246
+ return schemeRegex.test(input);
247
+ }
248
+ function isSchemeRelativeUrl(input) {
249
+ return input.startsWith('//');
250
+ }
251
+ function isAbsolutePath(input) {
252
+ return input.startsWith('/');
253
+ }
254
+ function isFileUrl(input) {
255
+ return input.startsWith('file:');
256
+ }
257
+ function isRelative(input) {
258
+ return /^[.?#]/.test(input);
259
+ }
260
+ function parseAbsoluteUrl(input) {
261
+ const match = urlRegex.exec(input);
262
+ return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
263
+ }
264
+ function parseFileUrl(input) {
265
+ const match = fileRegex.exec(input);
266
+ const path = match[2];
267
+ return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
268
+ }
269
+ function makeUrl(scheme, user, host, port, path, query, hash) {
270
+ return {
271
+ scheme,
272
+ user,
273
+ host,
274
+ port,
275
+ path,
276
+ query,
277
+ hash,
278
+ type: 7 /* Absolute */,
279
+ };
280
+ }
281
+ function parseUrl(input) {
282
+ if (isSchemeRelativeUrl(input)) {
283
+ const url = parseAbsoluteUrl('http:' + input);
284
+ url.scheme = '';
285
+ url.type = 6 /* SchemeRelative */;
286
+ return url;
287
+ }
288
+ if (isAbsolutePath(input)) {
289
+ const url = parseAbsoluteUrl('http://foo.com' + input);
290
+ url.scheme = '';
291
+ url.host = '';
292
+ url.type = 5 /* AbsolutePath */;
293
+ return url;
294
+ }
295
+ if (isFileUrl(input))
296
+ return parseFileUrl(input);
297
+ if (isAbsoluteUrl(input))
298
+ return parseAbsoluteUrl(input);
299
+ const url = parseAbsoluteUrl('http://foo.com/' + input);
300
+ url.scheme = '';
301
+ url.host = '';
302
+ url.type = input
303
+ ? input.startsWith('?')
304
+ ? 3 /* Query */
305
+ : input.startsWith('#')
306
+ ? 2 /* Hash */
307
+ : 4 /* RelativePath */
308
+ : 1 /* Empty */;
309
+ return url;
310
+ }
311
+ function stripPathFilename(path) {
312
+ // If a path ends with a parent directory "..", then it's a relative path with excess parent
313
+ // paths. It's not a file, so we can't strip it.
314
+ if (path.endsWith('/..'))
315
+ return path;
316
+ const index = path.lastIndexOf('/');
317
+ return path.slice(0, index + 1);
318
+ }
319
+ function mergePaths(url, base) {
320
+ normalizePath(base, base.type);
321
+ // If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
322
+ // path).
323
+ if (url.path === '/') {
324
+ url.path = base.path;
325
+ }
326
+ else {
327
+ // Resolution happens relative to the base path's directory, not the file.
328
+ url.path = stripPathFilename(base.path) + url.path;
329
+ }
330
+ }
331
+ /**
332
+ * The path can have empty directories "//", unneeded parents "foo/..", or current directory
333
+ * "foo/.". We need to normalize to a standard representation.
334
+ */
335
+ function normalizePath(url, type) {
336
+ const rel = type <= 4 /* RelativePath */;
337
+ const pieces = url.path.split('/');
338
+ // We need to preserve the first piece always, so that we output a leading slash. The item at
339
+ // pieces[0] is an empty string.
340
+ let pointer = 1;
341
+ // Positive is the number of real directories we've output, used for popping a parent directory.
342
+ // Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
343
+ let positive = 0;
344
+ // We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
345
+ // generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
346
+ // real directory, we won't need to append, unless the other conditions happen again.
347
+ let addTrailingSlash = false;
348
+ for (let i = 1; i < pieces.length; i++) {
349
+ const piece = pieces[i];
350
+ // An empty directory, could be a trailing slash, or just a double "//" in the path.
351
+ if (!piece) {
352
+ addTrailingSlash = true;
353
+ continue;
354
+ }
355
+ // If we encounter a real directory, then we don't need to append anymore.
356
+ addTrailingSlash = false;
357
+ // A current directory, which we can always drop.
358
+ if (piece === '.')
359
+ continue;
360
+ // A parent directory, we need to see if there are any real directories we can pop. Else, we
361
+ // have an excess of parents, and we'll need to keep the "..".
362
+ if (piece === '..') {
363
+ if (positive) {
364
+ addTrailingSlash = true;
365
+ positive--;
366
+ pointer--;
367
+ }
368
+ else if (rel) {
369
+ // If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
370
+ // URL, protocol relative URL, or an absolute path, we don't need to keep excess.
371
+ pieces[pointer++] = piece;
372
+ }
373
+ continue;
374
+ }
375
+ // We've encountered a real directory. Move it to the next insertion pointer, which accounts for
376
+ // any popped or dropped directories.
377
+ pieces[pointer++] = piece;
378
+ positive++;
379
+ }
380
+ let path = '';
381
+ for (let i = 1; i < pointer; i++) {
382
+ path += '/' + pieces[i];
383
+ }
384
+ if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
385
+ path += '/';
386
+ }
387
+ url.path = path;
388
+ }
389
+ /**
390
+ * Attempts to resolve `input` URL/path relative to `base`.
391
+ */
392
+ function resolve(input, base) {
393
+ if (!input && !base)
394
+ return '';
395
+ const url = parseUrl(input);
396
+ let inputType = url.type;
397
+ if (base && inputType !== 7 /* Absolute */) {
398
+ const baseUrl = parseUrl(base);
399
+ const baseType = baseUrl.type;
400
+ switch (inputType) {
401
+ case 1 /* Empty */:
402
+ url.hash = baseUrl.hash;
403
+ // fall through
404
+ case 2 /* Hash */:
405
+ url.query = baseUrl.query;
406
+ // fall through
407
+ case 3 /* Query */:
408
+ case 4 /* RelativePath */:
409
+ mergePaths(url, baseUrl);
410
+ // fall through
411
+ case 5 /* AbsolutePath */:
412
+ // The host, user, and port are joined, you can't copy one without the others.
413
+ url.user = baseUrl.user;
414
+ url.host = baseUrl.host;
415
+ url.port = baseUrl.port;
416
+ // fall through
417
+ case 6 /* SchemeRelative */:
418
+ // The input doesn't have a schema at least, so we need to copy at least that over.
419
+ url.scheme = baseUrl.scheme;
420
+ }
421
+ if (baseType > inputType)
422
+ inputType = baseType;
423
+ }
424
+ normalizePath(url, inputType);
425
+ const queryHash = url.query + url.hash;
426
+ switch (inputType) {
427
+ // This is impossible, because of the empty checks at the start of the function.
428
+ // case UrlType.Empty:
429
+ case 2 /* Hash */:
430
+ case 3 /* Query */:
431
+ return queryHash;
432
+ case 4 /* RelativePath */: {
433
+ // The first char is always a "/", and we need it to be relative.
434
+ const path = url.path.slice(1);
435
+ if (!path)
436
+ return queryHash || '.';
437
+ if (isRelative(base || input) && !isRelative(path)) {
438
+ // If base started with a leading ".", or there is no base and input started with a ".",
439
+ // then we need to ensure that the relative path starts with a ".". We don't know if
440
+ // relative starts with a "..", though, so check before prepending.
441
+ return './' + path + queryHash;
442
+ }
443
+ return path + queryHash;
444
+ }
445
+ case 5 /* AbsolutePath */:
446
+ return url.path + queryHash;
447
+ default:
448
+ return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
449
+ }
450
+ }
451
+
452
+ // src/trace-mapping.ts
453
+
454
+ // src/strip-filename.ts
455
+ function stripFilename(path) {
456
+ if (!path) return "";
457
+ const index = path.lastIndexOf("/");
458
+ return path.slice(0, index + 1);
459
+ }
460
+
461
+ // src/resolve.ts
462
+ function resolver(mapUrl, sourceRoot) {
463
+ const from = stripFilename(mapUrl);
464
+ const prefix = sourceRoot ? sourceRoot + "/" : "";
465
+ return (source) => resolve(prefix + (source || ""), from);
466
+ }
467
+
468
+ // src/sourcemap-segment.ts
469
+ var COLUMN = 0;
470
+ var SOURCES_INDEX = 1;
471
+ var SOURCE_LINE = 2;
472
+ var SOURCE_COLUMN = 3;
473
+ var NAMES_INDEX = 4;
474
+ var REV_GENERATED_LINE = 1;
475
+ var REV_GENERATED_COLUMN = 2;
476
+
477
+ // src/sort.ts
478
+ function maybeSort(mappings, owned) {
479
+ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
480
+ if (unsortedIndex === mappings.length) return mappings;
481
+ if (!owned) mappings = mappings.slice();
482
+ for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
483
+ mappings[i] = sortSegments(mappings[i], owned);
484
+ }
485
+ return mappings;
486
+ }
487
+ function nextUnsortedSegmentLine(mappings, start) {
488
+ for (let i = start; i < mappings.length; i++) {
489
+ if (!isSorted(mappings[i])) return i;
490
+ }
491
+ return mappings.length;
492
+ }
493
+ function isSorted(line) {
494
+ for (let j = 1; j < line.length; j++) {
495
+ if (line[j][COLUMN] < line[j - 1][COLUMN]) {
496
+ return false;
497
+ }
498
+ }
499
+ return true;
500
+ }
501
+ function sortSegments(line, owned) {
502
+ if (!owned) line = line.slice();
503
+ return line.sort(sortComparator);
504
+ }
505
+ function sortComparator(a, b) {
506
+ return a[COLUMN] - b[COLUMN];
507
+ }
508
+
509
+ // src/by-source.ts
510
+ function buildBySources(decoded, memos) {
511
+ const sources = memos.map(() => []);
512
+ for (let i = 0; i < decoded.length; i++) {
513
+ const line = decoded[i];
514
+ for (let j = 0; j < line.length; j++) {
515
+ const seg = line[j];
516
+ if (seg.length === 1) continue;
517
+ const sourceIndex2 = seg[SOURCES_INDEX];
518
+ const sourceLine = seg[SOURCE_LINE];
519
+ const sourceColumn = seg[SOURCE_COLUMN];
520
+ const source = sources[sourceIndex2];
521
+ const segs = source[sourceLine] || (source[sourceLine] = []);
522
+ segs.push([sourceColumn, i, seg[COLUMN]]);
523
+ }
524
+ }
525
+ for (let i = 0; i < sources.length; i++) {
526
+ const source = sources[i];
527
+ for (let j = 0; j < source.length; j++) {
528
+ const line = source[j];
529
+ if (line) line.sort(sortComparator);
530
+ }
531
+ }
532
+ return sources;
533
+ }
534
+
535
+ // src/binary-search.ts
536
+ var found = false;
537
+ function binarySearch(haystack, needle, low, high) {
538
+ while (low <= high) {
539
+ const mid = low + (high - low >> 1);
540
+ const cmp = haystack[mid][COLUMN] - needle;
541
+ if (cmp === 0) {
542
+ found = true;
543
+ return mid;
544
+ }
545
+ if (cmp < 0) {
546
+ low = mid + 1;
547
+ } else {
548
+ high = mid - 1;
549
+ }
550
+ }
551
+ found = false;
552
+ return low - 1;
553
+ }
554
+ function upperBound(haystack, needle, index) {
555
+ for (let i = index + 1; i < haystack.length; index = i++) {
556
+ if (haystack[i][COLUMN] !== needle) break;
557
+ }
558
+ return index;
559
+ }
560
+ function lowerBound(haystack, needle, index) {
561
+ for (let i = index - 1; i >= 0; index = i--) {
562
+ if (haystack[i][COLUMN] !== needle) break;
563
+ }
564
+ return index;
565
+ }
566
+ function memoizedState() {
567
+ return {
568
+ lastKey: -1,
569
+ lastNeedle: -1,
570
+ lastIndex: -1
571
+ };
572
+ }
573
+ function memoizedBinarySearch(haystack, needle, state, key) {
574
+ const { lastKey, lastNeedle, lastIndex } = state;
575
+ let low = 0;
576
+ let high = haystack.length - 1;
577
+ if (key === lastKey) {
578
+ if (needle === lastNeedle) {
579
+ found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
580
+ return lastIndex;
581
+ }
582
+ if (needle >= lastNeedle) {
583
+ low = lastIndex === -1 ? 0 : lastIndex;
584
+ } else {
585
+ high = lastIndex;
586
+ }
587
+ }
588
+ state.lastKey = key;
589
+ state.lastNeedle = needle;
590
+ return state.lastIndex = binarySearch(haystack, needle, low, high);
591
+ }
592
+
593
+ // src/types.ts
594
+ function parse(map) {
595
+ return typeof map === "string" ? JSON.parse(map) : map;
596
+ }
597
+
598
+ // src/trace-mapping.ts
599
+ var LINE_GTR_ZERO = "`line` must be greater than 0 (lines start at line 1)";
600
+ var COL_GTR_EQ_ZERO = "`column` must be greater than or equal to 0 (columns start at column 0)";
601
+ var LEAST_UPPER_BOUND = -1;
602
+ var GREATEST_LOWER_BOUND = 1;
603
+ var TraceMap = class {
604
+ constructor(map, mapUrl) {
605
+ const isString = typeof map === "string";
606
+ if (!isString && map._decodedMemo) return map;
607
+ const parsed = parse(map);
608
+ const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
609
+ this.version = version;
610
+ this.file = file;
611
+ this.names = names || [];
612
+ this.sourceRoot = sourceRoot;
613
+ this.sources = sources;
614
+ this.sourcesContent = sourcesContent;
615
+ this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || void 0;
616
+ const resolve = resolver(mapUrl, sourceRoot);
617
+ this.resolvedSources = sources.map(resolve);
618
+ const { mappings } = parsed;
619
+ if (typeof mappings === "string") {
620
+ this._encoded = mappings;
621
+ this._decoded = void 0;
622
+ } else if (Array.isArray(mappings)) {
623
+ this._encoded = void 0;
624
+ this._decoded = maybeSort(mappings, isString);
625
+ } else if (parsed.sections) {
626
+ throw new Error(`TraceMap passed sectioned source map, please use FlattenMap export instead`);
627
+ } else {
628
+ throw new Error(`invalid source map: ${JSON.stringify(parsed)}`);
629
+ }
630
+ this._decodedMemo = memoizedState();
631
+ this._bySources = void 0;
632
+ this._bySourceMemos = void 0;
633
+ }
634
+ };
635
+ function cast(map) {
636
+ return map;
637
+ }
638
+ function decodedMappings(map) {
639
+ var _a;
640
+ return (_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded));
641
+ }
642
+ function originalPositionFor(map, needle) {
643
+ let { line, column, bias } = needle;
644
+ line--;
645
+ if (line < 0) throw new Error(LINE_GTR_ZERO);
646
+ if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
647
+ const decoded = decodedMappings(map);
648
+ if (line >= decoded.length) return OMapping(null, null, null, null);
649
+ const segments = decoded[line];
650
+ const index = traceSegmentInternal(
651
+ segments,
652
+ cast(map)._decodedMemo,
653
+ line,
654
+ column,
655
+ bias || GREATEST_LOWER_BOUND
656
+ );
657
+ if (index === -1) return OMapping(null, null, null, null);
658
+ const segment = segments[index];
659
+ if (segment.length === 1) return OMapping(null, null, null, null);
660
+ const { names, resolvedSources } = map;
661
+ return OMapping(
662
+ resolvedSources[segment[SOURCES_INDEX]],
663
+ segment[SOURCE_LINE] + 1,
664
+ segment[SOURCE_COLUMN],
665
+ segment.length === 5 ? names[segment[NAMES_INDEX]] : null
666
+ );
667
+ }
668
+ function generatedPositionFor(map, needle) {
669
+ const { source, line, column, bias } = needle;
670
+ return generatedPosition(map, source, line, column, bias || GREATEST_LOWER_BOUND, false);
671
+ }
672
+ function eachMapping(map, cb) {
673
+ const decoded = decodedMappings(map);
674
+ const { names, resolvedSources } = map;
675
+ for (let i = 0; i < decoded.length; i++) {
676
+ const line = decoded[i];
677
+ for (let j = 0; j < line.length; j++) {
678
+ const seg = line[j];
679
+ const generatedLine = i + 1;
680
+ const generatedColumn = seg[0];
681
+ let source = null;
682
+ let originalLine = null;
683
+ let originalColumn = null;
684
+ let name = null;
685
+ if (seg.length !== 1) {
686
+ source = resolvedSources[seg[1]];
687
+ originalLine = seg[2] + 1;
688
+ originalColumn = seg[3];
689
+ }
690
+ if (seg.length === 5) name = names[seg[4]];
691
+ cb({
692
+ generatedLine,
693
+ generatedColumn,
694
+ source,
695
+ originalLine,
696
+ originalColumn,
697
+ name
698
+ });
699
+ }
700
+ }
701
+ }
702
+ function OMapping(source, line, column, name) {
703
+ return { source, line, column, name };
704
+ }
705
+ function GMapping(line, column) {
706
+ return { line, column };
707
+ }
708
+ function traceSegmentInternal(segments, memo, line, column, bias) {
709
+ let index = memoizedBinarySearch(segments, column, memo, line);
710
+ if (found) {
711
+ index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
712
+ } else if (bias === LEAST_UPPER_BOUND) index++;
713
+ if (index === -1 || index === segments.length) return -1;
714
+ return index;
715
+ }
716
+ function generatedPosition(map, source, line, column, bias, all) {
717
+ var _a, _b;
718
+ line--;
719
+ if (line < 0) throw new Error(LINE_GTR_ZERO);
720
+ if (column < 0) throw new Error(COL_GTR_EQ_ZERO);
721
+ const { sources, resolvedSources } = map;
722
+ let sourceIndex2 = sources.indexOf(source);
723
+ if (sourceIndex2 === -1) sourceIndex2 = resolvedSources.indexOf(source);
724
+ if (sourceIndex2 === -1) return all ? [] : GMapping(null, null);
725
+ const bySourceMemos = (_a = cast(map))._bySourceMemos || (_a._bySourceMemos = sources.map(memoizedState));
726
+ const generated = (_b = cast(map))._bySources || (_b._bySources = buildBySources(decodedMappings(map), bySourceMemos));
727
+ const segments = generated[sourceIndex2][line];
728
+ if (segments == null) return all ? [] : GMapping(null, null);
729
+ const memo = bySourceMemos[sourceIndex2];
730
+ const index = traceSegmentInternal(segments, memo, line, column, bias);
731
+ if (index === -1) return GMapping(null, null);
732
+ const segment = segments[index];
733
+ return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
734
+ }
735
+
126
736
  // AST walker module for ESTree compatible trees
127
737
 
128
738
 
@@ -459,7 +1069,7 @@ async function collectTests(ctx, filepath) {
459
1069
  if (callee.type === "CallExpression") start = callee.end;
460
1070
  else if (callee.type === "TaggedTemplateExpression") start = callee.end + 1;
461
1071
  else start = node.start;
462
- const { arguments: [messageNode] } = node, isQuoted = messageNode?.type === "Literal" || messageNode?.type === "TemplateLiteral", message = isQuoted ? request.code.slice(messageNode.start + 1, messageNode.end - 1) : request.code.slice(messageNode.start, messageNode.end);
1072
+ const { arguments: [messageNode] } = node, message = messageNode?.type === "Literal" || messageNode?.type === "TemplateLiteral" ? request.code.slice(messageNode.start + 1, messageNode.end - 1) : request.code.slice(messageNode.start, messageNode.end);
463
1073
  // cannot statically analyze, so we always skip it
464
1074
  if (mode === "skipIf" || mode === "runIf") mode = "skip";
465
1075
  definitions.push({
@@ -547,13 +1157,13 @@ async function makeTscErrorInfo(errInfo) {
547
1157
  }];
548
1158
  }
549
1159
  async function getRawErrsMapFromTsCompile(tscErrorStdout) {
550
- const rawErrsMap = /* @__PURE__ */ new Map(), infos = await Promise.all(tscErrorStdout.split(newLineRegExp).reduce((prev, next) => {
1160
+ const rawErrsMap = /* @__PURE__ */ new Map();
1161
+ return (await Promise.all(tscErrorStdout.split(newLineRegExp).reduce((prev, next) => {
551
1162
  if (!next) return prev;
552
- if (!next.startsWith(" ")) prev.push(next);
1163
+ if (next[0] !== " ") prev.push(next);
553
1164
  else prev[prev.length - 1] += `\n${next}`;
554
1165
  return prev;
555
- }, []).map((errInfoLine) => makeTscErrorInfo(errInfoLine)));
556
- return infos.forEach(([errFilePath, errInfo]) => {
1166
+ }, []).map((errInfoLine) => makeTscErrorInfo(errInfoLine)))).forEach(([errFilePath, errInfo]) => {
557
1167
  if (errInfo) if (!rawErrsMap.has(errFilePath)) rawErrsMap.set(errFilePath, [errInfo]);
558
1168
  else rawErrsMap.get(errFilePath)?.push(errInfo);
559
1169
  }), rawErrsMap;
@@ -663,7 +1273,7 @@ class Typechecker {
663
1273
  async parseTscLikeOutput(output) {
664
1274
  const errorsMap = await getRawErrsMapFromTsCompile(output), typesErrors = /* @__PURE__ */ new Map();
665
1275
  return errorsMap.forEach((errors, path) => {
666
- const filepath = resolve(this.project.config.root, path), suiteErrors = errors.map((info) => {
1276
+ const filepath = resolve$1(this.project.config.root, path), suiteErrors = errors.map((info) => {
667
1277
  const limit = Error.stackTraceLimit;
668
1278
  Error.stackTraceLimit = 0;
669
1279
  // Some expect-type errors have the most useful information on the second line e.g. `This expression is not callable.\n Type 'ExpectString<number>' has no call signatures.`
@@ -712,7 +1322,7 @@ class Typechecker {
712
1322
  // use builtin watcher because it's faster
713
1323
  if (watch) args.push("--watch");
714
1324
  if (typecheck.allowJs) args.push("--allowJs", "--checkJs");
715
- if (typecheck.tsconfig) args.push("-p", resolve(root, typecheck.tsconfig));
1325
+ if (typecheck.tsconfig) args.push("-p", resolve$1(root, typecheck.tsconfig));
716
1326
  this._output = "", this._startTime = performance.now();
717
1327
  const child = x(typecheck.checker, args, {
718
1328
  nodeOptions: {
@@ -802,4 +1412,4 @@ function findGeneratedPosition(traceMap, { line, column, source }) {
802
1412
  };
803
1413
  }
804
1414
 
805
- export { TypeCheckError as T, Typechecker as a, ancestor as b, createDefinesScript as c, convertTasksToEvents as d, getOutputFile as g, hasFailedSnapshot as h, wrapSerializableConfig as w };
1415
+ export { TypeCheckError as T, Typechecker as a, TraceMap as b, ancestor as c, createDefinesScript as d, convertTasksToEvents as e, getOutputFile as g, hasFailedSnapshot as h, originalPositionFor as o, wrapSerializableConfig as w };