@vitest/utils 2.0.0-beta.10 → 2.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/ast.js +49 -26
- package/dist/chunk-colors.js +7 -4
- package/dist/chunk-display.js +23 -12
- package/dist/diff.js +137 -61
- package/dist/error.js +61 -28
- package/dist/helpers.js +35 -17
- package/dist/index.js +10 -9
- package/dist/source-map.js +60 -28
- package/package.json +1 -1
package/dist/ast.js
CHANGED
@@ -14,8 +14,9 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
14
14
|
const identifiers = [];
|
15
15
|
const setScope = (node, name) => {
|
16
16
|
let scopeIds = scopeMap.get(node);
|
17
|
-
if (scopeIds && scopeIds.has(name))
|
17
|
+
if (scopeIds && scopeIds.has(name)) {
|
18
18
|
return;
|
19
|
+
}
|
19
20
|
if (!scopeIds) {
|
20
21
|
scopeIds = /* @__PURE__ */ new Set();
|
21
22
|
scopeMap.set(node, scopeIds);
|
@@ -35,15 +36,17 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
35
36
|
handlePattern(p.argument, parentScope);
|
36
37
|
} else if (p.type === "ObjectPattern") {
|
37
38
|
p.properties.forEach((property) => {
|
38
|
-
if (property.type === "RestElement")
|
39
|
+
if (property.type === "RestElement") {
|
39
40
|
setScope(parentScope, property.argument.name);
|
40
|
-
else
|
41
|
+
} else {
|
41
42
|
handlePattern(property.value, parentScope);
|
43
|
+
}
|
42
44
|
});
|
43
45
|
} else if (p.type === "ArrayPattern") {
|
44
46
|
p.elements.forEach((element) => {
|
45
|
-
if (element)
|
47
|
+
if (element) {
|
46
48
|
handlePattern(element, parentScope);
|
49
|
+
}
|
47
50
|
});
|
48
51
|
} else if (p.type === "AssignmentPattern") {
|
49
52
|
handlePattern(p.left, parentScope);
|
@@ -53,19 +56,23 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
53
56
|
}
|
54
57
|
walk(root, {
|
55
58
|
enter(node, parent) {
|
56
|
-
if (node.type === "ImportDeclaration")
|
59
|
+
if (node.type === "ImportDeclaration") {
|
57
60
|
return this.skip();
|
61
|
+
}
|
58
62
|
if (parent && !(parent.type === "IfStatement" && node === parent.alternate)) {
|
59
63
|
parentStack.unshift(parent);
|
60
64
|
}
|
61
|
-
if (node.type === "VariableDeclaration")
|
65
|
+
if (node.type === "VariableDeclaration") {
|
62
66
|
varKindStack.unshift(node.kind);
|
63
|
-
|
67
|
+
}
|
68
|
+
if (node.type === "CallExpression") {
|
64
69
|
onCallExpression == null ? void 0 : onCallExpression(node);
|
65
|
-
|
70
|
+
}
|
71
|
+
if (node.type === "MetaProperty" && node.meta.name === "import") {
|
66
72
|
onImportMeta == null ? void 0 : onImportMeta(node);
|
67
|
-
else if (node.type === "ImportExpression")
|
73
|
+
} else if (node.type === "ImportExpression") {
|
68
74
|
onDynamicImport == null ? void 0 : onDynamicImport(node);
|
75
|
+
}
|
69
76
|
if (node.type === "Identifier") {
|
70
77
|
if (!isInScope(node.name, parentStack) && isRefIdentifier(node, parent, parentStack)) {
|
71
78
|
identifiers.push([node, parentStack.slice(0)]);
|
@@ -73,8 +80,9 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
73
80
|
} else if (isFunctionNode(node)) {
|
74
81
|
if (node.type === "FunctionDeclaration") {
|
75
82
|
const parentScope = findParentScope(parentStack);
|
76
|
-
if (parentScope)
|
83
|
+
if (parentScope) {
|
77
84
|
setScope(parentScope, node.id.name);
|
85
|
+
}
|
78
86
|
}
|
79
87
|
node.params.forEach((p) => {
|
80
88
|
if (p.type === "ObjectPattern" || p.type === "ArrayPattern") {
|
@@ -86,10 +94,12 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
86
94
|
if ((parent2 == null ? void 0 : parent2.type) === "AssignmentPattern" && (parent2 == null ? void 0 : parent2.right) === child) {
|
87
95
|
return this.skip();
|
88
96
|
}
|
89
|
-
if (child.type !== "Identifier")
|
97
|
+
if (child.type !== "Identifier") {
|
90
98
|
return;
|
91
|
-
|
99
|
+
}
|
100
|
+
if (isStaticPropertyKey(child, parent2)) {
|
92
101
|
return;
|
102
|
+
}
|
93
103
|
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) {
|
94
104
|
return;
|
95
105
|
}
|
@@ -104,8 +114,9 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
104
114
|
parentStack,
|
105
115
|
varKindStack[0] === "var"
|
106
116
|
);
|
107
|
-
if (parentFunction)
|
117
|
+
if (parentFunction) {
|
108
118
|
handlePattern(node.id, parentFunction);
|
119
|
+
}
|
109
120
|
} else if (node.type === "CatchClause" && node.param) {
|
110
121
|
handlePattern(node.param, node);
|
111
122
|
}
|
@@ -114,8 +125,9 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
114
125
|
if (parent && !(parent.type === "IfStatement" && node === parent.alternate)) {
|
115
126
|
parentStack.shift();
|
116
127
|
}
|
117
|
-
if (node.type === "VariableDeclaration")
|
128
|
+
if (node.type === "VariableDeclaration") {
|
118
129
|
varKindStack.shift();
|
130
|
+
}
|
119
131
|
}
|
120
132
|
});
|
121
133
|
identifiers.forEach(([node, stack]) => {
|
@@ -125,11 +137,15 @@ function esmWalker(root, { onIdentifier, onImportMeta, onDynamicImport, onCallEx
|
|
125
137
|
const hasBindingShortcut = isStaticProperty(parent) && parent.shorthand && (!isNodeInPattern(parent) || isInDestructuringAssignment(parent, parentStack));
|
126
138
|
const classDeclaration = parent.type === "PropertyDefinition" && (grandparent == null ? void 0 : grandparent.type) === "ClassBody" || parent.type === "ClassDeclaration" && node === parent.superClass;
|
127
139
|
const classExpression = parent.type === "ClassExpression" && node === parent.id;
|
128
|
-
onIdentifier == null ? void 0 : onIdentifier(
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
140
|
+
onIdentifier == null ? void 0 : onIdentifier(
|
141
|
+
node,
|
142
|
+
{
|
143
|
+
hasBindingShortcut,
|
144
|
+
classDeclaration,
|
145
|
+
classExpression
|
146
|
+
},
|
147
|
+
stack
|
148
|
+
);
|
133
149
|
}
|
134
150
|
});
|
135
151
|
}
|
@@ -138,27 +154,34 @@ function isRefIdentifier(id, parent, parentStack) {
|
|
138
154
|
return false;
|
139
155
|
}
|
140
156
|
if (isFunctionNode(parent)) {
|
141
|
-
if (parent.id === id)
|
157
|
+
if (parent.id === id) {
|
142
158
|
return false;
|
143
|
-
|
159
|
+
}
|
160
|
+
if (parent.params.includes(id)) {
|
144
161
|
return false;
|
162
|
+
}
|
145
163
|
}
|
146
|
-
if (parent.type === "MethodDefinition" && !parent.computed)
|
164
|
+
if (parent.type === "MethodDefinition" && !parent.computed) {
|
147
165
|
return false;
|
148
|
-
|
166
|
+
}
|
167
|
+
if (isStaticPropertyKey(id, parent)) {
|
149
168
|
return false;
|
150
|
-
|
169
|
+
}
|
170
|
+
if (isNodeInPattern(parent) && parent.value === id) {
|
151
171
|
return false;
|
172
|
+
}
|
152
173
|
if (parent.type === "ArrayPattern" && !isInDestructuringAssignment(parent, parentStack)) {
|
153
174
|
return false;
|
154
175
|
}
|
155
176
|
if (parent.type === "MemberExpression" && parent.property === id && !parent.computed) {
|
156
177
|
return false;
|
157
178
|
}
|
158
|
-
if (parent.type === "ExportSpecifier")
|
179
|
+
if (parent.type === "ExportSpecifier") {
|
159
180
|
return false;
|
160
|
-
|
181
|
+
}
|
182
|
+
if (id.name === "arguments") {
|
161
183
|
return false;
|
184
|
+
}
|
162
185
|
return true;
|
163
186
|
}
|
164
187
|
function isStaticProperty(node) {
|
package/dist/chunk-colors.js
CHANGED
@@ -33,10 +33,13 @@ function string(str) {
|
|
33
33
|
}
|
34
34
|
string.open = "";
|
35
35
|
string.close = "";
|
36
|
-
const defaultColors = /* @__PURE__ */ colorsEntries.reduce(
|
37
|
-
acc[key]
|
38
|
-
|
39
|
-
|
36
|
+
const defaultColors = /* @__PURE__ */ colorsEntries.reduce(
|
37
|
+
(acc, [key]) => {
|
38
|
+
acc[key] = string;
|
39
|
+
return acc;
|
40
|
+
},
|
41
|
+
{ isColorSupported: false }
|
42
|
+
);
|
40
43
|
function getDefaultColors() {
|
41
44
|
return { ...defaultColors };
|
42
45
|
}
|
package/dist/chunk-display.js
CHANGED
@@ -45,39 +45,47 @@ const formatRegExp = /%[sdjifoOc%]/g;
|
|
45
45
|
function format(...args) {
|
46
46
|
if (typeof args[0] !== "string") {
|
47
47
|
const objects = [];
|
48
|
-
for (let i2 = 0; i2 < args.length; i2++)
|
48
|
+
for (let i2 = 0; i2 < args.length; i2++) {
|
49
49
|
objects.push(inspect(args[i2], { depth: 0, colors: false }));
|
50
|
+
}
|
50
51
|
return objects.join(" ");
|
51
52
|
}
|
52
53
|
const len = args.length;
|
53
54
|
let i = 1;
|
54
55
|
const template = args[0];
|
55
56
|
let str = String(template).replace(formatRegExp, (x) => {
|
56
|
-
if (x === "%%")
|
57
|
+
if (x === "%%") {
|
57
58
|
return "%";
|
58
|
-
|
59
|
+
}
|
60
|
+
if (i >= len) {
|
59
61
|
return x;
|
62
|
+
}
|
60
63
|
switch (x) {
|
61
64
|
case "%s": {
|
62
65
|
const value = args[i++];
|
63
|
-
if (typeof value === "bigint")
|
66
|
+
if (typeof value === "bigint") {
|
64
67
|
return `${value.toString()}n`;
|
65
|
-
|
68
|
+
}
|
69
|
+
if (typeof value === "number" && value === 0 && 1 / value < 0) {
|
66
70
|
return "-0";
|
67
|
-
|
71
|
+
}
|
72
|
+
if (typeof value === "object" && value !== null) {
|
68
73
|
return inspect(value, { depth: 0, colors: false });
|
74
|
+
}
|
69
75
|
return String(value);
|
70
76
|
}
|
71
77
|
case "%d": {
|
72
78
|
const value = args[i++];
|
73
|
-
if (typeof value === "bigint")
|
79
|
+
if (typeof value === "bigint") {
|
74
80
|
return `${value.toString()}n`;
|
81
|
+
}
|
75
82
|
return Number(value).toString();
|
76
83
|
}
|
77
84
|
case "%i": {
|
78
85
|
const value = args[i++];
|
79
|
-
if (typeof value === "bigint")
|
86
|
+
if (typeof value === "bigint") {
|
80
87
|
return `${value.toString()}n`;
|
88
|
+
}
|
81
89
|
return Number.parseInt(String(value)).toString();
|
82
90
|
}
|
83
91
|
case "%f":
|
@@ -108,21 +116,24 @@ function format(...args) {
|
|
108
116
|
}
|
109
117
|
});
|
110
118
|
for (let x = args[i]; i < len; x = args[++i]) {
|
111
|
-
if (x === null || typeof x !== "object")
|
119
|
+
if (x === null || typeof x !== "object") {
|
112
120
|
str += ` ${x}`;
|
113
|
-
else
|
121
|
+
} else {
|
114
122
|
str += ` ${inspect(x)}`;
|
123
|
+
}
|
115
124
|
}
|
116
125
|
return str;
|
117
126
|
}
|
118
127
|
function inspect(obj, options = {}) {
|
119
|
-
if (options.truncate === 0)
|
128
|
+
if (options.truncate === 0) {
|
120
129
|
options.truncate = Number.POSITIVE_INFINITY;
|
130
|
+
}
|
121
131
|
return loupe.inspect(obj, options);
|
122
132
|
}
|
123
133
|
function objDisplay(obj, options = {}) {
|
124
|
-
if (typeof options.truncate === "undefined")
|
134
|
+
if (typeof options.truncate === "undefined") {
|
125
135
|
options.truncate = 40;
|
136
|
+
}
|
126
137
|
const str = inspect(obj, options);
|
127
138
|
const type = Object.prototype.toString.call(obj);
|
128
139
|
if (options.truncate && str.length >= options.truncate) {
|
package/dist/diff.js
CHANGED
@@ -21,14 +21,15 @@ function getType(value) {
|
|
21
21
|
return "bigint";
|
22
22
|
} else if (typeof value === "object") {
|
23
23
|
if (value != null) {
|
24
|
-
if (value.constructor === RegExp)
|
24
|
+
if (value.constructor === RegExp) {
|
25
25
|
return "regexp";
|
26
|
-
else if (value.constructor === Map)
|
26
|
+
} else if (value.constructor === Map) {
|
27
27
|
return "map";
|
28
|
-
else if (value.constructor === Set)
|
28
|
+
} else if (value.constructor === Set) {
|
29
29
|
return "set";
|
30
|
-
else if (value.constructor === Date)
|
30
|
+
} else if (value.constructor === Date) {
|
31
31
|
return "date";
|
32
|
+
}
|
32
33
|
}
|
33
34
|
return "object";
|
34
35
|
} else if (typeof value === "symbol") {
|
@@ -49,8 +50,9 @@ class Diff {
|
|
49
50
|
}
|
50
51
|
}
|
51
52
|
const diff_commonPrefix = function(text1, text2) {
|
52
|
-
if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0))
|
53
|
+
if (!text1 || !text2 || text1.charAt(0) !== text2.charAt(0)) {
|
53
54
|
return 0;
|
55
|
+
}
|
54
56
|
let pointermin = 0;
|
55
57
|
let pointermax = Math.min(text1.length, text2.length);
|
56
58
|
let pointermid = pointermax;
|
@@ -88,22 +90,26 @@ const diff_commonSuffix = function(text1, text2) {
|
|
88
90
|
const diff_commonOverlap_ = function(text1, text2) {
|
89
91
|
const text1_length = text1.length;
|
90
92
|
const text2_length = text2.length;
|
91
|
-
if (text1_length === 0 || text2_length === 0)
|
93
|
+
if (text1_length === 0 || text2_length === 0) {
|
92
94
|
return 0;
|
93
|
-
|
95
|
+
}
|
96
|
+
if (text1_length > text2_length) {
|
94
97
|
text1 = text1.substring(text1_length - text2_length);
|
95
|
-
else if (text1_length < text2_length)
|
98
|
+
} else if (text1_length < text2_length) {
|
96
99
|
text2 = text2.substring(0, text1_length);
|
100
|
+
}
|
97
101
|
const text_length = Math.min(text1_length, text2_length);
|
98
|
-
if (text1 === text2)
|
102
|
+
if (text1 === text2) {
|
99
103
|
return text_length;
|
104
|
+
}
|
100
105
|
let best = 0;
|
101
106
|
let length = 1;
|
102
107
|
while (true) {
|
103
108
|
const pattern = text1.substring(text_length - length);
|
104
109
|
const found = text2.indexOf(pattern);
|
105
|
-
if (found === -1)
|
110
|
+
if (found === -1) {
|
106
111
|
return best;
|
112
|
+
}
|
107
113
|
length += found;
|
108
114
|
if (found === 0 || text1.substring(text_length - length) === text2.substring(0, length)) {
|
109
115
|
best = length;
|
@@ -130,12 +136,17 @@ const diff_cleanupSemantic = function(diffs) {
|
|
130
136
|
length_deletions2 = 0;
|
131
137
|
lastEquality = diffs[pointer][1];
|
132
138
|
} else {
|
133
|
-
if (diffs[pointer][0] === DIFF_INSERT)
|
139
|
+
if (diffs[pointer][0] === DIFF_INSERT) {
|
134
140
|
length_insertions2 += diffs[pointer][1].length;
|
135
|
-
else
|
141
|
+
} else {
|
136
142
|
length_deletions2 += diffs[pointer][1].length;
|
143
|
+
}
|
137
144
|
if (lastEquality && lastEquality.length <= Math.max(length_insertions1, length_deletions1) && lastEquality.length <= Math.max(length_insertions2, length_deletions2)) {
|
138
|
-
diffs.splice(
|
145
|
+
diffs.splice(
|
146
|
+
equalities[equalitiesLength - 1],
|
147
|
+
0,
|
148
|
+
new Diff(DIFF_DELETE, lastEquality)
|
149
|
+
);
|
139
150
|
diffs[equalities[equalitiesLength - 1] + 1][0] = DIFF_INSERT;
|
140
151
|
equalitiesLength--;
|
141
152
|
equalitiesLength--;
|
@@ -150,8 +161,9 @@ const diff_cleanupSemantic = function(diffs) {
|
|
150
161
|
}
|
151
162
|
pointer++;
|
152
163
|
}
|
153
|
-
if (changes)
|
164
|
+
if (changes) {
|
154
165
|
diff_cleanupMerge(diffs);
|
166
|
+
}
|
155
167
|
diff_cleanupSemanticLossless(diffs);
|
156
168
|
pointer = 1;
|
157
169
|
while (pointer < diffs.length) {
|
@@ -162,16 +174,30 @@ const diff_cleanupSemantic = function(diffs) {
|
|
162
174
|
const overlap_length2 = diff_commonOverlap_(insertion, deletion);
|
163
175
|
if (overlap_length1 >= overlap_length2) {
|
164
176
|
if (overlap_length1 >= deletion.length / 2 || overlap_length1 >= insertion.length / 2) {
|
165
|
-
diffs.splice(
|
166
|
-
|
177
|
+
diffs.splice(
|
178
|
+
pointer,
|
179
|
+
0,
|
180
|
+
new Diff(DIFF_EQUAL, insertion.substring(0, overlap_length1))
|
181
|
+
);
|
182
|
+
diffs[pointer - 1][1] = deletion.substring(
|
183
|
+
0,
|
184
|
+
deletion.length - overlap_length1
|
185
|
+
);
|
167
186
|
diffs[pointer + 1][1] = insertion.substring(overlap_length1);
|
168
187
|
pointer++;
|
169
188
|
}
|
170
189
|
} else {
|
171
190
|
if (overlap_length2 >= deletion.length / 2 || overlap_length2 >= insertion.length / 2) {
|
172
|
-
diffs.splice(
|
191
|
+
diffs.splice(
|
192
|
+
pointer,
|
193
|
+
0,
|
194
|
+
new Diff(DIFF_EQUAL, deletion.substring(0, overlap_length2))
|
195
|
+
);
|
173
196
|
diffs[pointer - 1][0] = DIFF_INSERT;
|
174
|
-
diffs[pointer - 1][1] = insertion.substring(
|
197
|
+
diffs[pointer - 1][1] = insertion.substring(
|
198
|
+
0,
|
199
|
+
insertion.length - overlap_length2
|
200
|
+
);
|
175
201
|
diffs[pointer + 1][0] = DIFF_DELETE;
|
176
202
|
diffs[pointer + 1][1] = deletion.substring(overlap_length2);
|
177
203
|
pointer++;
|
@@ -291,7 +317,11 @@ function diff_cleanupMerge(diffs) {
|
|
291
317
|
if (pointer - count_delete - count_insert > 0 && diffs[pointer - count_delete - count_insert - 1][0] === DIFF_EQUAL) {
|
292
318
|
diffs[pointer - count_delete - count_insert - 1][1] += text_insert.substring(0, commonlength);
|
293
319
|
} else {
|
294
|
-
diffs.splice(
|
320
|
+
diffs.splice(
|
321
|
+
0,
|
322
|
+
0,
|
323
|
+
new Diff(DIFF_EQUAL, text_insert.substring(0, commonlength))
|
324
|
+
);
|
295
325
|
pointer++;
|
296
326
|
}
|
297
327
|
text_insert = text_insert.substring(commonlength);
|
@@ -300,8 +330,14 @@ function diff_cleanupMerge(diffs) {
|
|
300
330
|
commonlength = diff_commonSuffix(text_insert, text_delete);
|
301
331
|
if (commonlength !== 0) {
|
302
332
|
diffs[pointer][1] = text_insert.substring(text_insert.length - commonlength) + diffs[pointer][1];
|
303
|
-
text_insert = text_insert.substring(
|
304
|
-
|
333
|
+
text_insert = text_insert.substring(
|
334
|
+
0,
|
335
|
+
text_insert.length - commonlength
|
336
|
+
);
|
337
|
+
text_delete = text_delete.substring(
|
338
|
+
0,
|
339
|
+
text_delete.length - commonlength
|
340
|
+
);
|
305
341
|
}
|
306
342
|
}
|
307
343
|
pointer -= count_delete + count_insert;
|
@@ -328,14 +364,20 @@ function diff_cleanupMerge(diffs) {
|
|
328
364
|
break;
|
329
365
|
}
|
330
366
|
}
|
331
|
-
if (diffs[diffs.length - 1][1] === "")
|
367
|
+
if (diffs[diffs.length - 1][1] === "") {
|
332
368
|
diffs.pop();
|
369
|
+
}
|
333
370
|
let changes = false;
|
334
371
|
pointer = 1;
|
335
372
|
while (pointer < diffs.length - 1) {
|
336
373
|
if (diffs[pointer - 1][0] === DIFF_EQUAL && diffs[pointer + 1][0] === DIFF_EQUAL) {
|
337
|
-
if (diffs[pointer][1].substring(
|
338
|
-
diffs[pointer][1]
|
374
|
+
if (diffs[pointer][1].substring(
|
375
|
+
diffs[pointer][1].length - diffs[pointer - 1][1].length
|
376
|
+
) === diffs[pointer - 1][1]) {
|
377
|
+
diffs[pointer][1] = diffs[pointer - 1][1] + diffs[pointer][1].substring(
|
378
|
+
0,
|
379
|
+
diffs[pointer][1].length - diffs[pointer - 1][1].length
|
380
|
+
);
|
339
381
|
diffs[pointer + 1][1] = diffs[pointer - 1][1] + diffs[pointer + 1][1];
|
340
382
|
diffs.splice(pointer - 1, 1);
|
341
383
|
changes = true;
|
@@ -348,8 +390,9 @@ function diff_cleanupMerge(diffs) {
|
|
348
390
|
}
|
349
391
|
pointer++;
|
350
392
|
}
|
351
|
-
if (changes)
|
393
|
+
if (changes) {
|
352
394
|
diff_cleanupMerge(diffs);
|
395
|
+
}
|
353
396
|
}
|
354
397
|
|
355
398
|
const NO_DIFF_MESSAGE = "Compared values have no visual difference.";
|
@@ -423,8 +466,9 @@ function joinAlignedDiffsNoExpand(diffs, options) {
|
|
423
466
|
let i = 0;
|
424
467
|
while (i !== iLength) {
|
425
468
|
const iStart = i;
|
426
|
-
while (i !== iLength && diffs[i][0] === DIFF_EQUAL)
|
469
|
+
while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
|
427
470
|
i += 1;
|
471
|
+
}
|
428
472
|
if (iStart !== i) {
|
429
473
|
if (iStart === 0) {
|
430
474
|
if (i > nContextLines) {
|
@@ -445,19 +489,22 @@ function joinAlignedDiffsNoExpand(diffs, options) {
|
|
445
489
|
}
|
446
490
|
}
|
447
491
|
}
|
448
|
-
while (i !== iLength && diffs[i][0] !== DIFF_EQUAL)
|
492
|
+
while (i !== iLength && diffs[i][0] !== DIFF_EQUAL) {
|
449
493
|
i += 1;
|
494
|
+
}
|
450
495
|
}
|
451
496
|
const hasPatch = nExcessesBetweenChanges !== 0 || hasExcessAtStartOrEnd;
|
452
|
-
if (nExcessesBetweenChanges !== 0)
|
497
|
+
if (nExcessesBetweenChanges !== 0) {
|
453
498
|
jLength += nExcessesBetweenChanges + 1;
|
454
|
-
else if (hasExcessAtStartOrEnd)
|
499
|
+
} else if (hasExcessAtStartOrEnd) {
|
455
500
|
jLength += 1;
|
501
|
+
}
|
456
502
|
const jLast = jLength - 1;
|
457
503
|
const lines = [];
|
458
504
|
let jPatchMark = 0;
|
459
|
-
if (hasPatch)
|
505
|
+
if (hasPatch) {
|
460
506
|
lines.push("");
|
507
|
+
}
|
461
508
|
let aStart = 0;
|
462
509
|
let bStart = 0;
|
463
510
|
let aEnd = 0;
|
@@ -481,8 +528,9 @@ function joinAlignedDiffsNoExpand(diffs, options) {
|
|
481
528
|
i = 0;
|
482
529
|
while (i !== iLength) {
|
483
530
|
let iStart = i;
|
484
|
-
while (i !== iLength && diffs[i][0] === DIFF_EQUAL)
|
531
|
+
while (i !== iLength && diffs[i][0] === DIFF_EQUAL) {
|
485
532
|
i += 1;
|
533
|
+
}
|
486
534
|
if (iStart !== i) {
|
487
535
|
if (iStart === 0) {
|
488
536
|
if (i > nContextLines) {
|
@@ -492,18 +540,21 @@ function joinAlignedDiffsNoExpand(diffs, options) {
|
|
492
540
|
aEnd = aStart;
|
493
541
|
bEnd = bStart;
|
494
542
|
}
|
495
|
-
for (let iCommon = iStart; iCommon !== i; iCommon += 1)
|
543
|
+
for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
|
496
544
|
pushCommonLine(diffs[iCommon][1]);
|
545
|
+
}
|
497
546
|
} else if (i === iLength) {
|
498
547
|
const iEnd = i - iStart > nContextLines ? iStart + nContextLines : i;
|
499
|
-
for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1)
|
548
|
+
for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
|
500
549
|
pushCommonLine(diffs[iCommon][1]);
|
550
|
+
}
|
501
551
|
} else {
|
502
552
|
const nCommon = i - iStart;
|
503
553
|
if (nCommon > nContextLines2) {
|
504
554
|
const iEnd = iStart + nContextLines;
|
505
|
-
for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1)
|
555
|
+
for (let iCommon = iStart; iCommon !== iEnd; iCommon += 1) {
|
506
556
|
pushCommonLine(diffs[iCommon][1]);
|
557
|
+
}
|
507
558
|
lines[jPatchMark] = createPatchMark(
|
508
559
|
aStart,
|
509
560
|
aEnd,
|
@@ -518,11 +569,13 @@ function joinAlignedDiffsNoExpand(diffs, options) {
|
|
518
569
|
bStart = bEnd + nOmit;
|
519
570
|
aEnd = aStart;
|
520
571
|
bEnd = bStart;
|
521
|
-
for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1)
|
572
|
+
for (let iCommon = i - nContextLines; iCommon !== i; iCommon += 1) {
|
522
573
|
pushCommonLine(diffs[iCommon][1]);
|
574
|
+
}
|
523
575
|
} else {
|
524
|
-
for (let iCommon = iStart; iCommon !== i; iCommon += 1)
|
576
|
+
for (let iCommon = iStart; iCommon !== i; iCommon += 1) {
|
525
577
|
pushCommonLine(diffs[iCommon][1]);
|
578
|
+
}
|
526
579
|
}
|
527
580
|
}
|
528
581
|
}
|
@@ -535,8 +588,9 @@ function joinAlignedDiffsNoExpand(diffs, options) {
|
|
535
588
|
i += 1;
|
536
589
|
}
|
537
590
|
}
|
538
|
-
if (hasPatch)
|
591
|
+
if (hasPatch) {
|
539
592
|
lines[jPatchMark] = createPatchMark(aStart, aEnd, bStart, bEnd, options);
|
593
|
+
}
|
540
594
|
return lines.join("\n");
|
541
595
|
}
|
542
596
|
function joinAlignedDiffsExpand(diffs, options) {
|
@@ -626,8 +680,9 @@ function printAnnotation({
|
|
626
680
|
includeChangeCounts,
|
627
681
|
omitAnnotationLines
|
628
682
|
}, changeCounts) {
|
629
|
-
if (omitAnnotationLines)
|
683
|
+
if (omitAnnotationLines) {
|
630
684
|
return "";
|
685
|
+
}
|
631
686
|
let aRest = "";
|
632
687
|
let bRest = "";
|
633
688
|
if (includeChangeCounts) {
|
@@ -660,11 +715,7 @@ function diffLinesUnified(aLines, bLines, options) {
|
|
660
715
|
isEmptyString(bLines) ? [] : bLines,
|
661
716
|
normalizedOptions
|
662
717
|
);
|
663
|
-
return printDiffLines(
|
664
|
-
diffs,
|
665
|
-
truncated,
|
666
|
-
normalizedOptions
|
667
|
-
);
|
718
|
+
return printDiffLines(diffs, truncated, normalizedOptions);
|
668
719
|
}
|
669
720
|
function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCompare, options) {
|
670
721
|
if (isEmptyString(aLinesDisplay) && isEmptyString(aLinesCompare)) {
|
@@ -678,7 +729,11 @@ function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCo
|
|
678
729
|
if (aLinesDisplay.length !== aLinesCompare.length || bLinesDisplay.length !== bLinesCompare.length) {
|
679
730
|
return diffLinesUnified(aLinesDisplay, bLinesDisplay, options);
|
680
731
|
}
|
681
|
-
const [diffs, truncated] = diffLinesRaw(
|
732
|
+
const [diffs, truncated] = diffLinesRaw(
|
733
|
+
aLinesCompare,
|
734
|
+
bLinesCompare,
|
735
|
+
options
|
736
|
+
);
|
682
737
|
let aIndex = 0;
|
683
738
|
let bIndex = 0;
|
684
739
|
diffs.forEach((diff2) => {
|
@@ -701,7 +756,10 @@ function diffLinesUnified2(aLinesDisplay, bLinesDisplay, aLinesCompare, bLinesCo
|
|
701
756
|
}
|
702
757
|
function diffLinesRaw(aLines, bLines, options) {
|
703
758
|
const truncate = (options == null ? void 0 : options.truncateThreshold) ?? false;
|
704
|
-
const truncateThreshold = Math.max(
|
759
|
+
const truncateThreshold = Math.max(
|
760
|
+
Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0),
|
761
|
+
0
|
762
|
+
);
|
705
763
|
const aLength = truncate ? Math.min(aLines.length, truncateThreshold) : aLines.length;
|
706
764
|
const bLength = truncate ? Math.min(bLines.length, truncateThreshold) : bLines.length;
|
707
765
|
const truncated = aLength !== aLines.length || bLength !== bLines.length;
|
@@ -710,19 +768,24 @@ function diffLinesRaw(aLines, bLines, options) {
|
|
710
768
|
let aIndex = 0;
|
711
769
|
let bIndex = 0;
|
712
770
|
const foundSubsequence = (nCommon, aCommon, bCommon) => {
|
713
|
-
for (; aIndex !== aCommon; aIndex += 1)
|
771
|
+
for (; aIndex !== aCommon; aIndex += 1) {
|
714
772
|
diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
|
715
|
-
|
773
|
+
}
|
774
|
+
for (; bIndex !== bCommon; bIndex += 1) {
|
716
775
|
diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
|
717
|
-
|
776
|
+
}
|
777
|
+
for (; nCommon !== 0; nCommon -= 1, aIndex += 1, bIndex += 1) {
|
718
778
|
diffs.push(new Diff(DIFF_EQUAL, bLines[bIndex]));
|
779
|
+
}
|
719
780
|
};
|
720
781
|
const diffSequences = diff$1.default.default || diff$1.default;
|
721
782
|
diffSequences(aLength, bLength, isCommon, foundSubsequence);
|
722
|
-
for (; aIndex !== aLength; aIndex += 1)
|
783
|
+
for (; aIndex !== aLength; aIndex += 1) {
|
723
784
|
diffs.push(new Diff(DIFF_DELETE, aLines[aIndex]));
|
724
|
-
|
785
|
+
}
|
786
|
+
for (; bIndex !== bLength; bIndex += 1) {
|
725
787
|
diffs.push(new Diff(DIFF_INSERT, bLines[bIndex]));
|
788
|
+
}
|
726
789
|
return [diffs, truncated];
|
727
790
|
}
|
728
791
|
|
@@ -731,7 +794,10 @@ function getNewLineSymbol(string) {
|
|
731
794
|
}
|
732
795
|
function diffStrings(a, b, options) {
|
733
796
|
const truncate = (options == null ? void 0 : options.truncateThreshold) ?? false;
|
734
|
-
const truncateThreshold = Math.max(
|
797
|
+
const truncateThreshold = Math.max(
|
798
|
+
Math.floor((options == null ? void 0 : options.truncateThreshold) ?? 0),
|
799
|
+
0
|
800
|
+
);
|
735
801
|
let aLength = a.length;
|
736
802
|
let bLength = b.length;
|
737
803
|
if (truncate) {
|
@@ -752,20 +818,24 @@ function diffStrings(a, b, options) {
|
|
752
818
|
let bIndex = 0;
|
753
819
|
const diffs = [];
|
754
820
|
const foundSubsequence = (nCommon, aCommon, bCommon) => {
|
755
|
-
if (aIndex !== aCommon)
|
821
|
+
if (aIndex !== aCommon) {
|
756
822
|
diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex, aCommon)));
|
757
|
-
|
823
|
+
}
|
824
|
+
if (bIndex !== bCommon) {
|
758
825
|
diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex, bCommon)));
|
826
|
+
}
|
759
827
|
aIndex = aCommon + nCommon;
|
760
828
|
bIndex = bCommon + nCommon;
|
761
829
|
diffs.push(new Diff(DIFF_EQUAL, b.slice(bCommon, bIndex)));
|
762
830
|
};
|
763
831
|
const diffSequences = diff$1.default.default || diff$1.default;
|
764
832
|
diffSequences(aLength, bLength, isCommon, foundSubsequence);
|
765
|
-
if (aIndex !== aLength)
|
833
|
+
if (aIndex !== aLength) {
|
766
834
|
diffs.push(new Diff(DIFF_DELETE, a.slice(aIndex)));
|
767
|
-
|
835
|
+
}
|
836
|
+
if (bIndex !== bLength) {
|
768
837
|
diffs.push(new Diff(DIFF_INSERT, b.slice(bIndex)));
|
838
|
+
}
|
769
839
|
return [diffs, truncated];
|
770
840
|
}
|
771
841
|
|
@@ -828,8 +898,9 @@ class ChangeBuffer {
|
|
828
898
|
}
|
829
899
|
// Output from buffer.
|
830
900
|
moveLinesTo(lines) {
|
831
|
-
if (!this.isLineEmpty())
|
901
|
+
if (!this.isLineEmpty()) {
|
832
902
|
this.pushLine();
|
903
|
+
}
|
833
904
|
lines.push(...this.lines);
|
834
905
|
this.lines.length = 0;
|
835
906
|
}
|
@@ -848,10 +919,12 @@ class CommonBuffer {
|
|
848
919
|
}
|
849
920
|
pushDiffChangeLines(diff) {
|
850
921
|
const isDiffEmpty = diff[1].length === 0;
|
851
|
-
if (!isDiffEmpty || this.deleteBuffer.isLineEmpty())
|
922
|
+
if (!isDiffEmpty || this.deleteBuffer.isLineEmpty()) {
|
852
923
|
this.deleteBuffer.pushDiff(diff);
|
853
|
-
|
924
|
+
}
|
925
|
+
if (!isDiffEmpty || this.insertBuffer.isLineEmpty()) {
|
854
926
|
this.insertBuffer.pushDiff(diff);
|
927
|
+
}
|
855
928
|
}
|
856
929
|
flushChangeLines() {
|
857
930
|
this.deleteBuffer.moveLinesTo(this.lines);
|
@@ -940,8 +1013,9 @@ function diffStringsUnified(a, b, options) {
|
|
940
1013
|
}
|
941
1014
|
function diffStringsRaw(a, b, cleanup, options) {
|
942
1015
|
const [diffs, truncated] = diffStrings(a, b, options);
|
943
|
-
if (cleanup)
|
1016
|
+
if (cleanup) {
|
944
1017
|
diff_cleanupSemantic(diffs);
|
1018
|
+
}
|
945
1019
|
return [diffs, truncated];
|
946
1020
|
}
|
947
1021
|
|
@@ -974,8 +1048,9 @@ const FALLBACK_FORMAT_OPTIONS = {
|
|
974
1048
|
plugins: PLUGINS
|
975
1049
|
};
|
976
1050
|
function diff(a, b, options) {
|
977
|
-
if (Object.is(a, b))
|
1051
|
+
if (Object.is(a, b)) {
|
978
1052
|
return "";
|
1053
|
+
}
|
979
1054
|
const aType = getType(a);
|
980
1055
|
let expectedType = aType;
|
981
1056
|
let omitDifference = false;
|
@@ -1002,8 +1077,9 @@ ${bDisplay}`;
|
|
1002
1077
|
|
1003
1078
|
${bDiff}`;
|
1004
1079
|
}
|
1005
|
-
if (omitDifference)
|
1080
|
+
if (omitDifference) {
|
1006
1081
|
return null;
|
1082
|
+
}
|
1007
1083
|
switch (aType) {
|
1008
1084
|
case "string":
|
1009
1085
|
return diffLinesUnified(a.split("\n"), b.split("\n"), options);
|
package/dist/error.js
CHANGED
@@ -13,33 +13,45 @@ function isImmutable(v) {
|
|
13
13
|
}
|
14
14
|
const OBJECT_PROTO = Object.getPrototypeOf({});
|
15
15
|
function getUnserializableMessage(err) {
|
16
|
-
if (err instanceof Error)
|
16
|
+
if (err instanceof Error) {
|
17
17
|
return `<unserializable>: ${err.message}`;
|
18
|
-
|
18
|
+
}
|
19
|
+
if (typeof err === "string") {
|
19
20
|
return `<unserializable>: ${err}`;
|
21
|
+
}
|
20
22
|
return "<unserializable>";
|
21
23
|
}
|
22
24
|
function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
23
|
-
if (!val || typeof val === "string")
|
25
|
+
if (!val || typeof val === "string") {
|
24
26
|
return val;
|
25
|
-
|
27
|
+
}
|
28
|
+
if (typeof val === "function") {
|
26
29
|
return `Function<${val.name || "anonymous"}>`;
|
27
|
-
|
30
|
+
}
|
31
|
+
if (typeof val === "symbol") {
|
28
32
|
return val.toString();
|
29
|
-
|
33
|
+
}
|
34
|
+
if (typeof val !== "object") {
|
30
35
|
return val;
|
31
|
-
|
36
|
+
}
|
37
|
+
if (isImmutable(val)) {
|
32
38
|
return serializeError(val.toJSON(), seen);
|
33
|
-
|
39
|
+
}
|
40
|
+
if (val instanceof Promise || val.constructor && val.constructor.prototype === "AsyncFunction") {
|
34
41
|
return "Promise";
|
35
|
-
|
42
|
+
}
|
43
|
+
if (typeof Element !== "undefined" && val instanceof Element) {
|
36
44
|
return val.tagName;
|
37
|
-
|
45
|
+
}
|
46
|
+
if (typeof val.asymmetricMatch === "function") {
|
38
47
|
return `${val.toString()} ${format(val.sample)}`;
|
39
|
-
|
40
|
-
|
41
|
-
|
48
|
+
}
|
49
|
+
if (typeof val.toJSON === "function") {
|
50
|
+
return serializeError(val.toJSON(), seen);
|
51
|
+
}
|
52
|
+
if (seen.has(val)) {
|
42
53
|
return seen.get(val);
|
54
|
+
}
|
43
55
|
if (Array.isArray(val)) {
|
44
56
|
const clone = new Array(val.length);
|
45
57
|
seen.set(val, clone);
|
@@ -57,8 +69,9 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
|
57
69
|
let obj = val;
|
58
70
|
while (obj && obj !== OBJECT_PROTO) {
|
59
71
|
Object.getOwnPropertyNames(obj).forEach((key) => {
|
60
|
-
if (key in clone)
|
72
|
+
if (key in clone) {
|
61
73
|
return;
|
74
|
+
}
|
62
75
|
try {
|
63
76
|
clone[key] = serializeError(val[key], seen);
|
64
77
|
} catch (err) {
|
@@ -75,25 +88,37 @@ function normalizeErrorMessage(message) {
|
|
75
88
|
return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "");
|
76
89
|
}
|
77
90
|
function processError(err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
|
78
|
-
if (!err || typeof err !== "object")
|
91
|
+
if (!err || typeof err !== "object") {
|
79
92
|
return { message: err };
|
80
|
-
|
93
|
+
}
|
94
|
+
if (err.stack) {
|
81
95
|
err.stackStr = String(err.stack);
|
82
|
-
|
96
|
+
}
|
97
|
+
if (err.name) {
|
83
98
|
err.nameStr = String(err.name);
|
99
|
+
}
|
84
100
|
if (err.showDiff || err.showDiff === void 0 && err.expected !== void 0 && err.actual !== void 0) {
|
85
101
|
const clonedActual = deepClone(err.actual, { forceWritable: true });
|
86
102
|
const clonedExpected = deepClone(err.expected, { forceWritable: true });
|
87
|
-
const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(
|
88
|
-
|
103
|
+
const { replacedActual, replacedExpected } = replaceAsymmetricMatcher(
|
104
|
+
clonedActual,
|
105
|
+
clonedExpected
|
106
|
+
);
|
107
|
+
err.diff = diff(replacedExpected, replacedActual, {
|
108
|
+
...diffOptions,
|
109
|
+
...err.diffOptions
|
110
|
+
});
|
89
111
|
}
|
90
|
-
if (typeof err.expected !== "string")
|
112
|
+
if (typeof err.expected !== "string") {
|
91
113
|
err.expected = stringify(err.expected, 10);
|
92
|
-
|
114
|
+
}
|
115
|
+
if (typeof err.actual !== "string") {
|
93
116
|
err.actual = stringify(err.actual, 10);
|
117
|
+
}
|
94
118
|
try {
|
95
|
-
if (typeof err.message === "string")
|
119
|
+
if (typeof err.message === "string") {
|
96
120
|
err.message = normalizeErrorMessage(err.message);
|
121
|
+
}
|
97
122
|
} catch {
|
98
123
|
}
|
99
124
|
try {
|
@@ -106,8 +131,12 @@ function processError(err, diffOptions, seen = /* @__PURE__ */ new WeakSet()) {
|
|
106
131
|
try {
|
107
132
|
return serializeError(err);
|
108
133
|
} catch (e) {
|
109
|
-
return serializeError(
|
110
|
-
|
134
|
+
return serializeError(
|
135
|
+
new Error(
|
136
|
+
`Failed to fully serialize error: ${e == null ? void 0 : e.message}
|
137
|
+
Inner error message: ${err == null ? void 0 : err.message}`
|
138
|
+
)
|
139
|
+
);
|
111
140
|
}
|
112
141
|
}
|
113
142
|
function isAsymmetricMatcher(data) {
|
@@ -120,21 +149,25 @@ function isReplaceable(obj1, obj2) {
|
|
120
149
|
return obj1Type === obj2Type && (obj1Type === "Object" || obj1Type === "Array");
|
121
150
|
}
|
122
151
|
function replaceAsymmetricMatcher(actual, expected, actualReplaced = /* @__PURE__ */ new WeakSet(), expectedReplaced = /* @__PURE__ */ new WeakSet()) {
|
123
|
-
if (!isReplaceable(actual, expected))
|
152
|
+
if (!isReplaceable(actual, expected)) {
|
124
153
|
return { replacedActual: actual, replacedExpected: expected };
|
125
|
-
|
154
|
+
}
|
155
|
+
if (actualReplaced.has(actual) || expectedReplaced.has(expected)) {
|
126
156
|
return { replacedActual: actual, replacedExpected: expected };
|
157
|
+
}
|
127
158
|
actualReplaced.add(actual);
|
128
159
|
expectedReplaced.add(expected);
|
129
160
|
getOwnProperties(expected).forEach((key) => {
|
130
161
|
const expectedValue = expected[key];
|
131
162
|
const actualValue = actual[key];
|
132
163
|
if (isAsymmetricMatcher(expectedValue)) {
|
133
|
-
if (expectedValue.asymmetricMatch(actualValue))
|
164
|
+
if (expectedValue.asymmetricMatch(actualValue)) {
|
134
165
|
actual[key] = expectedValue;
|
166
|
+
}
|
135
167
|
} else if (isAsymmetricMatcher(actualValue)) {
|
136
|
-
if (actualValue.asymmetricMatch(expectedValue))
|
168
|
+
if (actualValue.asymmetricMatch(expectedValue)) {
|
137
169
|
expected[key] = actualValue;
|
170
|
+
}
|
138
171
|
} else if (isReplaceable(actualValue, expectedValue)) {
|
139
172
|
const replaced = replaceAsymmetricMatcher(
|
140
173
|
actualValue,
|
package/dist/helpers.js
CHANGED
@@ -4,8 +4,11 @@ function notNullish(v) {
|
|
4
4
|
function assertTypes(value, name, types) {
|
5
5
|
const receivedType = typeof value;
|
6
6
|
const pass = types.includes(receivedType);
|
7
|
-
if (!pass)
|
8
|
-
throw new TypeError(
|
7
|
+
if (!pass) {
|
8
|
+
throw new TypeError(
|
9
|
+
`${name} value must be ${types.join(" or ")}, received "${receivedType}"`
|
10
|
+
);
|
11
|
+
}
|
9
12
|
}
|
10
13
|
function isPrimitive(value) {
|
11
14
|
return value === null || typeof value !== "function" && typeof value !== "object";
|
@@ -15,17 +18,21 @@ function slash(path) {
|
|
15
18
|
}
|
16
19
|
function parseRegexp(input) {
|
17
20
|
const m = input.match(/(\/?)(.+)\1([a-z]*)/i);
|
18
|
-
if (!m)
|
21
|
+
if (!m) {
|
19
22
|
return /$^/;
|
20
|
-
|
23
|
+
}
|
24
|
+
if (m[3] && !/^(?!.*?(.).*?\1)[gmixXsuUAJ]+$/.test(m[3])) {
|
21
25
|
return RegExp(input);
|
26
|
+
}
|
22
27
|
return new RegExp(m[2], m[3]);
|
23
28
|
}
|
24
29
|
function toArray(array) {
|
25
|
-
if (array === null || array === void 0)
|
30
|
+
if (array === null || array === void 0) {
|
26
31
|
array = [];
|
27
|
-
|
32
|
+
}
|
33
|
+
if (Array.isArray(array)) {
|
28
34
|
return array;
|
35
|
+
}
|
29
36
|
return [array];
|
30
37
|
}
|
31
38
|
function isObject(item) {
|
@@ -44,8 +51,9 @@ function collectOwnProperties(obj, collector) {
|
|
44
51
|
}
|
45
52
|
function getOwnProperties(obj) {
|
46
53
|
const ownProps = /* @__PURE__ */ new Set();
|
47
|
-
if (isFinalObj(obj))
|
54
|
+
if (isFinalObj(obj)) {
|
48
55
|
return [];
|
56
|
+
}
|
49
57
|
collectOwnProperties(obj, ownProps);
|
50
58
|
return Array.from(ownProps);
|
51
59
|
}
|
@@ -56,12 +64,15 @@ function deepClone(val, options = defaultCloneOptions) {
|
|
56
64
|
}
|
57
65
|
function clone(val, seen, options = defaultCloneOptions) {
|
58
66
|
let k, out;
|
59
|
-
if (seen.has(val))
|
67
|
+
if (seen.has(val)) {
|
60
68
|
return seen.get(val);
|
69
|
+
}
|
61
70
|
if (Array.isArray(val)) {
|
62
71
|
out = Array(k = val.length);
|
63
72
|
seen.set(val, out);
|
64
|
-
while (k--)
|
73
|
+
while (k--) {
|
74
|
+
out[k] = clone(val[k], seen, options);
|
75
|
+
}
|
65
76
|
return out;
|
66
77
|
}
|
67
78
|
if (Object.prototype.toString.call(val) === "[object Object]") {
|
@@ -70,8 +81,9 @@ function clone(val, seen, options = defaultCloneOptions) {
|
|
70
81
|
const props = getOwnProperties(val);
|
71
82
|
for (const k2 of props) {
|
72
83
|
const descriptor = Object.getOwnPropertyDescriptor(val, k2);
|
73
|
-
if (!descriptor)
|
84
|
+
if (!descriptor) {
|
74
85
|
continue;
|
86
|
+
}
|
75
87
|
const cloned = clone(val[k2], seen, options);
|
76
88
|
if (options.forceWritable) {
|
77
89
|
Object.defineProperty(out, k2, {
|
@@ -105,8 +117,9 @@ function objectAttr(source, path, defaultValue = void 0) {
|
|
105
117
|
let result = source;
|
106
118
|
for (const p of paths) {
|
107
119
|
result = Object(result)[p];
|
108
|
-
if (result === void 0)
|
120
|
+
if (result === void 0) {
|
109
121
|
return defaultValue;
|
122
|
+
}
|
110
123
|
}
|
111
124
|
return result;
|
112
125
|
}
|
@@ -133,25 +146,30 @@ function getCallLastIndex(code) {
|
|
133
146
|
const char = code[charIndex];
|
134
147
|
const isCharString = char === '"' || char === "'" || char === "`";
|
135
148
|
if (isCharString && beforeChar !== "\\") {
|
136
|
-
if (inString === char)
|
149
|
+
if (inString === char) {
|
137
150
|
inString = null;
|
138
|
-
else if (!inString)
|
151
|
+
} else if (!inString) {
|
139
152
|
inString = char;
|
153
|
+
}
|
140
154
|
}
|
141
155
|
if (!inString) {
|
142
|
-
if (char === "(")
|
156
|
+
if (char === "(") {
|
143
157
|
startedBracers++;
|
144
|
-
|
158
|
+
}
|
159
|
+
if (char === ")") {
|
145
160
|
endedBracers++;
|
161
|
+
}
|
146
162
|
}
|
147
|
-
if (startedBracers && endedBracers && startedBracers === endedBracers)
|
163
|
+
if (startedBracers && endedBracers && startedBracers === endedBracers) {
|
148
164
|
return charIndex;
|
165
|
+
}
|
149
166
|
}
|
150
167
|
return null;
|
151
168
|
}
|
152
169
|
function isNegativeNaN(val) {
|
153
|
-
if (!Number.isNaN(val))
|
170
|
+
if (!Number.isNaN(val)) {
|
154
171
|
return false;
|
172
|
+
}
|
155
173
|
const f64 = new Float64Array(1);
|
156
174
|
f64[0] = val;
|
157
175
|
const u32 = new Uint32Array(f64.buffer);
|
package/dist/index.js
CHANGED
@@ -14,9 +14,7 @@ function getSafeTimers() {
|
|
14
14
|
setImmediate: safeSetImmediate,
|
15
15
|
clearImmediate: safeClearImmediate
|
16
16
|
} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis;
|
17
|
-
const {
|
18
|
-
nextTick: safeNextTick
|
19
|
-
} = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
|
17
|
+
const { nextTick: safeNextTick } = globalThis[SAFE_TIMERS_SYMBOL] || globalThis.process || { nextTick: (cb) => cb() };
|
20
18
|
return {
|
21
19
|
nextTick: safeNextTick,
|
22
20
|
setTimeout: safeSetTimeout,
|
@@ -36,9 +34,9 @@ function setSafeTimers() {
|
|
36
34
|
setImmediate: safeSetImmediate,
|
37
35
|
clearImmediate: safeClearImmediate
|
38
36
|
} = globalThis;
|
39
|
-
const {
|
40
|
-
nextTick:
|
41
|
-
}
|
37
|
+
const { nextTick: safeNextTick } = globalThis.process || {
|
38
|
+
nextTick: (cb) => cb()
|
39
|
+
};
|
42
40
|
const timers = {
|
43
41
|
nextTick: safeNextTick,
|
44
42
|
setTimeout: safeSetTimeout,
|
@@ -86,10 +84,12 @@ function positionToOffset(source, lineNumber, columnNumber) {
|
|
86
84
|
const lines = source.split(lineSplitRE);
|
87
85
|
const nl = /\r\n/.test(source) ? 2 : 1;
|
88
86
|
let start = 0;
|
89
|
-
if (lineNumber > lines.length)
|
87
|
+
if (lineNumber > lines.length) {
|
90
88
|
return source.length;
|
91
|
-
|
89
|
+
}
|
90
|
+
for (let i = 0; i < lineNumber - 1; i++) {
|
92
91
|
start += lines[i].length + nl;
|
92
|
+
}
|
93
93
|
return start + columnNumber;
|
94
94
|
}
|
95
95
|
function offsetToLineNumber(source, offset) {
|
@@ -104,8 +104,9 @@ function offsetToLineNumber(source, offset) {
|
|
104
104
|
let line = 0;
|
105
105
|
for (; line < lines.length; line++) {
|
106
106
|
const lineLength = lines[line].length + nl;
|
107
|
-
if (counted + lineLength >= offset)
|
107
|
+
if (counted + lineLength >= offset) {
|
108
108
|
break;
|
109
|
+
}
|
109
110
|
counted += lineLength;
|
110
111
|
}
|
111
112
|
return line + 1;
|
package/dist/source-map.js
CHANGED
@@ -774,24 +774,28 @@ const stackIgnorePatterns = [
|
|
774
774
|
"/node_modules/tinypool/",
|
775
775
|
"/node_modules/tinyspy/",
|
776
776
|
// browser related deps
|
777
|
-
"/deps/
|
778
|
-
"/deps
|
779
|
-
"/deps/
|
777
|
+
"/deps/chunk-",
|
778
|
+
"/deps/@vitest",
|
779
|
+
"/deps/loupe",
|
780
|
+
"/deps/chai",
|
780
781
|
/node:\w+/,
|
781
782
|
/__vitest_test__/,
|
782
783
|
/__vitest_browser__/,
|
783
784
|
/\/deps\/vitest_/
|
784
785
|
];
|
785
786
|
function extractLocation(urlLike) {
|
786
|
-
if (!urlLike.includes(":"))
|
787
|
+
if (!urlLike.includes(":")) {
|
787
788
|
return [urlLike];
|
789
|
+
}
|
788
790
|
const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
|
789
791
|
const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
|
790
|
-
if (!parts)
|
792
|
+
if (!parts) {
|
791
793
|
return [urlLike];
|
794
|
+
}
|
792
795
|
let url = parts[1];
|
793
|
-
if (url.startsWith("async "))
|
796
|
+
if (url.startsWith("async ")) {
|
794
797
|
url = url.slice(6);
|
798
|
+
}
|
795
799
|
if (url.startsWith("http:") || url.startsWith("https:")) {
|
796
800
|
const urlObj = new URL(url);
|
797
801
|
url = urlObj.pathname;
|
@@ -804,18 +808,27 @@ function extractLocation(urlLike) {
|
|
804
808
|
}
|
805
809
|
function parseSingleFFOrSafariStack(raw) {
|
806
810
|
let line = raw.trim();
|
807
|
-
if (SAFARI_NATIVE_CODE_REGEXP.test(line))
|
811
|
+
if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
|
808
812
|
return null;
|
809
|
-
|
810
|
-
|
811
|
-
|
813
|
+
}
|
814
|
+
if (line.includes(" > eval")) {
|
815
|
+
line = line.replace(
|
816
|
+
/ line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
|
817
|
+
":$1"
|
818
|
+
);
|
819
|
+
}
|
820
|
+
if (!line.includes("@") && !line.includes(":")) {
|
812
821
|
return null;
|
822
|
+
}
|
813
823
|
const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
|
814
824
|
const matches = line.match(functionNameRegex);
|
815
825
|
const functionName = matches && matches[1] ? matches[1] : void 0;
|
816
|
-
const [url, lineNumber, columnNumber] = extractLocation(
|
817
|
-
|
826
|
+
const [url, lineNumber, columnNumber] = extractLocation(
|
827
|
+
line.replace(functionNameRegex, "")
|
828
|
+
);
|
829
|
+
if (!url || !lineNumber || !columnNumber) {
|
818
830
|
return null;
|
831
|
+
}
|
819
832
|
return {
|
820
833
|
file: url,
|
821
834
|
method: functionName || "",
|
@@ -825,31 +838,40 @@ function parseSingleFFOrSafariStack(raw) {
|
|
825
838
|
}
|
826
839
|
function parseSingleStack(raw) {
|
827
840
|
const line = raw.trim();
|
828
|
-
if (!CHROME_IE_STACK_REGEXP.test(line))
|
841
|
+
if (!CHROME_IE_STACK_REGEXP.test(line)) {
|
829
842
|
return parseSingleFFOrSafariStack(line);
|
843
|
+
}
|
830
844
|
return parseSingleV8Stack(line);
|
831
845
|
}
|
832
846
|
function parseSingleV8Stack(raw) {
|
833
847
|
let line = raw.trim();
|
834
|
-
if (!CHROME_IE_STACK_REGEXP.test(line))
|
848
|
+
if (!CHROME_IE_STACK_REGEXP.test(line)) {
|
835
849
|
return null;
|
836
|
-
|
850
|
+
}
|
851
|
+
if (line.includes("(eval ")) {
|
837
852
|
line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
|
853
|
+
}
|
838
854
|
let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
|
839
855
|
const location = sanitizedLine.match(/ (\(.+\)$)/);
|
840
856
|
sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
|
841
|
-
const [url, lineNumber, columnNumber] = extractLocation(
|
857
|
+
const [url, lineNumber, columnNumber] = extractLocation(
|
858
|
+
location ? location[1] : sanitizedLine
|
859
|
+
);
|
842
860
|
let method = location && sanitizedLine || "";
|
843
861
|
let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
|
844
|
-
if (!file || !lineNumber || !columnNumber)
|
862
|
+
if (!file || !lineNumber || !columnNumber) {
|
845
863
|
return null;
|
846
|
-
|
864
|
+
}
|
865
|
+
if (method.startsWith("async ")) {
|
847
866
|
method = method.slice(6);
|
848
|
-
|
867
|
+
}
|
868
|
+
if (file.startsWith("file://")) {
|
849
869
|
file = file.slice(7);
|
870
|
+
}
|
850
871
|
file = resolve$2(file);
|
851
|
-
if (method)
|
872
|
+
if (method) {
|
852
873
|
method = method.replace(/__vite_ssr_import_\d+__\./g, "");
|
874
|
+
}
|
853
875
|
return {
|
854
876
|
method,
|
855
877
|
file,
|
@@ -860,17 +882,22 @@ function parseSingleV8Stack(raw) {
|
|
860
882
|
function parseStacktrace(stack, options = {}) {
|
861
883
|
const { ignoreStackEntries = stackIgnorePatterns } = options;
|
862
884
|
let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
|
863
|
-
if (ignoreStackEntries.length)
|
864
|
-
stacks = stacks.filter(
|
885
|
+
if (ignoreStackEntries.length) {
|
886
|
+
stacks = stacks.filter(
|
887
|
+
(stack2) => !ignoreStackEntries.some((p) => stack2.file.match(p))
|
888
|
+
);
|
889
|
+
}
|
865
890
|
return stacks.map((stack2) => {
|
866
891
|
var _a;
|
867
892
|
const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
|
868
|
-
if (!map || typeof map !== "object" || !map.version)
|
893
|
+
if (!map || typeof map !== "object" || !map.version) {
|
869
894
|
return stack2;
|
895
|
+
}
|
870
896
|
const traceMap = new TraceMap(map);
|
871
897
|
const { line, column } = originalPositionFor(traceMap, stack2);
|
872
|
-
if (line != null && column != null)
|
898
|
+
if (line != null && column != null) {
|
873
899
|
return { ...stack2, line, column };
|
900
|
+
}
|
874
901
|
return stack2;
|
875
902
|
});
|
876
903
|
}
|
@@ -881,14 +908,19 @@ function parseV8Stacktrace(stack) {
|
|
881
908
|
return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
|
882
909
|
}
|
883
910
|
function parseErrorStacktrace(e, options = {}) {
|
884
|
-
if (!e || isPrimitive(e))
|
911
|
+
if (!e || isPrimitive(e)) {
|
885
912
|
return [];
|
886
|
-
|
913
|
+
}
|
914
|
+
if (e.stacks) {
|
887
915
|
return e.stacks;
|
916
|
+
}
|
888
917
|
const stackStr = e.stack || e.stackStr || "";
|
889
918
|
let stackFrames = parseStacktrace(stackStr, options);
|
890
|
-
if (options.frameFilter)
|
891
|
-
stackFrames = stackFrames.filter(
|
919
|
+
if (options.frameFilter) {
|
920
|
+
stackFrames = stackFrames.filter(
|
921
|
+
(f) => options.frameFilter(e, f) !== false
|
922
|
+
);
|
923
|
+
}
|
892
924
|
e.stacks = stackFrames;
|
893
925
|
return stackFrames;
|
894
926
|
}
|