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