@vitest/utils 2.0.0-beta.1 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ast.js +16 -8
- package/dist/chunk-colors.js +8 -4
- package/dist/chunk-display.js +3 -2
- package/dist/diff.js +3 -2
- package/dist/helpers.d.ts +2 -1
- package/dist/helpers.js +10 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/source-map.js +14 -5
- package/package.json +5 -2
package/dist/ast.js
CHANGED
@@ -55,8 +55,9 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
55
55
|
enter(node, parent) {
|
56
56
|
if (node.type === "ImportDeclaration")
|
57
57
|
return this.skip();
|
58
|
-
if (parent && !(parent.type === "IfStatement" && node === parent.alternate))
|
58
|
+
if (parent && !(parent.type === "IfStatement" && node === parent.alternate)) {
|
59
59
|
parentStack.unshift(parent);
|
60
|
+
}
|
60
61
|
if (node.type === "VariableDeclaration")
|
61
62
|
varKindStack.unshift(node.kind);
|
62
63
|
if (node.type === "CallExpression")
|
@@ -82,14 +83,16 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
82
83
|
}
|
83
84
|
walk(p.type === "AssignmentPattern" ? p.left : p, {
|
84
85
|
enter(child, parent2) {
|
85
|
-
if ((parent2 == null ? void 0 : parent2.type) === "AssignmentPattern" && (parent2 == null ? void 0 : parent2.right) === child)
|
86
|
+
if ((parent2 == null ? void 0 : parent2.type) === "AssignmentPattern" && (parent2 == null ? void 0 : parent2.right) === child) {
|
86
87
|
return this.skip();
|
88
|
+
}
|
87
89
|
if (child.type !== "Identifier")
|
88
90
|
return;
|
89
91
|
if (isStaticPropertyKey(child, parent2))
|
90
92
|
return;
|
91
|
-
if ((parent2 == null ? void 0 : parent2.type) === "TemplateLiteral" && (parent2 == null ? void 0 : parent2.expressions.includes(child)) || (parent2 == null ? void 0 : parent2.type) === "CallExpression" && (parent2 == null ? void 0 : parent2.callee) === child)
|
93
|
+
if ((parent2 == null ? void 0 : parent2.type) === "TemplateLiteral" && (parent2 == null ? void 0 : parent2.expressions.includes(child)) || (parent2 == null ? void 0 : parent2.type) === "CallExpression" && (parent2 == null ? void 0 : parent2.callee) === child) {
|
92
94
|
return;
|
95
|
+
}
|
93
96
|
setScope(node, child.name);
|
94
97
|
}
|
95
98
|
});
|
@@ -108,8 +111,9 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
108
111
|
}
|
109
112
|
},
|
110
113
|
leave(node, parent) {
|
111
|
-
if (parent && !(parent.type === "IfStatement" && node === parent.alternate))
|
114
|
+
if (parent && !(parent.type === "IfStatement" && node === parent.alternate)) {
|
112
115
|
parentStack.shift();
|
116
|
+
}
|
113
117
|
if (node.type === "VariableDeclaration")
|
114
118
|
varKindStack.shift();
|
115
119
|
}
|
@@ -130,8 +134,9 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
130
134
|
});
|
131
135
|
}
|
132
136
|
function isRefIdentifier(id, parent, parentStack) {
|
133
|
-
if (parent.type === "CatchClause" || (parent.type === "VariableDeclarator" || parent.type === "ClassDeclaration") && parent.id === id)
|
137
|
+
if (parent.type === "CatchClause" || (parent.type === "VariableDeclarator" || parent.type === "ClassDeclaration") && parent.id === id) {
|
134
138
|
return false;
|
139
|
+
}
|
135
140
|
if (isFunctionNode(parent)) {
|
136
141
|
if (parent.id === id)
|
137
142
|
return false;
|
@@ -144,10 +149,12 @@ function isRefIdentifier(id, parent, parentStack) {
|
|
144
149
|
return false;
|
145
150
|
if (isNodeInPattern(parent) && parent.value === id)
|
146
151
|
return false;
|
147
|
-
if (parent.type === "ArrayPattern" && !isInDestructuringAssignment(parent, parentStack))
|
152
|
+
if (parent.type === "ArrayPattern" && !isInDestructuringAssignment(parent, parentStack)) {
|
148
153
|
return false;
|
149
|
-
|
154
|
+
}
|
155
|
+
if (parent.type === "MemberExpression" && parent.property === id && !parent.computed) {
|
150
156
|
return false;
|
157
|
+
}
|
151
158
|
if (parent.type === "ExportSpecifier")
|
152
159
|
return false;
|
153
160
|
if (id.name === "arguments")
|
@@ -172,8 +179,9 @@ function findParentScope(parentStack, isVar = false) {
|
|
172
179
|
return parentStack.find(isVar ? isFunctionNode : isBlock);
|
173
180
|
}
|
174
181
|
function isInDestructuringAssignment(parent, parentStack) {
|
175
|
-
if (parent && (parent.type === "Property" || parent.type === "ArrayPattern"))
|
182
|
+
if (parent && (parent.type === "Property" || parent.type === "ArrayPattern")) {
|
176
183
|
return parentStack.some((i) => i.type === "AssignmentExpression");
|
184
|
+
}
|
177
185
|
return false;
|
178
186
|
}
|
179
187
|
|
package/dist/chunk-colors.js
CHANGED
@@ -46,10 +46,14 @@ function getColors() {
|
|
46
46
|
function createColors(isTTY = false) {
|
47
47
|
const enabled = typeof process !== "undefined" && !("NO_COLOR" in process.env || process.argv.includes("--no-color")) && !("GITHUB_ACTIONS" in process.env) && ("FORCE_COLOR" in process.env || process.argv.includes("--color") || process.platform === "win32" || isTTY && process.env.TERM !== "dumb" || "CI" in process.env);
|
48
48
|
const replaceClose = (string2, close, replace, index) => {
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
49
|
+
let result = "";
|
50
|
+
let cursor = 0;
|
51
|
+
do {
|
52
|
+
result += string2.substring(cursor, index) + replace;
|
53
|
+
cursor = index + close.length;
|
54
|
+
index = string2.indexOf(close, cursor);
|
55
|
+
} while (~index);
|
56
|
+
return result + string2.substring(cursor);
|
53
57
|
};
|
54
58
|
const formatter = (open, close, replace = open) => {
|
55
59
|
const fn = (input) => {
|
package/dist/chunk-display.js
CHANGED
@@ -41,7 +41,7 @@ function stringify(object, maxDepth = 10, { maxLength, ...options } = {}) {
|
|
41
41
|
return result.length >= MAX_LENGTH && maxDepth > 1 ? stringify(object, Math.floor(maxDepth / 2)) : result;
|
42
42
|
}
|
43
43
|
|
44
|
-
const formatRegExp = /%[
|
44
|
+
const formatRegExp = /%[sdjifoOc%]/g;
|
45
45
|
function format(...args) {
|
46
46
|
if (typeof args[0] !== "string") {
|
47
47
|
const objects = [];
|
@@ -98,8 +98,9 @@ function format(...args) {
|
|
98
98
|
if (
|
99
99
|
// chromium
|
100
100
|
m.includes("circular structure") || m.includes("cyclic structures") || m.includes("cyclic object")
|
101
|
-
)
|
101
|
+
) {
|
102
102
|
return "[Circular]";
|
103
|
+
}
|
103
104
|
throw err;
|
104
105
|
}
|
105
106
|
default:
|
package/dist/diff.js
CHANGED
@@ -67,8 +67,9 @@ const diff_commonPrefix = function(text1, text2) {
|
|
67
67
|
return pointermid;
|
68
68
|
};
|
69
69
|
const diff_commonSuffix = function(text1, text2) {
|
70
|
-
if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1))
|
70
|
+
if (!text1 || !text2 || text1.charAt(text1.length - 1) !== text2.charAt(text2.length - 1)) {
|
71
71
|
return 0;
|
72
|
+
}
|
72
73
|
let pointermin = 0;
|
73
74
|
let pointermax = Math.min(text1.length, text2.length);
|
74
75
|
let pointermid = pointermax;
|
@@ -181,7 +182,7 @@ const diff_cleanupSemantic = function(diffs) {
|
|
181
182
|
pointer++;
|
182
183
|
}
|
183
184
|
};
|
184
|
-
const nonAlphaNumericRegex_ = /[^a-
|
185
|
+
const nonAlphaNumericRegex_ = /[^a-z0-9]/i;
|
185
186
|
const whitespaceRegex_ = /\s/;
|
186
187
|
const linebreakRegex_ = /[\r\n]/;
|
187
188
|
const blanklineEndRegex_ = /\n\r?\n$/;
|
package/dist/helpers.d.ts
CHANGED
@@ -31,5 +31,6 @@ declare function createDefer<T>(): DeferPromise<T>;
|
|
31
31
|
* ```
|
32
32
|
*/
|
33
33
|
declare function getCallLastIndex(code: string): number | null;
|
34
|
+
declare function isNegativeNaN(val: number): boolean;
|
34
35
|
|
35
|
-
export { type DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
36
|
+
export { type DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
package/dist/helpers.js
CHANGED
@@ -149,5 +149,14 @@ function getCallLastIndex(code) {
|
|
149
149
|
}
|
150
150
|
return null;
|
151
151
|
}
|
152
|
+
function isNegativeNaN(val) {
|
153
|
+
if (!Number.isNaN(val))
|
154
|
+
return false;
|
155
|
+
const f64 = new Float64Array(1);
|
156
|
+
f64[0] = val;
|
157
|
+
const u32 = new Uint32Array(f64.buffer);
|
158
|
+
const isNegative = u32[1] >>> 31 === 1;
|
159
|
+
return isNegative;
|
160
|
+
}
|
152
161
|
|
153
|
-
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
162
|
+
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray };
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export { DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
1
|
+
export { DeferPromise, assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
2
|
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack } from './types.js';
|
3
3
|
import { PrettyFormatOptions } from 'pretty-format';
|
4
4
|
|
package/dist/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
1
|
+
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
2
|
export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-display.js';
|
3
3
|
import { S as SAFE_TIMERS_SYMBOL, g as getColors } from './chunk-colors.js';
|
4
4
|
export { a as SAFE_COLORS_SYMBOL, c as createColors, b as getDefaultColors, s as setupColors } from './chunk-colors.js';
|
@@ -69,7 +69,7 @@ function shuffle(array, seed = RealDate.now()) {
|
|
69
69
|
}
|
70
70
|
|
71
71
|
function createSimpleStackTrace(options) {
|
72
|
-
const { message = "error", stackTraceLimit = 1 } = options || {};
|
72
|
+
const { message = "$$stack trace error", stackTraceLimit = 1 } = options || {};
|
73
73
|
const limit = Error.stackTraceLimit;
|
74
74
|
const prepareStackTrace = Error.prepareStackTrace;
|
75
75
|
Error.stackTraceLimit = stackTraceLimit;
|
package/dist/source-map.js
CHANGED
@@ -760,8 +760,8 @@ function generatedPosition(map, source, line, column, bias, all) {
|
|
760
760
|
return GMapping(segment[REV_GENERATED_LINE] + 1, segment[REV_GENERATED_COLUMN]);
|
761
761
|
}
|
762
762
|
|
763
|
-
const CHROME_IE_STACK_REGEXP = /^\s*at .*(
|
764
|
-
const SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(
|
763
|
+
const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
|
764
|
+
const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
|
765
765
|
const stackIgnorePatterns = [
|
766
766
|
"node:internal",
|
767
767
|
/\/packages\/\w+\/dist\//,
|
@@ -773,8 +773,14 @@ const stackIgnorePatterns = [
|
|
773
773
|
"/node_modules/chai/",
|
774
774
|
"/node_modules/tinypool/",
|
775
775
|
"/node_modules/tinyspy/",
|
776
|
+
// browser related deps
|
776
777
|
"/deps/chai.js",
|
777
|
-
/
|
778
|
+
"/deps/vitest___chai.js",
|
779
|
+
"/deps/p-limit.js",
|
780
|
+
/node:\w+/,
|
781
|
+
/__vitest_test__/,
|
782
|
+
/__vitest_browser__/,
|
783
|
+
/\/deps\/vitest_/
|
778
784
|
];
|
779
785
|
function extractLocation(urlLike) {
|
780
786
|
if (!urlLike.includes(":"))
|
@@ -784,12 +790,15 @@ function extractLocation(urlLike) {
|
|
784
790
|
if (!parts)
|
785
791
|
return [urlLike];
|
786
792
|
let url = parts[1];
|
793
|
+
if (url.startsWith("async "))
|
794
|
+
url = url.slice(6);
|
787
795
|
if (url.startsWith("http:") || url.startsWith("https:")) {
|
788
796
|
const urlObj = new URL(url);
|
789
797
|
url = urlObj.pathname;
|
790
798
|
}
|
791
799
|
if (url.startsWith("/@fs/")) {
|
792
|
-
|
800
|
+
const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
|
801
|
+
url = url.slice(isWindows ? 5 : 4);
|
793
802
|
}
|
794
803
|
return [url, parts[2] || void 0, parts[3] || void 0];
|
795
804
|
}
|
@@ -801,7 +810,7 @@ function parseSingleFFOrSafariStack(raw) {
|
|
801
810
|
line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g, ":$1");
|
802
811
|
if (!line.includes("@") && !line.includes(":"))
|
803
812
|
return null;
|
804
|
-
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(
|
813
|
+
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
|
805
814
|
const matches = line.match(functionNameRegex);
|
806
815
|
const functionName = matches && matches[1] ? matches[1] : void 0;
|
807
816
|
const [url, lineNumber, columnNumber] = extractLocation(line.replace(functionNameRegex, ""));
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "2.0.0-beta.
|
4
|
+
"version": "2.0.0-beta.10",
|
5
5
|
"description": "Shared Vitest utility functions",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -47,6 +47,9 @@
|
|
47
47
|
"types": "./dist/index.d.ts",
|
48
48
|
"typesVersions": {
|
49
49
|
"*": {
|
50
|
+
"ast": [
|
51
|
+
"dist/ast.d.ts"
|
52
|
+
],
|
50
53
|
"source-map": [
|
51
54
|
"dist/source-map.d.ts"
|
52
55
|
]
|
@@ -59,7 +62,7 @@
|
|
59
62
|
"dependencies": {
|
60
63
|
"diff-sequences": "^29.6.3",
|
61
64
|
"estree-walker": "^3.0.3",
|
62
|
-
"loupe": "^3.1.
|
65
|
+
"loupe": "^3.1.1",
|
63
66
|
"pretty-format": "^29.7.0"
|
64
67
|
},
|
65
68
|
"devDependencies": {
|