@vitest/utils 3.1.0-beta.1 → 3.1.0

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/index.js CHANGED
@@ -508,144 +508,124 @@ function highlight$1(code, options = { jsx: false, colors: {} }) {
508
508
  return code && highlightTokens(options.colors || {}, code, options.jsx);
509
509
  }
510
510
 
511
- function getDefs(c2) {
512
- const Invalid = (text) => c2.white(c2.bgRed(c2.bold(text)));
513
- return {
514
- Keyword: c2.magenta,
515
- IdentifierCapitalized: c2.yellow,
516
- Punctuator: c2.yellow,
517
- StringLiteral: c2.green,
518
- NoSubstitutionTemplate: c2.green,
519
- MultiLineComment: c2.gray,
520
- SingleLineComment: c2.gray,
521
- RegularExpressionLiteral: c2.cyan,
522
- NumericLiteral: c2.blue,
523
- TemplateHead: (text) => c2.green(text.slice(0, text.length - 2)) + c2.cyan(text.slice(-2)),
524
- TemplateTail: (text) => c2.cyan(text.slice(0, 1)) + c2.green(text.slice(1)),
525
- TemplateMiddle: (text) => c2.cyan(text.slice(0, 1)) + c2.green(text.slice(1, text.length - 2)) + c2.cyan(text.slice(-2)),
526
- IdentifierCallable: c2.blue,
527
- PrivateIdentifierCallable: (text) => `#${c2.blue(text.slice(1))}`,
528
- Invalid,
529
- JSXString: c2.green,
530
- JSXIdentifier: c2.yellow,
531
- JSXInvalid: Invalid,
532
- JSXPunctuator: c2.yellow
533
- };
511
+ function getDefs(c) {
512
+ const Invalid = (text) => c.white(c.bgRed(c.bold(text)));
513
+ return {
514
+ Keyword: c.magenta,
515
+ IdentifierCapitalized: c.yellow,
516
+ Punctuator: c.yellow,
517
+ StringLiteral: c.green,
518
+ NoSubstitutionTemplate: c.green,
519
+ MultiLineComment: c.gray,
520
+ SingleLineComment: c.gray,
521
+ RegularExpressionLiteral: c.cyan,
522
+ NumericLiteral: c.blue,
523
+ TemplateHead: (text) => c.green(text.slice(0, text.length - 2)) + c.cyan(text.slice(-2)),
524
+ TemplateTail: (text) => c.cyan(text.slice(0, 1)) + c.green(text.slice(1)),
525
+ TemplateMiddle: (text) => c.cyan(text.slice(0, 1)) + c.green(text.slice(1, text.length - 2)) + c.cyan(text.slice(-2)),
526
+ IdentifierCallable: c.blue,
527
+ PrivateIdentifierCallable: (text) => `#${c.blue(text.slice(1))}`,
528
+ Invalid,
529
+ JSXString: c.green,
530
+ JSXIdentifier: c.yellow,
531
+ JSXInvalid: Invalid,
532
+ JSXPunctuator: c.yellow
533
+ };
534
534
  }
535
535
  function highlight(code, options = { jsx: false }) {
536
- return highlight$1(code, {
537
- jsx: options.jsx,
538
- colors: getDefs(options.colors || c)
539
- });
536
+ return highlight$1(code, {
537
+ jsx: options.jsx,
538
+ colors: getDefs(options.colors || c)
539
+ });
540
540
  }
541
541
 
542
542
  const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
543
543
  function nanoid(size = 21) {
544
- let id = "";
545
- let i = size;
546
- while (i--) {
547
- id += urlAlphabet[Math.random() * 64 | 0];
548
- }
549
- return id;
544
+ let id = "";
545
+ let i = size;
546
+ while (i--) {
547
+ id += urlAlphabet[Math.random() * 64 | 0];
548
+ }
549
+ return id;
550
550
  }
551
551
 
552
552
  const lineSplitRE = /\r?\n/;
553
553
  function positionToOffset(source, lineNumber, columnNumber) {
554
- const lines = source.split(lineSplitRE);
555
- const nl = /\r\n/.test(source) ? 2 : 1;
556
- let start = 0;
557
- if (lineNumber > lines.length) {
558
- return source.length;
559
- }
560
- for (let i = 0; i < lineNumber - 1; i++) {
561
- start += lines[i].length + nl;
562
- }
563
- return start + columnNumber;
554
+ const lines = source.split(lineSplitRE);
555
+ const nl = /\r\n/.test(source) ? 2 : 1;
556
+ let start = 0;
557
+ if (lineNumber > lines.length) {
558
+ return source.length;
559
+ }
560
+ for (let i = 0; i < lineNumber - 1; i++) {
561
+ start += lines[i].length + nl;
562
+ }
563
+ return start + columnNumber;
564
564
  }
565
565
  function offsetToLineNumber(source, offset) {
566
- if (offset > source.length) {
567
- throw new Error(
568
- `offset is longer than source length! offset ${offset} > length ${source.length}`
569
- );
570
- }
571
- const lines = source.split(lineSplitRE);
572
- const nl = /\r\n/.test(source) ? 2 : 1;
573
- let counted = 0;
574
- let line = 0;
575
- for (; line < lines.length; line++) {
576
- const lineLength = lines[line].length + nl;
577
- if (counted + lineLength >= offset) {
578
- break;
579
- }
580
- counted += lineLength;
581
- }
582
- return line + 1;
566
+ if (offset > source.length) {
567
+ throw new Error(`offset is longer than source length! offset ${offset} > length ${source.length}`);
568
+ }
569
+ const lines = source.split(lineSplitRE);
570
+ const nl = /\r\n/.test(source) ? 2 : 1;
571
+ let counted = 0;
572
+ let line = 0;
573
+ for (; line < lines.length; line++) {
574
+ const lineLength = lines[line].length + nl;
575
+ if (counted + lineLength >= offset) {
576
+ break;
577
+ }
578
+ counted += lineLength;
579
+ }
580
+ return line + 1;
583
581
  }
584
582
 
585
583
  const RealDate = Date;
586
584
  function random(seed) {
587
- const x = Math.sin(seed++) * 1e4;
588
- return x - Math.floor(x);
585
+ const x = Math.sin(seed++) * 1e4;
586
+ return x - Math.floor(x);
589
587
  }
590
588
  function shuffle(array, seed = RealDate.now()) {
591
- let length = array.length;
592
- while (length) {
593
- const index = Math.floor(random(seed) * length--);
594
- const previous = array[length];
595
- array[length] = array[index];
596
- array[index] = previous;
597
- ++seed;
598
- }
599
- return array;
589
+ let length = array.length;
590
+ while (length) {
591
+ const index = Math.floor(random(seed) * length--);
592
+ const previous = array[length];
593
+ array[length] = array[index];
594
+ array[index] = previous;
595
+ ++seed;
596
+ }
597
+ return array;
600
598
  }
601
599
 
602
600
  const SAFE_TIMERS_SYMBOL = Symbol("vitest:SAFE_TIMERS");
603
601
  function getSafeTimers() {
604
- const {
605
- setTimeout: safeSetTimeout,
606
- setInterval: safeSetInterval,
607
- clearInterval: safeClearInterval,
608
- clearTimeout: safeClearTimeout,
609
- setImmediate: safeSetImmediate,
610
- clearImmediate: safeClearImmediate,
611
- queueMicrotask: safeQueueMicrotask
612
- } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis;
613
- const { nextTick: safeNextTick } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
614
- return {
615
- nextTick: safeNextTick,
616
- setTimeout: safeSetTimeout,
617
- setInterval: safeSetInterval,
618
- clearInterval: safeClearInterval,
619
- clearTimeout: safeClearTimeout,
620
- setImmediate: safeSetImmediate,
621
- clearImmediate: safeClearImmediate,
622
- queueMicrotask: safeQueueMicrotask
623
- };
602
+ const { setTimeout: safeSetTimeout, setInterval: safeSetInterval, clearInterval: safeClearInterval, clearTimeout: safeClearTimeout, setImmediate: safeSetImmediate, clearImmediate: safeClearImmediate, queueMicrotask: safeQueueMicrotask } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis;
603
+ const { nextTick: safeNextTick } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
604
+ return {
605
+ nextTick: safeNextTick,
606
+ setTimeout: safeSetTimeout,
607
+ setInterval: safeSetInterval,
608
+ clearInterval: safeClearInterval,
609
+ clearTimeout: safeClearTimeout,
610
+ setImmediate: safeSetImmediate,
611
+ clearImmediate: safeClearImmediate,
612
+ queueMicrotask: safeQueueMicrotask
613
+ };
624
614
  }
625
615
  function setSafeTimers() {
626
- const {
627
- setTimeout: safeSetTimeout,
628
- setInterval: safeSetInterval,
629
- clearInterval: safeClearInterval,
630
- clearTimeout: safeClearTimeout,
631
- setImmediate: safeSetImmediate,
632
- clearImmediate: safeClearImmediate,
633
- queueMicrotask: safeQueueMicrotask
634
- } = globalThis;
635
- const { nextTick: safeNextTick } = globalThis.process || {
636
- nextTick: (cb) => cb()
637
- };
638
- const timers = {
639
- nextTick: safeNextTick,
640
- setTimeout: safeSetTimeout,
641
- setInterval: safeSetInterval,
642
- clearInterval: safeClearInterval,
643
- clearTimeout: safeClearTimeout,
644
- setImmediate: safeSetImmediate,
645
- clearImmediate: safeClearImmediate,
646
- queueMicrotask: safeQueueMicrotask
647
- };
648
- globalThis[SAFE_TIMERS_SYMBOL] = timers;
616
+ const { setTimeout: safeSetTimeout, setInterval: safeSetInterval, clearInterval: safeClearInterval, clearTimeout: safeClearTimeout, setImmediate: safeSetImmediate, clearImmediate: safeClearImmediate, queueMicrotask: safeQueueMicrotask } = globalThis;
617
+ const { nextTick: safeNextTick } = globalThis.process || { nextTick: (cb) => cb() };
618
+ const timers = {
619
+ nextTick: safeNextTick,
620
+ setTimeout: safeSetTimeout,
621
+ setInterval: safeSetInterval,
622
+ clearInterval: safeClearInterval,
623
+ clearTimeout: safeClearTimeout,
624
+ setImmediate: safeSetImmediate,
625
+ clearImmediate: safeClearImmediate,
626
+ queueMicrotask: safeQueueMicrotask
627
+ };
628
+ globalThis[SAFE_TIMERS_SYMBOL] = timers;
649
629
  }
650
630
 
651
631
  export { getSafeTimers, highlight, lineSplitRE, nanoid, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle };
@@ -133,4 +133,5 @@ declare function createStackString(stacks: ParsedStack[]): string;
133
133
  declare function parseStacktrace(stack: string, options?: StackTraceParserOptions): ParsedStack[];
134
134
  declare function parseErrorStacktrace(e: ErrorWithDiff, options?: StackTraceParserOptions): ParsedStack[];
135
135
 
136
- export { type EachMapping, type SourceMapInput, type StackTraceParserOptions, TraceMap, createStackString, eachMapping, generatedPositionFor, originalPositionFor, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
136
+ export { TraceMap, createStackString, eachMapping, generatedPositionFor, originalPositionFor, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
137
+ export type { EachMapping, SourceMapInput, StackTraceParserOptions };
@@ -786,192 +786,195 @@ const isAbsolute = function(p) {
786
786
  const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
787
787
  const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
788
788
  const stackIgnorePatterns = [
789
- "node:internal",
790
- /\/packages\/\w+\/dist\//,
791
- /\/@vitest\/\w+\/dist\//,
792
- "/vitest/dist/",
793
- "/vitest/src/",
794
- "/vite-node/dist/",
795
- "/vite-node/src/",
796
- "/node_modules/chai/",
797
- "/node_modules/tinypool/",
798
- "/node_modules/tinyspy/",
799
- // browser related deps
800
- "/deps/chunk-",
801
- "/deps/@vitest",
802
- "/deps/loupe",
803
- "/deps/chai",
804
- /node:\w+/,
805
- /__vitest_test__/,
806
- /__vitest_browser__/,
807
- /\/deps\/vitest_/
789
+ "node:internal",
790
+ /\/packages\/\w+\/dist\//,
791
+ /\/@vitest\/\w+\/dist\//,
792
+ "/vitest/dist/",
793
+ "/vitest/src/",
794
+ "/vite-node/dist/",
795
+ "/vite-node/src/",
796
+ "/node_modules/chai/",
797
+ "/node_modules/tinypool/",
798
+ "/node_modules/tinyspy/",
799
+ "/deps/chunk-",
800
+ "/deps/@vitest",
801
+ "/deps/loupe",
802
+ "/deps/chai",
803
+ /node:\w+/,
804
+ /__vitest_test__/,
805
+ /__vitest_browser__/,
806
+ /\/deps\/vitest_/
808
807
  ];
809
808
  function extractLocation(urlLike) {
810
- if (!urlLike.includes(":")) {
811
- return [urlLike];
812
- }
813
- const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
814
- const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
815
- if (!parts) {
816
- return [urlLike];
817
- }
818
- let url = parts[1];
819
- if (url.startsWith("async ")) {
820
- url = url.slice(6);
821
- }
822
- if (url.startsWith("http:") || url.startsWith("https:")) {
823
- const urlObj = new URL(url);
824
- urlObj.searchParams.delete("import");
825
- urlObj.searchParams.delete("browserv");
826
- url = urlObj.pathname + urlObj.hash + urlObj.search;
827
- }
828
- if (url.startsWith("/@fs/")) {
829
- const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
830
- url = url.slice(isWindows ? 5 : 4);
831
- }
832
- return [url, parts[2] || void 0, parts[3] || void 0];
809
+ if (!urlLike.includes(":")) {
810
+ return [urlLike];
811
+ }
812
+ const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
813
+ const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
814
+ if (!parts) {
815
+ return [urlLike];
816
+ }
817
+ let url = parts[1];
818
+ if (url.startsWith("async ")) {
819
+ url = url.slice(6);
820
+ }
821
+ if (url.startsWith("http:") || url.startsWith("https:")) {
822
+ const urlObj = new URL(url);
823
+ urlObj.searchParams.delete("import");
824
+ urlObj.searchParams.delete("browserv");
825
+ url = urlObj.pathname + urlObj.hash + urlObj.search;
826
+ }
827
+ if (url.startsWith("/@fs/")) {
828
+ const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
829
+ url = url.slice(isWindows ? 5 : 4);
830
+ }
831
+ return [
832
+ url,
833
+ parts[2] || undefined,
834
+ parts[3] || undefined
835
+ ];
833
836
  }
834
837
  function parseSingleFFOrSafariStack(raw) {
835
- let line = raw.trim();
836
- if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
837
- return null;
838
- }
839
- if (line.includes(" > eval")) {
840
- line = line.replace(
841
- / line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
842
- ":$1"
843
- );
844
- }
845
- if (!line.includes("@") && !line.includes(":")) {
846
- return null;
847
- }
848
- const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
849
- const matches = line.match(functionNameRegex);
850
- const functionName = matches && matches[1] ? matches[1] : void 0;
851
- const [url, lineNumber, columnNumber] = extractLocation(
852
- line.replace(functionNameRegex, "")
853
- );
854
- if (!url || !lineNumber || !columnNumber) {
855
- return null;
856
- }
857
- return {
858
- file: url,
859
- method: functionName || "",
860
- line: Number.parseInt(lineNumber),
861
- column: Number.parseInt(columnNumber)
862
- };
838
+ let line = raw.trim();
839
+ if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
840
+ return null;
841
+ }
842
+ if (line.includes(" > eval")) {
843
+ line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
844
+ }
845
+ if (!line.includes("@") && !line.includes(":")) {
846
+ return null;
847
+ }
848
+ const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
849
+ const matches = line.match(functionNameRegex);
850
+ const functionName = matches && matches[1] ? matches[1] : undefined;
851
+ const [url, lineNumber, columnNumber] = extractLocation(line.replace(functionNameRegex, ""));
852
+ if (!url || !lineNumber || !columnNumber) {
853
+ return null;
854
+ }
855
+ return {
856
+ file: url,
857
+ method: functionName || "",
858
+ line: Number.parseInt(lineNumber),
859
+ column: Number.parseInt(columnNumber)
860
+ };
863
861
  }
864
862
  function parseSingleStack(raw) {
865
- const line = raw.trim();
866
- if (!CHROME_IE_STACK_REGEXP.test(line)) {
867
- return parseSingleFFOrSafariStack(line);
868
- }
869
- return parseSingleV8Stack(line);
863
+ const line = raw.trim();
864
+ if (!CHROME_IE_STACK_REGEXP.test(line)) {
865
+ return parseSingleFFOrSafariStack(line);
866
+ }
867
+ return parseSingleV8Stack(line);
870
868
  }
871
869
  function parseSingleV8Stack(raw) {
872
- let line = raw.trim();
873
- if (!CHROME_IE_STACK_REGEXP.test(line)) {
874
- return null;
875
- }
876
- if (line.includes("(eval ")) {
877
- line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
878
- }
879
- let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
880
- const location = sanitizedLine.match(/ (\(.+\)$)/);
881
- sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
882
- const [url, lineNumber, columnNumber] = extractLocation(
883
- location ? location[1] : sanitizedLine
884
- );
885
- let method = location && sanitizedLine || "";
886
- let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
887
- if (!file || !lineNumber || !columnNumber) {
888
- return null;
889
- }
890
- if (method.startsWith("async ")) {
891
- method = method.slice(6);
892
- }
893
- if (file.startsWith("file://")) {
894
- file = file.slice(7);
895
- }
896
- file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve(file);
897
- if (method) {
898
- method = method.replace(/__vite_ssr_import_\d+__\./g, "");
899
- }
900
- return {
901
- method,
902
- file,
903
- line: Number.parseInt(lineNumber),
904
- column: Number.parseInt(columnNumber)
905
- };
870
+ let line = raw.trim();
871
+ if (!CHROME_IE_STACK_REGEXP.test(line)) {
872
+ return null;
873
+ }
874
+ if (line.includes("(eval ")) {
875
+ line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
876
+ }
877
+ let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
878
+ const location = sanitizedLine.match(/ (\(.+\)$)/);
879
+ sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
880
+ const [url, lineNumber, columnNumber] = extractLocation(location ? location[1] : sanitizedLine);
881
+ let method = location && sanitizedLine || "";
882
+ let file = url && ["eval", "<anonymous>"].includes(url) ? undefined : url;
883
+ if (!file || !lineNumber || !columnNumber) {
884
+ return null;
885
+ }
886
+ if (method.startsWith("async ")) {
887
+ method = method.slice(6);
888
+ }
889
+ if (file.startsWith("file://")) {
890
+ file = file.slice(7);
891
+ }
892
+ file = file.startsWith("node:") || file.startsWith("internal:") ? file : resolve(file);
893
+ if (method) {
894
+ method = method.replace(/__vite_ssr_import_\d+__\./g, "");
895
+ }
896
+ return {
897
+ method,
898
+ file,
899
+ line: Number.parseInt(lineNumber),
900
+ column: Number.parseInt(columnNumber)
901
+ };
906
902
  }
907
903
  function createStackString(stacks) {
908
- return stacks.map((stack) => {
909
- const line = `${stack.file}:${stack.line}:${stack.column}`;
910
- if (stack.method) {
911
- return ` at ${stack.method}(${line})`;
912
- }
913
- return ` at ${line}`;
914
- }).join("\n");
904
+ return stacks.map((stack) => {
905
+ const line = `${stack.file}:${stack.line}:${stack.column}`;
906
+ if (stack.method) {
907
+ return ` at ${stack.method}(${line})`;
908
+ }
909
+ return ` at ${line}`;
910
+ }).join("\n");
915
911
  }
916
912
  function parseStacktrace(stack, options = {}) {
917
- const { ignoreStackEntries = stackIgnorePatterns } = options;
918
- const stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
919
- return stacks.map((stack2) => {
920
- var _a;
921
- if (options.getUrlId) {
922
- stack2.file = options.getUrlId(stack2.file);
923
- }
924
- const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
925
- if (!map || typeof map !== "object" || !map.version) {
926
- return shouldFilter(ignoreStackEntries, stack2.file) ? null : stack2;
927
- }
928
- const traceMap = new TraceMap(map);
929
- const { line, column, source, name } = originalPositionFor(traceMap, stack2);
930
- let file = stack2.file;
931
- if (source) {
932
- const fileUrl = stack2.file.startsWith("file://") ? stack2.file : `file://${stack2.file}`;
933
- const sourceRootUrl = map.sourceRoot ? new URL(map.sourceRoot, fileUrl) : fileUrl;
934
- file = new URL(source, sourceRootUrl).pathname;
935
- }
936
- if (shouldFilter(ignoreStackEntries, file)) {
937
- return null;
938
- }
939
- if (line != null && column != null) {
940
- return {
941
- line,
942
- column,
943
- file,
944
- method: name || stack2.method
945
- };
946
- }
947
- return stack2;
948
- }).filter((s) => s != null);
913
+ const { ignoreStackEntries = stackIgnorePatterns } = options;
914
+ const stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
915
+ return stacks.map((stack) => {
916
+ var _options$getSourceMap;
917
+ if (options.getUrlId) {
918
+ stack.file = options.getUrlId(stack.file);
919
+ }
920
+ const map = (_options$getSourceMap = options.getSourceMap) === null || _options$getSourceMap === void 0 ? void 0 : _options$getSourceMap.call(options, stack.file);
921
+ if (!map || typeof map !== "object" || !map.version) {
922
+ return shouldFilter(ignoreStackEntries, stack.file) ? null : stack;
923
+ }
924
+ const traceMap = new TraceMap(map);
925
+ const { line, column, source, name } = originalPositionFor(traceMap, stack);
926
+ let file = stack.file;
927
+ if (source) {
928
+ const fileUrl = stack.file.startsWith("file://") ? stack.file : `file://${stack.file}`;
929
+ const sourceRootUrl = map.sourceRoot ? new URL(map.sourceRoot, fileUrl) : fileUrl;
930
+ file = new URL(source, sourceRootUrl).pathname;
931
+ }
932
+ if (shouldFilter(ignoreStackEntries, file)) {
933
+ return null;
934
+ }
935
+ if (line != null && column != null) {
936
+ return {
937
+ line,
938
+ column,
939
+ file,
940
+ method: name || stack.method
941
+ };
942
+ }
943
+ return stack;
944
+ }).filter((s) => s != null);
949
945
  }
950
946
  function shouldFilter(ignoreStackEntries, file) {
951
- return ignoreStackEntries.some((p) => file.match(p));
947
+ return ignoreStackEntries.some((p) => file.match(p));
952
948
  }
953
949
  function parseFFOrSafariStackTrace(stack) {
954
- return stack.split("\n").map((line) => parseSingleFFOrSafariStack(line)).filter(notNullish);
950
+ return stack.split("\n").map((line) => parseSingleFFOrSafariStack(line)).filter(notNullish);
955
951
  }
956
952
  function parseV8Stacktrace(stack) {
957
- return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
953
+ return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
958
954
  }
959
955
  function parseErrorStacktrace(e, options = {}) {
960
- if (!e || isPrimitive(e)) {
961
- return [];
962
- }
963
- if (e.stacks) {
964
- return e.stacks;
965
- }
966
- const stackStr = e.stack || e.stackStr || "";
967
- let stackFrames = parseStacktrace(stackStr, options);
968
- if (options.frameFilter) {
969
- stackFrames = stackFrames.filter(
970
- (f) => options.frameFilter(e, f) !== false
971
- );
972
- }
973
- e.stacks = stackFrames;
974
- return stackFrames;
956
+ if (!e || isPrimitive(e)) {
957
+ return [];
958
+ }
959
+ if (e.stacks) {
960
+ return e.stacks;
961
+ }
962
+ const stackStr = e.stack || e.stackStr || "";
963
+ let stackFrames = parseStacktrace(stackStr, options);
964
+ if (!stackFrames.length) {
965
+ const e_ = e;
966
+ if (e_.fileName != null && e_.lineNumber != null && e_.columnNumber != null) {
967
+ stackFrames = parseStacktrace(`${e_.fileName}:${e_.lineNumber}:${e_.columnNumber}`, options);
968
+ }
969
+ if (e_.sourceURL != null && e_.line != null && e_._column != null) {
970
+ stackFrames = parseStacktrace(`${e_.sourceURL}:${e_.line}:${e_.column}`, options);
971
+ }
972
+ }
973
+ if (options.frameFilter) {
974
+ stackFrames = stackFrames.filter((f) => options.frameFilter(e, f) !== false);
975
+ }
976
+ e.stacks = stackFrames;
977
+ return stackFrames;
975
978
  }
976
979
 
977
980
  export { TraceMap, createStackString, eachMapping, generatedPositionFor, originalPositionFor, parseErrorStacktrace, parseSingleFFOrSafariStack, parseSingleStack, parseSingleV8Stack, parseStacktrace };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vitest/utils",
3
3
  "type": "module",
4
- "version": "3.1.0-beta.1",
4
+ "version": "3.1.0",
5
5
  "description": "Shared Vitest utility functions",
6
6
  "license": "MIT",
7
7
  "funding": "https://opencollective.com/vitest",
@@ -62,11 +62,11 @@
62
62
  "dependencies": {
63
63
  "loupe": "^3.1.3",
64
64
  "tinyrainbow": "^2.0.0",
65
- "@vitest/pretty-format": "3.1.0-beta.1"
65
+ "@vitest/pretty-format": "3.1.0"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@jridgewell/trace-mapping": "^0.3.25",
69
- "@types/estree": "^1.0.6",
69
+ "@types/estree": "^1.0.7",
70
70
  "diff-sequences": "^29.6.3",
71
71
  "tinyhighlight": "^0.3.2"
72
72
  },