@vitest/snapshot 2.1.2 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,1632 +1,1386 @@
1
- import { plugins, format } from '@vitest/pretty-format';
2
1
  import { resolve as resolve$2 } from 'pathe';
2
+ import { plugins, format } from '@vitest/pretty-format';
3
3
 
4
- function getDefaultExportFromCjs (x) {
5
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
6
- }
7
-
8
- var naturalCompare$1 = {exports: {}};
9
-
10
- var hasRequiredNaturalCompare;
11
-
12
- function requireNaturalCompare () {
13
- if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
14
- hasRequiredNaturalCompare = 1;
15
- /*
16
- * @version 1.4.0
17
- * @date 2015-10-26
18
- * @stability 3 - Stable
19
- * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
20
- * @license MIT License
21
- */
22
-
23
-
24
- var naturalCompare = function(a, b) {
25
- var i, codeA
26
- , codeB = 1
27
- , posA = 0
28
- , posB = 0
29
- , alphabet = String.alphabet;
30
-
31
- function getCode(str, pos, code) {
32
- if (code) {
33
- for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
34
- return +str.slice(pos - 1, i)
35
- }
36
- code = alphabet && alphabet.indexOf(str.charAt(pos));
37
- return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
38
- : code < 46 ? 65 // -
39
- : code < 48 ? code - 1
40
- : code < 58 ? code + 18 // 0-9
41
- : code < 65 ? code - 11
42
- : code < 91 ? code + 11 // A-Z
43
- : code < 97 ? code - 37
44
- : code < 123 ? code + 5 // a-z
45
- : code - 63
46
- }
47
-
48
-
49
- if ((a+="") != (b+="")) for (;codeB;) {
50
- codeA = getCode(a, posA++);
51
- codeB = getCode(b, posB++);
52
-
53
- if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
54
- codeA = getCode(a, posA, posA);
55
- codeB = getCode(b, posB, posA = i);
56
- posB = i;
57
- }
58
-
59
- if (codeA != codeB) return (codeA < codeB) ? -1 : 1
60
- }
61
- return 0
62
- };
63
-
64
- try {
65
- naturalCompare$1.exports = naturalCompare;
66
- } catch (e) {
67
- String.naturalCompare = naturalCompare;
68
- }
69
- return naturalCompare$1.exports;
70
- }
71
-
72
- var naturalCompareExports = requireNaturalCompare();
73
- var naturalCompare = /*@__PURE__*/getDefaultExportFromCjs(naturalCompareExports);
74
-
75
- function notNullish(v) {
76
- return v != null;
4
+ const comma = ','.charCodeAt(0);
5
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
6
+ const intToChar = new Uint8Array(64); // 64 possible chars.
7
+ const charToInt = new Uint8Array(128); // z is 122 in ASCII
8
+ for (let i = 0; i < chars.length; i++) {
9
+ const c = chars.charCodeAt(i);
10
+ intToChar[i] = c;
11
+ charToInt[c] = i;
77
12
  }
78
- function isPrimitive(value) {
79
- return value === null || typeof value !== "function" && typeof value !== "object";
13
+ function decodeInteger(reader, relative) {
14
+ let value = 0;
15
+ let shift = 0;
16
+ let integer = 0;
17
+ do {
18
+ const c = reader.next();
19
+ integer = charToInt[c];
20
+ value |= (integer & 31) << shift;
21
+ shift += 5;
22
+ } while (integer & 32);
23
+ const shouldNegate = value & 1;
24
+ value >>>= 1;
25
+ if (shouldNegate) {
26
+ value = -0x80000000 | -value;
27
+ }
28
+ return relative + value;
80
29
  }
81
- function isObject(item) {
82
- return item != null && typeof item === "object" && !Array.isArray(item);
30
+ function hasMoreVlq(reader, max) {
31
+ if (reader.pos >= max)
32
+ return false;
33
+ return reader.peek() !== comma;
83
34
  }
84
- function getCallLastIndex(code) {
85
- let charIndex = -1;
86
- let inString = null;
87
- let startedBracers = 0;
88
- let endedBracers = 0;
89
- let beforeChar = null;
90
- while (charIndex <= code.length) {
91
- beforeChar = code[charIndex];
92
- charIndex++;
93
- const char = code[charIndex];
94
- const isCharString = char === '"' || char === "'" || char === "`";
95
- if (isCharString && beforeChar !== "\\") {
96
- if (inString === char) {
97
- inString = null;
98
- } else if (!inString) {
99
- inString = char;
100
- }
35
+ class StringReader {
36
+ constructor(buffer) {
37
+ this.pos = 0;
38
+ this.buffer = buffer;
101
39
  }
102
- if (!inString) {
103
- if (char === "(") {
104
- startedBracers++;
105
- }
106
- if (char === ")") {
107
- endedBracers++;
108
- }
40
+ next() {
41
+ return this.buffer.charCodeAt(this.pos++);
109
42
  }
110
- if (startedBracers && endedBracers && startedBracers === endedBracers) {
111
- return charIndex;
43
+ peek() {
44
+ return this.buffer.charCodeAt(this.pos);
45
+ }
46
+ indexOf(char) {
47
+ const { buffer, pos } = this;
48
+ const idx = buffer.indexOf(char, pos);
49
+ return idx === -1 ? buffer.length : idx;
112
50
  }
113
- }
114
- return null;
115
51
  }
116
52
 
117
- let getPromiseValue = () => 'Promise{…}';
118
- try {
119
- // @ts-ignore
120
- const { getPromiseDetails, kPending, kRejected } = process.binding('util');
121
- if (Array.isArray(getPromiseDetails(Promise.resolve()))) {
122
- getPromiseValue = (value, options) => {
123
- const [state, innerValue] = getPromiseDetails(value);
124
- if (state === kPending) {
125
- return 'Promise{<pending>}';
53
+ function decode(mappings) {
54
+ const { length } = mappings;
55
+ const reader = new StringReader(mappings);
56
+ const decoded = [];
57
+ let genColumn = 0;
58
+ let sourcesIndex = 0;
59
+ let sourceLine = 0;
60
+ let sourceColumn = 0;
61
+ let namesIndex = 0;
62
+ do {
63
+ const semi = reader.indexOf(';');
64
+ const line = [];
65
+ let sorted = true;
66
+ let lastCol = 0;
67
+ genColumn = 0;
68
+ while (reader.pos < semi) {
69
+ let seg;
70
+ genColumn = decodeInteger(reader, genColumn);
71
+ if (genColumn < lastCol)
72
+ sorted = false;
73
+ lastCol = genColumn;
74
+ if (hasMoreVlq(reader, semi)) {
75
+ sourcesIndex = decodeInteger(reader, sourcesIndex);
76
+ sourceLine = decodeInteger(reader, sourceLine);
77
+ sourceColumn = decodeInteger(reader, sourceColumn);
78
+ if (hasMoreVlq(reader, semi)) {
79
+ namesIndex = decodeInteger(reader, namesIndex);
80
+ seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
81
+ }
82
+ else {
83
+ seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
84
+ }
126
85
  }
127
- return `Promise${state === kRejected ? '!' : ''}{${options.inspect(innerValue, options)}}`;
128
- };
129
- }
86
+ else {
87
+ seg = [genColumn];
88
+ }
89
+ line.push(seg);
90
+ reader.pos++;
91
+ }
92
+ if (!sorted)
93
+ sort(line);
94
+ decoded.push(line);
95
+ reader.pos = semi + 1;
96
+ } while (reader.pos <= length);
97
+ return decoded;
130
98
  }
131
- catch (notNode) {
132
- /* ignore */
99
+ function sort(line) {
100
+ line.sort(sortComparator$1);
101
+ }
102
+ function sortComparator$1(a, b) {
103
+ return a[0] - b[0];
133
104
  }
134
105
 
135
- /* !
136
- * loupe
137
- * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com>
138
- * MIT Licensed
106
+ // Matches the scheme of a URL, eg "http://"
107
+ const schemeRegex = /^[\w+.-]+:\/\//;
108
+ /**
109
+ * Matches the parts of a URL:
110
+ * 1. Scheme, including ":", guaranteed.
111
+ * 2. User/password, including "@", optional.
112
+ * 3. Host, guaranteed.
113
+ * 4. Port, including ":", optional.
114
+ * 5. Path, including "/", optional.
115
+ * 6. Query, including "?", optional.
116
+ * 7. Hash, including "#", optional.
139
117
  */
140
- let nodeInspect = false;
141
- try {
142
- // eslint-disable-next-line global-require
143
- // @ts-ignore
144
- const nodeUtil = require('util');
145
- nodeInspect = nodeUtil.inspect ? nodeUtil.inspect.custom : false;
118
+ const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
119
+ /**
120
+ * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
121
+ * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
122
+ *
123
+ * 1. Host, optional.
124
+ * 2. Path, which may include "/", guaranteed.
125
+ * 3. Query, including "?", optional.
126
+ * 4. Hash, including "#", optional.
127
+ */
128
+ const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
129
+ var UrlType;
130
+ (function (UrlType) {
131
+ UrlType[UrlType["Empty"] = 1] = "Empty";
132
+ UrlType[UrlType["Hash"] = 2] = "Hash";
133
+ UrlType[UrlType["Query"] = 3] = "Query";
134
+ UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
135
+ UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
136
+ UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
137
+ UrlType[UrlType["Absolute"] = 7] = "Absolute";
138
+ })(UrlType || (UrlType = {}));
139
+ function isAbsoluteUrl(input) {
140
+ return schemeRegex.test(input);
146
141
  }
147
- catch (noNodeInspect) {
148
- nodeInspect = false;
142
+ function isSchemeRelativeUrl(input) {
143
+ return input.startsWith('//');
149
144
  }
150
-
151
- const lineSplitRE = /\r?\n/;
152
- function positionToOffset(source, lineNumber, columnNumber) {
153
- const lines = source.split(lineSplitRE);
154
- const nl = /\r\n/.test(source) ? 2 : 1;
155
- let start = 0;
156
- if (lineNumber > lines.length) {
157
- return source.length;
158
- }
159
- for (let i = 0; i < lineNumber - 1; i++) {
160
- start += lines[i].length + nl;
161
- }
162
- return start + columnNumber;
145
+ function isAbsolutePath(input) {
146
+ return input.startsWith('/');
163
147
  }
164
- function offsetToLineNumber(source, offset) {
165
- if (offset > source.length) {
166
- throw new Error(
167
- `offset is longer than source length! offset ${offset} > length ${source.length}`
168
- );
169
- }
170
- const lines = source.split(lineSplitRE);
171
- const nl = /\r\n/.test(source) ? 2 : 1;
172
- let counted = 0;
173
- let line = 0;
174
- for (; line < lines.length; line++) {
175
- const lineLength = lines[line].length + nl;
176
- if (counted + lineLength >= offset) {
177
- break;
148
+ function isFileUrl(input) {
149
+ return input.startsWith('file:');
150
+ }
151
+ function isRelative(input) {
152
+ return /^[.?#]/.test(input);
153
+ }
154
+ function parseAbsoluteUrl(input) {
155
+ const match = urlRegex.exec(input);
156
+ return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
157
+ }
158
+ function parseFileUrl(input) {
159
+ const match = fileRegex.exec(input);
160
+ const path = match[2];
161
+ return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
162
+ }
163
+ function makeUrl(scheme, user, host, port, path, query, hash) {
164
+ return {
165
+ scheme,
166
+ user,
167
+ host,
168
+ port,
169
+ path,
170
+ query,
171
+ hash,
172
+ type: UrlType.Absolute,
173
+ };
174
+ }
175
+ function parseUrl(input) {
176
+ if (isSchemeRelativeUrl(input)) {
177
+ const url = parseAbsoluteUrl('http:' + input);
178
+ url.scheme = '';
179
+ url.type = UrlType.SchemeRelative;
180
+ return url;
181
+ }
182
+ if (isAbsolutePath(input)) {
183
+ const url = parseAbsoluteUrl('http://foo.com' + input);
184
+ url.scheme = '';
185
+ url.host = '';
186
+ url.type = UrlType.AbsolutePath;
187
+ return url;
188
+ }
189
+ if (isFileUrl(input))
190
+ return parseFileUrl(input);
191
+ if (isAbsoluteUrl(input))
192
+ return parseAbsoluteUrl(input);
193
+ const url = parseAbsoluteUrl('http://foo.com/' + input);
194
+ url.scheme = '';
195
+ url.host = '';
196
+ url.type = input
197
+ ? input.startsWith('?')
198
+ ? UrlType.Query
199
+ : input.startsWith('#')
200
+ ? UrlType.Hash
201
+ : UrlType.RelativePath
202
+ : UrlType.Empty;
203
+ return url;
204
+ }
205
+ function stripPathFilename(path) {
206
+ // If a path ends with a parent directory "..", then it's a relative path with excess parent
207
+ // paths. It's not a file, so we can't strip it.
208
+ if (path.endsWith('/..'))
209
+ return path;
210
+ const index = path.lastIndexOf('/');
211
+ return path.slice(0, index + 1);
212
+ }
213
+ function mergePaths(url, base) {
214
+ normalizePath(base, base.type);
215
+ // If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
216
+ // path).
217
+ if (url.path === '/') {
218
+ url.path = base.path;
219
+ }
220
+ else {
221
+ // Resolution happens relative to the base path's directory, not the file.
222
+ url.path = stripPathFilename(base.path) + url.path;
223
+ }
224
+ }
225
+ /**
226
+ * The path can have empty directories "//", unneeded parents "foo/..", or current directory
227
+ * "foo/.". We need to normalize to a standard representation.
228
+ */
229
+ function normalizePath(url, type) {
230
+ const rel = type <= UrlType.RelativePath;
231
+ const pieces = url.path.split('/');
232
+ // We need to preserve the first piece always, so that we output a leading slash. The item at
233
+ // pieces[0] is an empty string.
234
+ let pointer = 1;
235
+ // Positive is the number of real directories we've output, used for popping a parent directory.
236
+ // Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
237
+ let positive = 0;
238
+ // We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
239
+ // generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
240
+ // real directory, we won't need to append, unless the other conditions happen again.
241
+ let addTrailingSlash = false;
242
+ for (let i = 1; i < pieces.length; i++) {
243
+ const piece = pieces[i];
244
+ // An empty directory, could be a trailing slash, or just a double "//" in the path.
245
+ if (!piece) {
246
+ addTrailingSlash = true;
247
+ continue;
248
+ }
249
+ // If we encounter a real directory, then we don't need to append anymore.
250
+ addTrailingSlash = false;
251
+ // A current directory, which we can always drop.
252
+ if (piece === '.')
253
+ continue;
254
+ // A parent directory, we need to see if there are any real directories we can pop. Else, we
255
+ // have an excess of parents, and we'll need to keep the "..".
256
+ if (piece === '..') {
257
+ if (positive) {
258
+ addTrailingSlash = true;
259
+ positive--;
260
+ pointer--;
261
+ }
262
+ else if (rel) {
263
+ // If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
264
+ // URL, protocol relative URL, or an absolute path, we don't need to keep excess.
265
+ pieces[pointer++] = piece;
266
+ }
267
+ continue;
268
+ }
269
+ // We've encountered a real directory. Move it to the next insertion pointer, which accounts for
270
+ // any popped or dropped directories.
271
+ pieces[pointer++] = piece;
272
+ positive++;
273
+ }
274
+ let path = '';
275
+ for (let i = 1; i < pointer; i++) {
276
+ path += '/' + pieces[i];
277
+ }
278
+ if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
279
+ path += '/';
280
+ }
281
+ url.path = path;
282
+ }
283
+ /**
284
+ * Attempts to resolve `input` URL/path relative to `base`.
285
+ */
286
+ function resolve$1(input, base) {
287
+ if (!input && !base)
288
+ return '';
289
+ const url = parseUrl(input);
290
+ let inputType = url.type;
291
+ if (base && inputType !== UrlType.Absolute) {
292
+ const baseUrl = parseUrl(base);
293
+ const baseType = baseUrl.type;
294
+ switch (inputType) {
295
+ case UrlType.Empty:
296
+ url.hash = baseUrl.hash;
297
+ // fall through
298
+ case UrlType.Hash:
299
+ url.query = baseUrl.query;
300
+ // fall through
301
+ case UrlType.Query:
302
+ case UrlType.RelativePath:
303
+ mergePaths(url, baseUrl);
304
+ // fall through
305
+ case UrlType.AbsolutePath:
306
+ // The host, user, and port are joined, you can't copy one without the others.
307
+ url.user = baseUrl.user;
308
+ url.host = baseUrl.host;
309
+ url.port = baseUrl.port;
310
+ // fall through
311
+ case UrlType.SchemeRelative:
312
+ // The input doesn't have a schema at least, so we need to copy at least that over.
313
+ url.scheme = baseUrl.scheme;
314
+ }
315
+ if (baseType > inputType)
316
+ inputType = baseType;
317
+ }
318
+ normalizePath(url, inputType);
319
+ const queryHash = url.query + url.hash;
320
+ switch (inputType) {
321
+ // This is impossible, because of the empty checks at the start of the function.
322
+ // case UrlType.Empty:
323
+ case UrlType.Hash:
324
+ case UrlType.Query:
325
+ return queryHash;
326
+ case UrlType.RelativePath: {
327
+ // The first char is always a "/", and we need it to be relative.
328
+ const path = url.path.slice(1);
329
+ if (!path)
330
+ return queryHash || '.';
331
+ if (isRelative(base || input) && !isRelative(path)) {
332
+ // If base started with a leading ".", or there is no base and input started with a ".",
333
+ // then we need to ensure that the relative path starts with a ".". We don't know if
334
+ // relative starts with a "..", though, so check before prepending.
335
+ return './' + path + queryHash;
336
+ }
337
+ return path + queryHash;
338
+ }
339
+ case UrlType.AbsolutePath:
340
+ return url.path + queryHash;
341
+ default:
342
+ return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
178
343
  }
179
- counted += lineLength;
180
- }
181
- return line + 1;
182
344
  }
183
345
 
184
- var jsTokens_1;
185
- var hasRequiredJsTokens;
346
+ function resolve(input, base) {
347
+ // The base is always treated as a directory, if it's not empty.
348
+ // https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
349
+ // https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
350
+ if (base && !base.endsWith('/'))
351
+ base += '/';
352
+ return resolve$1(input, base);
353
+ }
186
354
 
187
- function requireJsTokens () {
188
- if (hasRequiredJsTokens) return jsTokens_1;
189
- hasRequiredJsTokens = 1;
190
- // Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
191
- // License: MIT.
192
- var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
193
- RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
194
- Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
195
- Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
196
- StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
197
- NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y;
198
- Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
199
- WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
200
- LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
201
- MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
202
- SingleLineComment = /\/\/.*/y;
203
- JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
204
- JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
205
- JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
206
- JSXText = /[^<>{}]+/y;
207
- TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
208
- TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
209
- KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
210
- KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
211
- Newline = RegExp(LineTerminatorSequence.source);
212
- jsTokens_1 = function*(input, {jsx = false} = {}) {
213
- var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
214
- ({length} = input);
215
- lastIndex = 0;
216
- lastSignificantToken = "";
217
- stack = [
218
- {tag: "JS"}
219
- ];
220
- braces = [];
221
- parenNesting = 0;
222
- postfixIncDec = false;
223
- while (lastIndex < length) {
224
- mode = stack[stack.length - 1];
225
- switch (mode.tag) {
226
- case "JS":
227
- case "JSNonExpressionParen":
228
- case "InterpolationInTemplate":
229
- case "InterpolationInJSX":
230
- if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
231
- RegularExpressionLiteral.lastIndex = lastIndex;
232
- if (match = RegularExpressionLiteral.exec(input)) {
233
- lastIndex = RegularExpressionLiteral.lastIndex;
234
- lastSignificantToken = match[0];
235
- postfixIncDec = true;
236
- yield ({
237
- type: "RegularExpressionLiteral",
238
- value: match[0],
239
- closed: match[1] !== void 0 && match[1] !== "\\"
240
- });
241
- continue;
242
- }
243
- }
244
- Punctuator.lastIndex = lastIndex;
245
- if (match = Punctuator.exec(input)) {
246
- punctuator = match[0];
247
- nextLastIndex = Punctuator.lastIndex;
248
- nextLastSignificantToken = punctuator;
249
- switch (punctuator) {
250
- case "(":
251
- if (lastSignificantToken === "?NonExpressionParenKeyword") {
252
- stack.push({
253
- tag: "JSNonExpressionParen",
254
- nesting: parenNesting
255
- });
256
- }
257
- parenNesting++;
258
- postfixIncDec = false;
259
- break;
260
- case ")":
261
- parenNesting--;
262
- postfixIncDec = true;
263
- if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
264
- stack.pop();
265
- nextLastSignificantToken = "?NonExpressionParenEnd";
266
- postfixIncDec = false;
267
- }
268
- break;
269
- case "{":
270
- Punctuator.lastIndex = 0;
271
- isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
272
- braces.push(isExpression);
273
- postfixIncDec = false;
274
- break;
275
- case "}":
276
- switch (mode.tag) {
277
- case "InterpolationInTemplate":
278
- if (braces.length === mode.nesting) {
279
- Template.lastIndex = lastIndex;
280
- match = Template.exec(input);
281
- lastIndex = Template.lastIndex;
282
- lastSignificantToken = match[0];
283
- if (match[1] === "${") {
284
- lastSignificantToken = "?InterpolationInTemplate";
285
- postfixIncDec = false;
286
- yield ({
287
- type: "TemplateMiddle",
288
- value: match[0]
289
- });
290
- } else {
291
- stack.pop();
292
- postfixIncDec = true;
293
- yield ({
294
- type: "TemplateTail",
295
- value: match[0],
296
- closed: match[1] === "`"
297
- });
298
- }
299
- continue;
300
- }
301
- break;
302
- case "InterpolationInJSX":
303
- if (braces.length === mode.nesting) {
304
- stack.pop();
305
- lastIndex += 1;
306
- lastSignificantToken = "}";
307
- yield ({
308
- type: "JSXPunctuator",
309
- value: "}"
310
- });
311
- continue;
312
- }
313
- }
314
- postfixIncDec = braces.pop();
315
- nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
316
- break;
317
- case "]":
318
- postfixIncDec = true;
319
- break;
320
- case "++":
321
- case "--":
322
- nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
323
- break;
324
- case "<":
325
- if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
326
- stack.push({tag: "JSXTag"});
327
- lastIndex += 1;
328
- lastSignificantToken = "<";
329
- yield ({
330
- type: "JSXPunctuator",
331
- value: punctuator
332
- });
333
- continue;
334
- }
335
- postfixIncDec = false;
336
- break;
337
- default:
338
- postfixIncDec = false;
339
- }
340
- lastIndex = nextLastIndex;
341
- lastSignificantToken = nextLastSignificantToken;
342
- yield ({
343
- type: "Punctuator",
344
- value: punctuator
345
- });
346
- continue;
347
- }
348
- Identifier.lastIndex = lastIndex;
349
- if (match = Identifier.exec(input)) {
350
- lastIndex = Identifier.lastIndex;
351
- nextLastSignificantToken = match[0];
352
- switch (match[0]) {
353
- case "for":
354
- case "if":
355
- case "while":
356
- case "with":
357
- if (lastSignificantToken !== "." && lastSignificantToken !== "?.") {
358
- nextLastSignificantToken = "?NonExpressionParenKeyword";
359
- }
360
- }
361
- lastSignificantToken = nextLastSignificantToken;
362
- postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
363
- yield ({
364
- type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
365
- value: match[0]
366
- });
367
- continue;
368
- }
369
- StringLiteral.lastIndex = lastIndex;
370
- if (match = StringLiteral.exec(input)) {
371
- lastIndex = StringLiteral.lastIndex;
372
- lastSignificantToken = match[0];
373
- postfixIncDec = true;
374
- yield ({
375
- type: "StringLiteral",
376
- value: match[0],
377
- closed: match[2] !== void 0
378
- });
379
- continue;
380
- }
381
- NumericLiteral.lastIndex = lastIndex;
382
- if (match = NumericLiteral.exec(input)) {
383
- lastIndex = NumericLiteral.lastIndex;
384
- lastSignificantToken = match[0];
385
- postfixIncDec = true;
386
- yield ({
387
- type: "NumericLiteral",
388
- value: match[0]
389
- });
390
- continue;
391
- }
392
- Template.lastIndex = lastIndex;
393
- if (match = Template.exec(input)) {
394
- lastIndex = Template.lastIndex;
395
- lastSignificantToken = match[0];
396
- if (match[1] === "${") {
397
- lastSignificantToken = "?InterpolationInTemplate";
398
- stack.push({
399
- tag: "InterpolationInTemplate",
400
- nesting: braces.length
401
- });
402
- postfixIncDec = false;
403
- yield ({
404
- type: "TemplateHead",
405
- value: match[0]
406
- });
407
- } else {
408
- postfixIncDec = true;
409
- yield ({
410
- type: "NoSubstitutionTemplate",
411
- value: match[0],
412
- closed: match[1] === "`"
413
- });
414
- }
415
- continue;
416
- }
417
- break;
418
- case "JSXTag":
419
- case "JSXTagEnd":
420
- JSXPunctuator.lastIndex = lastIndex;
421
- if (match = JSXPunctuator.exec(input)) {
422
- lastIndex = JSXPunctuator.lastIndex;
423
- nextLastSignificantToken = match[0];
424
- switch (match[0]) {
425
- case "<":
426
- stack.push({tag: "JSXTag"});
427
- break;
428
- case ">":
429
- stack.pop();
430
- if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
431
- nextLastSignificantToken = "?JSX";
432
- postfixIncDec = true;
433
- } else {
434
- stack.push({tag: "JSXChildren"});
435
- }
436
- break;
437
- case "{":
438
- stack.push({
439
- tag: "InterpolationInJSX",
440
- nesting: braces.length
441
- });
442
- nextLastSignificantToken = "?InterpolationInJSX";
443
- postfixIncDec = false;
444
- break;
445
- case "/":
446
- if (lastSignificantToken === "<") {
447
- stack.pop();
448
- if (stack[stack.length - 1].tag === "JSXChildren") {
449
- stack.pop();
450
- }
451
- stack.push({tag: "JSXTagEnd"});
452
- }
453
- }
454
- lastSignificantToken = nextLastSignificantToken;
455
- yield ({
456
- type: "JSXPunctuator",
457
- value: match[0]
458
- });
459
- continue;
460
- }
461
- JSXIdentifier.lastIndex = lastIndex;
462
- if (match = JSXIdentifier.exec(input)) {
463
- lastIndex = JSXIdentifier.lastIndex;
464
- lastSignificantToken = match[0];
465
- yield ({
466
- type: "JSXIdentifier",
467
- value: match[0]
468
- });
469
- continue;
470
- }
471
- JSXString.lastIndex = lastIndex;
472
- if (match = JSXString.exec(input)) {
473
- lastIndex = JSXString.lastIndex;
474
- lastSignificantToken = match[0];
475
- yield ({
476
- type: "JSXString",
477
- value: match[0],
478
- closed: match[2] !== void 0
479
- });
480
- continue;
481
- }
482
- break;
483
- case "JSXChildren":
484
- JSXText.lastIndex = lastIndex;
485
- if (match = JSXText.exec(input)) {
486
- lastIndex = JSXText.lastIndex;
487
- lastSignificantToken = match[0];
488
- yield ({
489
- type: "JSXText",
490
- value: match[0]
491
- });
492
- continue;
493
- }
494
- switch (input[lastIndex]) {
495
- case "<":
496
- stack.push({tag: "JSXTag"});
497
- lastIndex++;
498
- lastSignificantToken = "<";
499
- yield ({
500
- type: "JSXPunctuator",
501
- value: "<"
502
- });
503
- continue;
504
- case "{":
505
- stack.push({
506
- tag: "InterpolationInJSX",
507
- nesting: braces.length
508
- });
509
- lastIndex++;
510
- lastSignificantToken = "?InterpolationInJSX";
511
- postfixIncDec = false;
512
- yield ({
513
- type: "JSXPunctuator",
514
- value: "{"
515
- });
516
- continue;
517
- }
518
- }
519
- WhiteSpace.lastIndex = lastIndex;
520
- if (match = WhiteSpace.exec(input)) {
521
- lastIndex = WhiteSpace.lastIndex;
522
- yield ({
523
- type: "WhiteSpace",
524
- value: match[0]
525
- });
526
- continue;
527
- }
528
- LineTerminatorSequence.lastIndex = lastIndex;
529
- if (match = LineTerminatorSequence.exec(input)) {
530
- lastIndex = LineTerminatorSequence.lastIndex;
531
- postfixIncDec = false;
532
- if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
533
- lastSignificantToken = "?NoLineTerminatorHere";
534
- }
535
- yield ({
536
- type: "LineTerminatorSequence",
537
- value: match[0]
538
- });
539
- continue;
540
- }
541
- MultiLineComment.lastIndex = lastIndex;
542
- if (match = MultiLineComment.exec(input)) {
543
- lastIndex = MultiLineComment.lastIndex;
544
- if (Newline.test(match[0])) {
545
- postfixIncDec = false;
546
- if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
547
- lastSignificantToken = "?NoLineTerminatorHere";
548
- }
549
- }
550
- yield ({
551
- type: "MultiLineComment",
552
- value: match[0],
553
- closed: match[1] !== void 0
554
- });
555
- continue;
556
- }
557
- SingleLineComment.lastIndex = lastIndex;
558
- if (match = SingleLineComment.exec(input)) {
559
- lastIndex = SingleLineComment.lastIndex;
560
- postfixIncDec = false;
561
- yield ({
562
- type: "SingleLineComment",
563
- value: match[0]
564
- });
565
- continue;
566
- }
567
- firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
568
- lastIndex += firstCodePoint.length;
569
- lastSignificantToken = firstCodePoint;
570
- postfixIncDec = false;
571
- yield ({
572
- type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
573
- value: firstCodePoint
574
- });
575
- }
576
- return void 0;
577
- };
578
- return jsTokens_1;
579
- }
580
-
581
- requireJsTokens();
582
-
583
- // src/index.ts
584
- var reservedWords = {
585
- keyword: [
586
- "break",
587
- "case",
588
- "catch",
589
- "continue",
590
- "debugger",
591
- "default",
592
- "do",
593
- "else",
594
- "finally",
595
- "for",
596
- "function",
597
- "if",
598
- "return",
599
- "switch",
600
- "throw",
601
- "try",
602
- "var",
603
- "const",
604
- "while",
605
- "with",
606
- "new",
607
- "this",
608
- "super",
609
- "class",
610
- "extends",
611
- "export",
612
- "import",
613
- "null",
614
- "true",
615
- "false",
616
- "in",
617
- "instanceof",
618
- "typeof",
619
- "void",
620
- "delete"
621
- ],
622
- strict: [
623
- "implements",
624
- "interface",
625
- "let",
626
- "package",
627
- "private",
628
- "protected",
629
- "public",
630
- "static",
631
- "yield"
632
- ]
633
- }; new Set(reservedWords.keyword); new Set(reservedWords.strict);
634
-
635
- // src/index.ts
636
- var f = {
637
- reset: [0, 0],
638
- bold: [1, 22, "\x1B[22m\x1B[1m"],
639
- dim: [2, 22, "\x1B[22m\x1B[2m"],
640
- italic: [3, 23],
641
- underline: [4, 24],
642
- inverse: [7, 27],
643
- hidden: [8, 28],
644
- strikethrough: [9, 29],
645
- black: [30, 39],
646
- red: [31, 39],
647
- green: [32, 39],
648
- yellow: [33, 39],
649
- blue: [34, 39],
650
- magenta: [35, 39],
651
- cyan: [36, 39],
652
- white: [37, 39],
653
- gray: [90, 39],
654
- bgBlack: [40, 49],
655
- bgRed: [41, 49],
656
- bgGreen: [42, 49],
657
- bgYellow: [43, 49],
658
- bgBlue: [44, 49],
659
- bgMagenta: [45, 49],
660
- bgCyan: [46, 49],
661
- bgWhite: [47, 49],
662
- blackBright: [90, 39],
663
- redBright: [91, 39],
664
- greenBright: [92, 39],
665
- yellowBright: [93, 39],
666
- blueBright: [94, 39],
667
- magentaBright: [95, 39],
668
- cyanBright: [96, 39],
669
- whiteBright: [97, 39],
670
- bgBlackBright: [100, 49],
671
- bgRedBright: [101, 49],
672
- bgGreenBright: [102, 49],
673
- bgYellowBright: [103, 49],
674
- bgBlueBright: [104, 49],
675
- bgMagentaBright: [105, 49],
676
- bgCyanBright: [106, 49],
677
- bgWhiteBright: [107, 49]
678
- }, h = Object.entries(f);
679
- function a(n) {
680
- return String(n);
681
- }
682
- a.open = "";
683
- a.close = "";
684
- function C(n = !1) {
685
- let e = typeof process != "undefined" ? process : void 0, i = (e == null ? void 0 : e.env) || {}, g = (e == null ? void 0 : e.argv) || [];
686
- return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || n && i.TERM !== "dumb" || "CI" in i) || typeof window != "undefined" && !!window.chrome;
687
- }
688
- function p(n = !1) {
689
- let e = C(n), i = (r, t, c, o) => {
690
- let l = "", s = 0;
691
- do
692
- l += r.substring(s, o) + c, s = o + t.length, o = r.indexOf(t, s);
693
- while (~o);
694
- return l + r.substring(s);
695
- }, g = (r, t, c = r) => {
696
- let o = (l) => {
697
- let s = String(l), b = s.indexOf(t, r.length);
698
- return ~b ? r + i(s, t, c, b) + t : r + s + t;
699
- };
700
- return o.open = r, o.close = t, o;
701
- }, u = {
702
- isColorSupported: e
703
- }, d = (r) => `\x1B[${r}m`;
704
- for (let [r, t] of h)
705
- u[r] = e ? g(
706
- d(t[0]),
707
- d(t[1]),
708
- t[2]
709
- ) : a;
710
- return u;
711
- }
712
-
713
- // src/browser.ts
714
- p(!1);
715
-
716
- const serialize$1 = (val, config, indentation, depth, refs, printer) => {
717
- const name = val.getMockName();
718
- const nameString = name === "vi.fn()" ? "" : ` ${name}`;
719
- let callsString = "";
720
- if (val.mock.calls.length !== 0) {
721
- const indentationNext = indentation + config.indent;
722
- callsString = ` {${config.spacingOuter}${indentationNext}"calls": ${printer(
723
- val.mock.calls,
724
- config,
725
- indentationNext,
726
- depth,
727
- refs
728
- )}${config.min ? ", " : ","}${config.spacingOuter}${indentationNext}"results": ${printer(
729
- val.mock.results,
730
- config,
731
- indentationNext,
732
- depth,
733
- refs
734
- )}${config.min ? "" : ","}${config.spacingOuter}${indentation}}`;
735
- }
736
- return `[MockFunction${nameString}]${callsString}`;
737
- };
738
- const test = (val) => val && !!val._isMockFunction;
739
- const plugin = { serialize: serialize$1, test };
740
-
741
- const {
742
- DOMCollection,
743
- DOMElement,
744
- Immutable,
745
- ReactElement,
746
- ReactTestComponent,
747
- AsymmetricMatcher
748
- } = plugins;
749
- let PLUGINS = [
750
- ReactTestComponent,
751
- ReactElement,
752
- DOMElement,
753
- DOMCollection,
754
- Immutable,
755
- AsymmetricMatcher,
756
- plugin
757
- ];
758
- function addSerializer(plugin) {
759
- PLUGINS = [plugin].concat(PLUGINS);
760
- }
761
- function getSerializers() {
762
- return PLUGINS;
355
+ /**
356
+ * Removes everything after the last "/", but leaves the slash.
357
+ */
358
+ function stripFilename(path) {
359
+ if (!path)
360
+ return '';
361
+ const index = path.lastIndexOf('/');
362
+ return path.slice(0, index + 1);
763
363
  }
764
364
 
765
- function testNameToKey(testName, count) {
766
- return `${testName} ${count}`;
767
- }
768
- function keyToTestName(key) {
769
- if (!/ \d+$/.test(key)) {
770
- throw new Error("Snapshot keys must end with a number.");
771
- }
772
- return key.replace(/ \d+$/, "");
773
- }
774
- function getSnapshotData(content, options) {
775
- const update = options.updateSnapshot;
776
- const data = /* @__PURE__ */ Object.create(null);
777
- let snapshotContents = "";
778
- let dirty = false;
779
- if (content != null) {
780
- try {
781
- snapshotContents = content;
782
- const populate = new Function("exports", snapshotContents);
783
- populate(data);
784
- } catch {
365
+ const COLUMN = 0;
366
+ const SOURCES_INDEX = 1;
367
+ const SOURCE_LINE = 2;
368
+ const SOURCE_COLUMN = 3;
369
+ const NAMES_INDEX = 4;
370
+
371
+ function maybeSort(mappings, owned) {
372
+ const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
373
+ if (unsortedIndex === mappings.length)
374
+ return mappings;
375
+ // If we own the array (meaning we parsed it from JSON), then we're free to directly mutate it. If
376
+ // not, we do not want to modify the consumer's input array.
377
+ if (!owned)
378
+ mappings = mappings.slice();
379
+ for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
380
+ mappings[i] = sortSegments(mappings[i], owned);
785
381
  }
786
- }
787
- const isInvalid = snapshotContents;
788
- if ((update === "all" || update === "new") && isInvalid) {
789
- dirty = true;
790
- }
791
- return { data, dirty };
792
- }
793
- function addExtraLineBreaks(string) {
794
- return string.includes("\n") ? `
795
- ${string}
796
- ` : string;
797
- }
798
- function removeExtraLineBreaks(string) {
799
- return string.length > 2 && string.startsWith("\n") && string.endsWith("\n") ? string.slice(1, -1) : string;
382
+ return mappings;
800
383
  }
801
- const escapeRegex = true;
802
- const printFunctionName = false;
803
- function serialize(val, indent = 2, formatOverrides = {}) {
804
- return normalizeNewlines(
805
- format(val, {
806
- escapeRegex,
807
- indent,
808
- plugins: getSerializers(),
809
- printFunctionName,
810
- ...formatOverrides
811
- })
812
- );
384
+ function nextUnsortedSegmentLine(mappings, start) {
385
+ for (let i = start; i < mappings.length; i++) {
386
+ if (!isSorted(mappings[i]))
387
+ return i;
388
+ }
389
+ return mappings.length;
813
390
  }
814
- function escapeBacktickString(str) {
815
- return str.replace(/`|\\|\$\{/g, "\\$&");
391
+ function isSorted(line) {
392
+ for (let j = 1; j < line.length; j++) {
393
+ if (line[j][COLUMN] < line[j - 1][COLUMN]) {
394
+ return false;
395
+ }
396
+ }
397
+ return true;
816
398
  }
817
- function printBacktickString(str) {
818
- return `\`${escapeBacktickString(str)}\``;
399
+ function sortSegments(line, owned) {
400
+ if (!owned)
401
+ line = line.slice();
402
+ return line.sort(sortComparator);
819
403
  }
820
- function normalizeNewlines(string) {
821
- return string.replace(/\r\n|\r/g, "\n");
404
+ function sortComparator(a, b) {
405
+ return a[COLUMN] - b[COLUMN];
822
406
  }
823
- async function saveSnapshotFile(environment, snapshotData, snapshotPath) {
824
- const snapshots = Object.keys(snapshotData).sort(naturalCompare).map(
825
- (key) => `exports[${printBacktickString(key)}] = ${printBacktickString(
826
- normalizeNewlines(snapshotData[key])
827
- )};`
828
- );
829
- const content = `${environment.getHeader()}
830
407
 
831
- ${snapshots.join("\n\n")}
832
- `;
833
- const oldContent = await environment.readSnapshotFile(snapshotPath);
834
- const skipWriting = oldContent != null && oldContent === content;
835
- if (skipWriting) {
836
- return;
837
- }
838
- await environment.saveSnapshotFile(snapshotPath, content);
839
- }
840
- function prepareExpected(expected) {
841
- function findStartIndent() {
842
- var _a, _b;
843
- const matchObject = /^( +)\}\s+$/m.exec(expected || "");
844
- const objectIndent = (_a = matchObject == null ? void 0 : matchObject[1]) == null ? void 0 : _a.length;
845
- if (objectIndent) {
846
- return objectIndent;
408
+ let found = false;
409
+ /**
410
+ * A binary search implementation that returns the index if a match is found.
411
+ * If no match is found, then the left-index (the index associated with the item that comes just
412
+ * before the desired index) is returned. To maintain proper sort order, a splice would happen at
413
+ * the next index:
414
+ *
415
+ * ```js
416
+ * const array = [1, 3];
417
+ * const needle = 2;
418
+ * const index = binarySearch(array, needle, (item, needle) => item - needle);
419
+ *
420
+ * assert.equal(index, 0);
421
+ * array.splice(index + 1, 0, needle);
422
+ * assert.deepEqual(array, [1, 2, 3]);
423
+ * ```
424
+ */
425
+ function binarySearch(haystack, needle, low, high) {
426
+ while (low <= high) {
427
+ const mid = low + ((high - low) >> 1);
428
+ const cmp = haystack[mid][COLUMN] - needle;
429
+ if (cmp === 0) {
430
+ found = true;
431
+ return mid;
432
+ }
433
+ if (cmp < 0) {
434
+ low = mid + 1;
435
+ }
436
+ else {
437
+ high = mid - 1;
438
+ }
847
439
  }
848
- const matchText = /^\n( +)"/.exec(expected || "");
849
- return ((_b = matchText == null ? void 0 : matchText[1]) == null ? void 0 : _b.length) || 0;
850
- }
851
- const startIndent = findStartIndent();
852
- let expectedTrimmed = expected == null ? void 0 : expected.trim();
853
- if (startIndent) {
854
- expectedTrimmed = expectedTrimmed == null ? void 0 : expectedTrimmed.replace(new RegExp(`^${" ".repeat(startIndent)}`, "gm"), "").replace(/ +\}$/, "}");
855
- }
856
- return expectedTrimmed;
440
+ found = false;
441
+ return low - 1;
857
442
  }
858
- function deepMergeArray(target = [], source = []) {
859
- const mergedOutput = Array.from(target);
860
- source.forEach((sourceElement, index) => {
861
- const targetElement = mergedOutput[index];
862
- if (Array.isArray(target[index])) {
863
- mergedOutput[index] = deepMergeArray(target[index], sourceElement);
864
- } else if (isObject(targetElement)) {
865
- mergedOutput[index] = deepMergeSnapshot(target[index], sourceElement);
866
- } else {
867
- mergedOutput[index] = sourceElement;
443
+ function upperBound(haystack, needle, index) {
444
+ for (let i = index + 1; i < haystack.length; index = i++) {
445
+ if (haystack[i][COLUMN] !== needle)
446
+ break;
868
447
  }
869
- });
870
- return mergedOutput;
871
- }
872
- function deepMergeSnapshot(target, source) {
873
- if (isObject(target) && isObject(source)) {
874
- const mergedOutput = { ...target };
875
- Object.keys(source).forEach((key) => {
876
- if (isObject(source[key]) && !source[key].$$typeof) {
877
- if (!(key in target)) {
878
- Object.assign(mergedOutput, { [key]: source[key] });
879
- } else {
880
- mergedOutput[key] = deepMergeSnapshot(target[key], source[key]);
881
- }
882
- } else if (Array.isArray(source[key])) {
883
- mergedOutput[key] = deepMergeArray(target[key], source[key]);
884
- } else {
885
- Object.assign(mergedOutput, { [key]: source[key] });
886
- }
887
- });
888
- return mergedOutput;
889
- } else if (Array.isArray(target) && Array.isArray(source)) {
890
- return deepMergeArray(target, source);
891
- }
892
- return target;
893
- }
894
-
895
- const comma = ','.charCodeAt(0);
896
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
897
- const intToChar = new Uint8Array(64); // 64 possible chars.
898
- const charToInt = new Uint8Array(128); // z is 122 in ASCII
899
- for (let i = 0; i < chars.length; i++) {
900
- const c = chars.charCodeAt(i);
901
- intToChar[i] = c;
902
- charToInt[c] = i;
448
+ return index;
903
449
  }
904
- function decodeInteger(reader, relative) {
905
- let value = 0;
906
- let shift = 0;
907
- let integer = 0;
908
- do {
909
- const c = reader.next();
910
- integer = charToInt[c];
911
- value |= (integer & 31) << shift;
912
- shift += 5;
913
- } while (integer & 32);
914
- const shouldNegate = value & 1;
915
- value >>>= 1;
916
- if (shouldNegate) {
917
- value = -0x80000000 | -value;
450
+ function lowerBound(haystack, needle, index) {
451
+ for (let i = index - 1; i >= 0; index = i--) {
452
+ if (haystack[i][COLUMN] !== needle)
453
+ break;
918
454
  }
919
- return relative + value;
455
+ return index;
920
456
  }
921
- function hasMoreVlq(reader, max) {
922
- if (reader.pos >= max)
923
- return false;
924
- return reader.peek() !== comma;
457
+ function memoizedState() {
458
+ return {
459
+ lastKey: -1,
460
+ lastNeedle: -1,
461
+ lastIndex: -1,
462
+ };
925
463
  }
926
- class StringReader {
927
- constructor(buffer) {
928
- this.pos = 0;
929
- this.buffer = buffer;
930
- }
931
- next() {
932
- return this.buffer.charCodeAt(this.pos++);
933
- }
934
- peek() {
935
- return this.buffer.charCodeAt(this.pos);
936
- }
937
- indexOf(char) {
938
- const { buffer, pos } = this;
939
- const idx = buffer.indexOf(char, pos);
940
- return idx === -1 ? buffer.length : idx;
464
+ /**
465
+ * This overly complicated beast is just to record the last tested line/column and the resulting
466
+ * index, allowing us to skip a few tests if mappings are monotonically increasing.
467
+ */
468
+ function memoizedBinarySearch(haystack, needle, state, key) {
469
+ const { lastKey, lastNeedle, lastIndex } = state;
470
+ let low = 0;
471
+ let high = haystack.length - 1;
472
+ if (key === lastKey) {
473
+ if (needle === lastNeedle) {
474
+ found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
475
+ return lastIndex;
476
+ }
477
+ if (needle >= lastNeedle) {
478
+ // lastIndex may be -1 if the previous needle was not found.
479
+ low = lastIndex === -1 ? 0 : lastIndex;
480
+ }
481
+ else {
482
+ high = lastIndex;
483
+ }
941
484
  }
485
+ state.lastKey = key;
486
+ state.lastNeedle = needle;
487
+ return (state.lastIndex = binarySearch(haystack, needle, low, high));
942
488
  }
943
489
 
944
- function decode(mappings) {
945
- const { length } = mappings;
946
- const reader = new StringReader(mappings);
947
- const decoded = [];
948
- let genColumn = 0;
949
- let sourcesIndex = 0;
950
- let sourceLine = 0;
951
- let sourceColumn = 0;
952
- let namesIndex = 0;
953
- do {
954
- const semi = reader.indexOf(';');
955
- const line = [];
956
- let sorted = true;
957
- let lastCol = 0;
958
- genColumn = 0;
959
- while (reader.pos < semi) {
960
- let seg;
961
- genColumn = decodeInteger(reader, genColumn);
962
- if (genColumn < lastCol)
963
- sorted = false;
964
- lastCol = genColumn;
965
- if (hasMoreVlq(reader, semi)) {
966
- sourcesIndex = decodeInteger(reader, sourcesIndex);
967
- sourceLine = decodeInteger(reader, sourceLine);
968
- sourceColumn = decodeInteger(reader, sourceColumn);
969
- if (hasMoreVlq(reader, semi)) {
970
- namesIndex = decodeInteger(reader, namesIndex);
971
- seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
972
- }
973
- else {
974
- seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
975
- }
976
- }
977
- else {
978
- seg = [genColumn];
979
- }
980
- line.push(seg);
981
- reader.pos++;
490
+ const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
491
+ const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
492
+ const LEAST_UPPER_BOUND = -1;
493
+ const GREATEST_LOWER_BOUND = 1;
494
+ class TraceMap {
495
+ constructor(map, mapUrl) {
496
+ const isString = typeof map === 'string';
497
+ if (!isString && map._decodedMemo)
498
+ return map;
499
+ const parsed = (isString ? JSON.parse(map) : map);
500
+ const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
501
+ this.version = version;
502
+ this.file = file;
503
+ this.names = names || [];
504
+ this.sourceRoot = sourceRoot;
505
+ this.sources = sources;
506
+ this.sourcesContent = sourcesContent;
507
+ this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
508
+ const from = resolve(sourceRoot || '', stripFilename(mapUrl));
509
+ this.resolvedSources = sources.map((s) => resolve(s || '', from));
510
+ const { mappings } = parsed;
511
+ if (typeof mappings === 'string') {
512
+ this._encoded = mappings;
513
+ this._decoded = undefined;
982
514
  }
983
- if (!sorted)
984
- sort(line);
985
- decoded.push(line);
986
- reader.pos = semi + 1;
987
- } while (reader.pos <= length);
988
- return decoded;
989
- }
990
- function sort(line) {
991
- line.sort(sortComparator$1);
515
+ else {
516
+ this._encoded = undefined;
517
+ this._decoded = maybeSort(mappings, isString);
518
+ }
519
+ this._decodedMemo = memoizedState();
520
+ this._bySources = undefined;
521
+ this._bySourceMemos = undefined;
522
+ }
992
523
  }
993
- function sortComparator$1(a, b) {
994
- return a[0] - b[0];
524
+ /**
525
+ * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
526
+ * with public access modifiers.
527
+ */
528
+ function cast(map) {
529
+ return map;
995
530
  }
996
-
997
- // Matches the scheme of a URL, eg "http://"
998
- const schemeRegex = /^[\w+.-]+:\/\//;
999
531
  /**
1000
- * Matches the parts of a URL:
1001
- * 1. Scheme, including ":", guaranteed.
1002
- * 2. User/password, including "@", optional.
1003
- * 3. Host, guaranteed.
1004
- * 4. Port, including ":", optional.
1005
- * 5. Path, including "/", optional.
1006
- * 6. Query, including "?", optional.
1007
- * 7. Hash, including "#", optional.
532
+ * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
1008
533
  */
1009
- const urlRegex = /^([\w+.-]+:)\/\/([^@/#?]*@)?([^:/#?]*)(:\d+)?(\/[^#?]*)?(\?[^#]*)?(#.*)?/;
534
+ function decodedMappings(map) {
535
+ var _a;
536
+ return ((_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded)));
537
+ }
1010
538
  /**
1011
- * File URLs are weird. They dont' need the regular `//` in the scheme, they may or may not start
1012
- * with a leading `/`, they can have a domain (but only if they don't start with a Windows drive).
1013
- *
1014
- * 1. Host, optional.
1015
- * 2. Path, which may include "/", guaranteed.
1016
- * 3. Query, including "?", optional.
1017
- * 4. Hash, including "#", optional.
539
+ * A higher-level API to find the source/line/column associated with a generated line/column
540
+ * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
541
+ * `source-map` library.
1018
542
  */
1019
- const fileRegex = /^file:(?:\/\/((?![a-z]:)[^/#?]*)?)?(\/?[^#?]*)(\?[^#]*)?(#.*)?/i;
1020
- var UrlType;
1021
- (function (UrlType) {
1022
- UrlType[UrlType["Empty"] = 1] = "Empty";
1023
- UrlType[UrlType["Hash"] = 2] = "Hash";
1024
- UrlType[UrlType["Query"] = 3] = "Query";
1025
- UrlType[UrlType["RelativePath"] = 4] = "RelativePath";
1026
- UrlType[UrlType["AbsolutePath"] = 5] = "AbsolutePath";
1027
- UrlType[UrlType["SchemeRelative"] = 6] = "SchemeRelative";
1028
- UrlType[UrlType["Absolute"] = 7] = "Absolute";
1029
- })(UrlType || (UrlType = {}));
1030
- function isAbsoluteUrl(input) {
1031
- return schemeRegex.test(input);
543
+ function originalPositionFor(map, needle) {
544
+ let { line, column, bias } = needle;
545
+ line--;
546
+ if (line < 0)
547
+ throw new Error(LINE_GTR_ZERO);
548
+ if (column < 0)
549
+ throw new Error(COL_GTR_EQ_ZERO);
550
+ const decoded = decodedMappings(map);
551
+ // It's common for parent source maps to have pointers to lines that have no
552
+ // mapping (like a "//# sourceMappingURL=") at the end of the child file.
553
+ if (line >= decoded.length)
554
+ return OMapping(null, null, null, null);
555
+ const segments = decoded[line];
556
+ const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
557
+ if (index === -1)
558
+ return OMapping(null, null, null, null);
559
+ const segment = segments[index];
560
+ if (segment.length === 1)
561
+ return OMapping(null, null, null, null);
562
+ const { names, resolvedSources } = map;
563
+ return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
1032
564
  }
1033
- function isSchemeRelativeUrl(input) {
1034
- return input.startsWith('//');
565
+ function OMapping(source, line, column, name) {
566
+ return { source, line, column, name };
1035
567
  }
1036
- function isAbsolutePath(input) {
1037
- return input.startsWith('/');
568
+ function traceSegmentInternal(segments, memo, line, column, bias) {
569
+ let index = memoizedBinarySearch(segments, column, memo, line);
570
+ if (found) {
571
+ index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
572
+ }
573
+ else if (bias === LEAST_UPPER_BOUND)
574
+ index++;
575
+ if (index === -1 || index === segments.length)
576
+ return -1;
577
+ return index;
1038
578
  }
1039
- function isFileUrl(input) {
1040
- return input.startsWith('file:');
579
+
580
+ function notNullish(v) {
581
+ return v != null;
1041
582
  }
1042
- function isRelative(input) {
1043
- return /^[.?#]/.test(input);
583
+ function isPrimitive(value) {
584
+ return value === null || typeof value !== "function" && typeof value !== "object";
585
+ }
586
+ function isObject(item) {
587
+ return item != null && typeof item === "object" && !Array.isArray(item);
588
+ }
589
+ function getCallLastIndex(code) {
590
+ let charIndex = -1;
591
+ let inString = null;
592
+ let startedBracers = 0;
593
+ let endedBracers = 0;
594
+ let beforeChar = null;
595
+ while (charIndex <= code.length) {
596
+ beforeChar = code[charIndex];
597
+ charIndex++;
598
+ const char = code[charIndex];
599
+ const isCharString = char === '"' || char === "'" || char === "`";
600
+ if (isCharString && beforeChar !== "\\") {
601
+ if (inString === char) {
602
+ inString = null;
603
+ } else if (!inString) {
604
+ inString = char;
605
+ }
606
+ }
607
+ if (!inString) {
608
+ if (char === "(") {
609
+ startedBracers++;
610
+ }
611
+ if (char === ")") {
612
+ endedBracers++;
613
+ }
614
+ }
615
+ if (startedBracers && endedBracers && startedBracers === endedBracers) {
616
+ return charIndex;
617
+ }
618
+ }
619
+ return null;
1044
620
  }
1045
- function parseAbsoluteUrl(input) {
1046
- const match = urlRegex.exec(input);
1047
- return makeUrl(match[1], match[2] || '', match[3], match[4] || '', match[5] || '/', match[6] || '', match[7] || '');
621
+
622
+ const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
623
+ const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
624
+ const stackIgnorePatterns = [
625
+ "node:internal",
626
+ /\/packages\/\w+\/dist\//,
627
+ /\/@vitest\/\w+\/dist\//,
628
+ "/vitest/dist/",
629
+ "/vitest/src/",
630
+ "/vite-node/dist/",
631
+ "/vite-node/src/",
632
+ "/node_modules/chai/",
633
+ "/node_modules/tinypool/",
634
+ "/node_modules/tinyspy/",
635
+ // browser related deps
636
+ "/deps/chunk-",
637
+ "/deps/@vitest",
638
+ "/deps/loupe",
639
+ "/deps/chai",
640
+ /node:\w+/,
641
+ /__vitest_test__/,
642
+ /__vitest_browser__/,
643
+ /\/deps\/vitest_/
644
+ ];
645
+ function extractLocation(urlLike) {
646
+ if (!urlLike.includes(":")) {
647
+ return [urlLike];
648
+ }
649
+ const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
650
+ const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
651
+ if (!parts) {
652
+ return [urlLike];
653
+ }
654
+ let url = parts[1];
655
+ if (url.startsWith("async ")) {
656
+ url = url.slice(6);
657
+ }
658
+ if (url.startsWith("http:") || url.startsWith("https:")) {
659
+ const urlObj = new URL(url);
660
+ url = urlObj.pathname;
661
+ }
662
+ if (url.startsWith("/@fs/")) {
663
+ const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
664
+ url = url.slice(isWindows ? 5 : 4);
665
+ }
666
+ return [url, parts[2] || void 0, parts[3] || void 0];
1048
667
  }
1049
- function parseFileUrl(input) {
1050
- const match = fileRegex.exec(input);
1051
- const path = match[2];
1052
- return makeUrl('file:', '', match[1] || '', '', isAbsolutePath(path) ? path : '/' + path, match[3] || '', match[4] || '');
668
+ function parseSingleFFOrSafariStack(raw) {
669
+ let line = raw.trim();
670
+ if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
671
+ return null;
672
+ }
673
+ if (line.includes(" > eval")) {
674
+ line = line.replace(
675
+ / line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
676
+ ":$1"
677
+ );
678
+ }
679
+ if (!line.includes("@") && !line.includes(":")) {
680
+ return null;
681
+ }
682
+ const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
683
+ const matches = line.match(functionNameRegex);
684
+ const functionName = matches && matches[1] ? matches[1] : void 0;
685
+ const [url, lineNumber, columnNumber] = extractLocation(
686
+ line.replace(functionNameRegex, "")
687
+ );
688
+ if (!url || !lineNumber || !columnNumber) {
689
+ return null;
690
+ }
691
+ return {
692
+ file: url,
693
+ method: functionName || "",
694
+ line: Number.parseInt(lineNumber),
695
+ column: Number.parseInt(columnNumber)
696
+ };
1053
697
  }
1054
- function makeUrl(scheme, user, host, port, path, query, hash) {
1055
- return {
1056
- scheme,
1057
- user,
1058
- host,
1059
- port,
1060
- path,
1061
- query,
1062
- hash,
1063
- type: UrlType.Absolute,
1064
- };
698
+ function parseSingleV8Stack(raw) {
699
+ let line = raw.trim();
700
+ if (!CHROME_IE_STACK_REGEXP.test(line)) {
701
+ return null;
702
+ }
703
+ if (line.includes("(eval ")) {
704
+ line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
705
+ }
706
+ let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
707
+ const location = sanitizedLine.match(/ (\(.+\)$)/);
708
+ sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
709
+ const [url, lineNumber, columnNumber] = extractLocation(
710
+ location ? location[1] : sanitizedLine
711
+ );
712
+ let method = location && sanitizedLine || "";
713
+ let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
714
+ if (!file || !lineNumber || !columnNumber) {
715
+ return null;
716
+ }
717
+ if (method.startsWith("async ")) {
718
+ method = method.slice(6);
719
+ }
720
+ if (file.startsWith("file://")) {
721
+ file = file.slice(7);
722
+ }
723
+ file = resolve$2(file);
724
+ if (method) {
725
+ method = method.replace(/__vite_ssr_import_\d+__\./g, "");
726
+ }
727
+ return {
728
+ method,
729
+ file,
730
+ line: Number.parseInt(lineNumber),
731
+ column: Number.parseInt(columnNumber)
732
+ };
1065
733
  }
1066
- function parseUrl(input) {
1067
- if (isSchemeRelativeUrl(input)) {
1068
- const url = parseAbsoluteUrl('http:' + input);
1069
- url.scheme = '';
1070
- url.type = UrlType.SchemeRelative;
1071
- return url;
734
+ function parseStacktrace(stack, options = {}) {
735
+ const { ignoreStackEntries = stackIgnorePatterns } = options;
736
+ let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
737
+ if (ignoreStackEntries.length) {
738
+ stacks = stacks.filter(
739
+ (stack2) => !ignoreStackEntries.some((p) => stack2.file.match(p))
740
+ );
741
+ }
742
+ return stacks.map((stack2) => {
743
+ var _a;
744
+ if (options.getFileName) {
745
+ stack2.file = options.getFileName(stack2.file);
1072
746
  }
1073
- if (isAbsolutePath(input)) {
1074
- const url = parseAbsoluteUrl('http://foo.com' + input);
1075
- url.scheme = '';
1076
- url.host = '';
1077
- url.type = UrlType.AbsolutePath;
1078
- return url;
747
+ const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
748
+ if (!map || typeof map !== "object" || !map.version) {
749
+ return stack2;
1079
750
  }
1080
- if (isFileUrl(input))
1081
- return parseFileUrl(input);
1082
- if (isAbsoluteUrl(input))
1083
- return parseAbsoluteUrl(input);
1084
- const url = parseAbsoluteUrl('http://foo.com/' + input);
1085
- url.scheme = '';
1086
- url.host = '';
1087
- url.type = input
1088
- ? input.startsWith('?')
1089
- ? UrlType.Query
1090
- : input.startsWith('#')
1091
- ? UrlType.Hash
1092
- : UrlType.RelativePath
1093
- : UrlType.Empty;
1094
- return url;
751
+ const traceMap = new TraceMap(map);
752
+ const { line, column } = originalPositionFor(traceMap, stack2);
753
+ if (line != null && column != null) {
754
+ return { ...stack2, line, column };
755
+ }
756
+ return stack2;
757
+ });
1095
758
  }
1096
- function stripPathFilename(path) {
1097
- // If a path ends with a parent directory "..", then it's a relative path with excess parent
1098
- // paths. It's not a file, so we can't strip it.
1099
- if (path.endsWith('/..'))
1100
- return path;
1101
- const index = path.lastIndexOf('/');
1102
- return path.slice(0, index + 1);
759
+ function parseFFOrSafariStackTrace(stack) {
760
+ return stack.split("\n").map((line) => parseSingleFFOrSafariStack(line)).filter(notNullish);
1103
761
  }
1104
- function mergePaths(url, base) {
1105
- normalizePath(base, base.type);
1106
- // If the path is just a "/", then it was an empty path to begin with (remember, we're a relative
1107
- // path).
1108
- if (url.path === '/') {
1109
- url.path = base.path;
1110
- }
1111
- else {
1112
- // Resolution happens relative to the base path's directory, not the file.
1113
- url.path = stripPathFilename(base.path) + url.path;
1114
- }
762
+ function parseV8Stacktrace(stack) {
763
+ return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
1115
764
  }
1116
- /**
1117
- * The path can have empty directories "//", unneeded parents "foo/..", or current directory
1118
- * "foo/.". We need to normalize to a standard representation.
1119
- */
1120
- function normalizePath(url, type) {
1121
- const rel = type <= UrlType.RelativePath;
1122
- const pieces = url.path.split('/');
1123
- // We need to preserve the first piece always, so that we output a leading slash. The item at
1124
- // pieces[0] is an empty string.
1125
- let pointer = 1;
1126
- // Positive is the number of real directories we've output, used for popping a parent directory.
1127
- // Eg, "foo/bar/.." will have a positive 2, and we can decrement to be left with just "foo".
1128
- let positive = 0;
1129
- // We need to keep a trailing slash if we encounter an empty directory (eg, splitting "foo/" will
1130
- // generate `["foo", ""]` pieces). And, if we pop a parent directory. But once we encounter a
1131
- // real directory, we won't need to append, unless the other conditions happen again.
1132
- let addTrailingSlash = false;
1133
- for (let i = 1; i < pieces.length; i++) {
1134
- const piece = pieces[i];
1135
- // An empty directory, could be a trailing slash, or just a double "//" in the path.
1136
- if (!piece) {
1137
- addTrailingSlash = true;
1138
- continue;
1139
- }
1140
- // If we encounter a real directory, then we don't need to append anymore.
1141
- addTrailingSlash = false;
1142
- // A current directory, which we can always drop.
1143
- if (piece === '.')
1144
- continue;
1145
- // A parent directory, we need to see if there are any real directories we can pop. Else, we
1146
- // have an excess of parents, and we'll need to keep the "..".
1147
- if (piece === '..') {
1148
- if (positive) {
1149
- addTrailingSlash = true;
1150
- positive--;
1151
- pointer--;
1152
- }
1153
- else if (rel) {
1154
- // If we're in a relativePath, then we need to keep the excess parents. Else, in an absolute
1155
- // URL, protocol relative URL, or an absolute path, we don't need to keep excess.
1156
- pieces[pointer++] = piece;
765
+ function parseErrorStacktrace(e, options = {}) {
766
+ if (!e || isPrimitive(e)) {
767
+ return [];
768
+ }
769
+ if (e.stacks) {
770
+ return e.stacks;
771
+ }
772
+ const stackStr = e.stack || e.stackStr || "";
773
+ let stackFrames = parseStacktrace(stackStr, options);
774
+ if (options.frameFilter) {
775
+ stackFrames = stackFrames.filter(
776
+ (f) => options.frameFilter(e, f) !== false
777
+ );
778
+ }
779
+ e.stacks = stackFrames;
780
+ return stackFrames;
781
+ }
782
+
783
+ let getPromiseValue = () => 'Promise{…}';
784
+ try {
785
+ // @ts-ignore
786
+ const { getPromiseDetails, kPending, kRejected } = process.binding('util');
787
+ if (Array.isArray(getPromiseDetails(Promise.resolve()))) {
788
+ getPromiseValue = (value, options) => {
789
+ const [state, innerValue] = getPromiseDetails(value);
790
+ if (state === kPending) {
791
+ return 'Promise{<pending>}';
1157
792
  }
1158
- continue;
1159
- }
1160
- // We've encountered a real directory. Move it to the next insertion pointer, which accounts for
1161
- // any popped or dropped directories.
1162
- pieces[pointer++] = piece;
1163
- positive++;
1164
- }
1165
- let path = '';
1166
- for (let i = 1; i < pointer; i++) {
1167
- path += '/' + pieces[i];
1168
- }
1169
- if (!path || (addTrailingSlash && !path.endsWith('/..'))) {
1170
- path += '/';
793
+ return `Promise${state === kRejected ? '!' : ''}{${options.inspect(innerValue, options)}}`;
794
+ };
1171
795
  }
1172
- url.path = path;
1173
796
  }
1174
- /**
1175
- * Attempts to resolve `input` URL/path relative to `base`.
797
+ catch (notNode) {
798
+ /* ignore */
799
+ }
800
+
801
+ /* !
802
+ * loupe
803
+ * Copyright(c) 2013 Jake Luer <jake@alogicalparadox.com>
804
+ * MIT Licensed
1176
805
  */
1177
- function resolve$1(input, base) {
1178
- if (!input && !base)
1179
- return '';
1180
- const url = parseUrl(input);
1181
- let inputType = url.type;
1182
- if (base && inputType !== UrlType.Absolute) {
1183
- const baseUrl = parseUrl(base);
1184
- const baseType = baseUrl.type;
1185
- switch (inputType) {
1186
- case UrlType.Empty:
1187
- url.hash = baseUrl.hash;
1188
- // fall through
1189
- case UrlType.Hash:
1190
- url.query = baseUrl.query;
1191
- // fall through
1192
- case UrlType.Query:
1193
- case UrlType.RelativePath:
1194
- mergePaths(url, baseUrl);
1195
- // fall through
1196
- case UrlType.AbsolutePath:
1197
- // The host, user, and port are joined, you can't copy one without the others.
1198
- url.user = baseUrl.user;
1199
- url.host = baseUrl.host;
1200
- url.port = baseUrl.port;
1201
- // fall through
1202
- case UrlType.SchemeRelative:
1203
- // The input doesn't have a schema at least, so we need to copy at least that over.
1204
- url.scheme = baseUrl.scheme;
1205
- }
1206
- if (baseType > inputType)
1207
- inputType = baseType;
1208
- }
1209
- normalizePath(url, inputType);
1210
- const queryHash = url.query + url.hash;
1211
- switch (inputType) {
1212
- // This is impossible, because of the empty checks at the start of the function.
1213
- // case UrlType.Empty:
1214
- case UrlType.Hash:
1215
- case UrlType.Query:
1216
- return queryHash;
1217
- case UrlType.RelativePath: {
1218
- // The first char is always a "/", and we need it to be relative.
1219
- const path = url.path.slice(1);
1220
- if (!path)
1221
- return queryHash || '.';
1222
- if (isRelative(base || input) && !isRelative(path)) {
1223
- // If base started with a leading ".", or there is no base and input started with a ".",
1224
- // then we need to ensure that the relative path starts with a ".". We don't know if
1225
- // relative starts with a "..", though, so check before prepending.
1226
- return './' + path + queryHash;
1227
- }
1228
- return path + queryHash;
1229
- }
1230
- case UrlType.AbsolutePath:
1231
- return url.path + queryHash;
1232
- default:
1233
- return url.scheme + '//' + url.user + url.host + url.port + url.path + queryHash;
1234
- }
806
+ let nodeInspect = false;
807
+ try {
808
+ // eslint-disable-next-line global-require
809
+ // @ts-ignore
810
+ const nodeUtil = require('util');
811
+ nodeInspect = nodeUtil.inspect ? nodeUtil.inspect.custom : false;
812
+ }
813
+ catch (noNodeInspect) {
814
+ nodeInspect = false;
1235
815
  }
1236
816
 
1237
- function resolve(input, base) {
1238
- // The base is always treated as a directory, if it's not empty.
1239
- // https://github.com/mozilla/source-map/blob/8cb3ee57/lib/util.js#L327
1240
- // https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
1241
- if (base && !base.endsWith('/'))
1242
- base += '/';
1243
- return resolve$1(input, base);
817
+ function getDefaultExportFromCjs (x) {
818
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1244
819
  }
1245
820
 
1246
- /**
1247
- * Removes everything after the last "/", but leaves the slash.
1248
- */
1249
- function stripFilename(path) {
1250
- if (!path)
1251
- return '';
1252
- const index = path.lastIndexOf('/');
1253
- return path.slice(0, index + 1);
821
+ var jsTokens_1;
822
+ var hasRequiredJsTokens;
823
+
824
+ function requireJsTokens () {
825
+ if (hasRequiredJsTokens) return jsTokens_1;
826
+ hasRequiredJsTokens = 1;
827
+ // Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
828
+ // License: MIT.
829
+ var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
830
+ RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
831
+ Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
832
+ Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
833
+ StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
834
+ NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y;
835
+ Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
836
+ WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
837
+ LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
838
+ MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
839
+ SingleLineComment = /\/\/.*/y;
840
+ JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
841
+ JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
842
+ JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
843
+ JSXText = /[^<>{}]+/y;
844
+ TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
845
+ TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
846
+ KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
847
+ KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
848
+ Newline = RegExp(LineTerminatorSequence.source);
849
+ jsTokens_1 = function*(input, {jsx = false} = {}) {
850
+ var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
851
+ ({length} = input);
852
+ lastIndex = 0;
853
+ lastSignificantToken = "";
854
+ stack = [
855
+ {tag: "JS"}
856
+ ];
857
+ braces = [];
858
+ parenNesting = 0;
859
+ postfixIncDec = false;
860
+ while (lastIndex < length) {
861
+ mode = stack[stack.length - 1];
862
+ switch (mode.tag) {
863
+ case "JS":
864
+ case "JSNonExpressionParen":
865
+ case "InterpolationInTemplate":
866
+ case "InterpolationInJSX":
867
+ if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
868
+ RegularExpressionLiteral.lastIndex = lastIndex;
869
+ if (match = RegularExpressionLiteral.exec(input)) {
870
+ lastIndex = RegularExpressionLiteral.lastIndex;
871
+ lastSignificantToken = match[0];
872
+ postfixIncDec = true;
873
+ yield ({
874
+ type: "RegularExpressionLiteral",
875
+ value: match[0],
876
+ closed: match[1] !== void 0 && match[1] !== "\\"
877
+ });
878
+ continue;
879
+ }
880
+ }
881
+ Punctuator.lastIndex = lastIndex;
882
+ if (match = Punctuator.exec(input)) {
883
+ punctuator = match[0];
884
+ nextLastIndex = Punctuator.lastIndex;
885
+ nextLastSignificantToken = punctuator;
886
+ switch (punctuator) {
887
+ case "(":
888
+ if (lastSignificantToken === "?NonExpressionParenKeyword") {
889
+ stack.push({
890
+ tag: "JSNonExpressionParen",
891
+ nesting: parenNesting
892
+ });
893
+ }
894
+ parenNesting++;
895
+ postfixIncDec = false;
896
+ break;
897
+ case ")":
898
+ parenNesting--;
899
+ postfixIncDec = true;
900
+ if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
901
+ stack.pop();
902
+ nextLastSignificantToken = "?NonExpressionParenEnd";
903
+ postfixIncDec = false;
904
+ }
905
+ break;
906
+ case "{":
907
+ Punctuator.lastIndex = 0;
908
+ isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
909
+ braces.push(isExpression);
910
+ postfixIncDec = false;
911
+ break;
912
+ case "}":
913
+ switch (mode.tag) {
914
+ case "InterpolationInTemplate":
915
+ if (braces.length === mode.nesting) {
916
+ Template.lastIndex = lastIndex;
917
+ match = Template.exec(input);
918
+ lastIndex = Template.lastIndex;
919
+ lastSignificantToken = match[0];
920
+ if (match[1] === "${") {
921
+ lastSignificantToken = "?InterpolationInTemplate";
922
+ postfixIncDec = false;
923
+ yield ({
924
+ type: "TemplateMiddle",
925
+ value: match[0]
926
+ });
927
+ } else {
928
+ stack.pop();
929
+ postfixIncDec = true;
930
+ yield ({
931
+ type: "TemplateTail",
932
+ value: match[0],
933
+ closed: match[1] === "`"
934
+ });
935
+ }
936
+ continue;
937
+ }
938
+ break;
939
+ case "InterpolationInJSX":
940
+ if (braces.length === mode.nesting) {
941
+ stack.pop();
942
+ lastIndex += 1;
943
+ lastSignificantToken = "}";
944
+ yield ({
945
+ type: "JSXPunctuator",
946
+ value: "}"
947
+ });
948
+ continue;
949
+ }
950
+ }
951
+ postfixIncDec = braces.pop();
952
+ nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
953
+ break;
954
+ case "]":
955
+ postfixIncDec = true;
956
+ break;
957
+ case "++":
958
+ case "--":
959
+ nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
960
+ break;
961
+ case "<":
962
+ if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
963
+ stack.push({tag: "JSXTag"});
964
+ lastIndex += 1;
965
+ lastSignificantToken = "<";
966
+ yield ({
967
+ type: "JSXPunctuator",
968
+ value: punctuator
969
+ });
970
+ continue;
971
+ }
972
+ postfixIncDec = false;
973
+ break;
974
+ default:
975
+ postfixIncDec = false;
976
+ }
977
+ lastIndex = nextLastIndex;
978
+ lastSignificantToken = nextLastSignificantToken;
979
+ yield ({
980
+ type: "Punctuator",
981
+ value: punctuator
982
+ });
983
+ continue;
984
+ }
985
+ Identifier.lastIndex = lastIndex;
986
+ if (match = Identifier.exec(input)) {
987
+ lastIndex = Identifier.lastIndex;
988
+ nextLastSignificantToken = match[0];
989
+ switch (match[0]) {
990
+ case "for":
991
+ case "if":
992
+ case "while":
993
+ case "with":
994
+ if (lastSignificantToken !== "." && lastSignificantToken !== "?.") {
995
+ nextLastSignificantToken = "?NonExpressionParenKeyword";
996
+ }
997
+ }
998
+ lastSignificantToken = nextLastSignificantToken;
999
+ postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
1000
+ yield ({
1001
+ type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
1002
+ value: match[0]
1003
+ });
1004
+ continue;
1005
+ }
1006
+ StringLiteral.lastIndex = lastIndex;
1007
+ if (match = StringLiteral.exec(input)) {
1008
+ lastIndex = StringLiteral.lastIndex;
1009
+ lastSignificantToken = match[0];
1010
+ postfixIncDec = true;
1011
+ yield ({
1012
+ type: "StringLiteral",
1013
+ value: match[0],
1014
+ closed: match[2] !== void 0
1015
+ });
1016
+ continue;
1017
+ }
1018
+ NumericLiteral.lastIndex = lastIndex;
1019
+ if (match = NumericLiteral.exec(input)) {
1020
+ lastIndex = NumericLiteral.lastIndex;
1021
+ lastSignificantToken = match[0];
1022
+ postfixIncDec = true;
1023
+ yield ({
1024
+ type: "NumericLiteral",
1025
+ value: match[0]
1026
+ });
1027
+ continue;
1028
+ }
1029
+ Template.lastIndex = lastIndex;
1030
+ if (match = Template.exec(input)) {
1031
+ lastIndex = Template.lastIndex;
1032
+ lastSignificantToken = match[0];
1033
+ if (match[1] === "${") {
1034
+ lastSignificantToken = "?InterpolationInTemplate";
1035
+ stack.push({
1036
+ tag: "InterpolationInTemplate",
1037
+ nesting: braces.length
1038
+ });
1039
+ postfixIncDec = false;
1040
+ yield ({
1041
+ type: "TemplateHead",
1042
+ value: match[0]
1043
+ });
1044
+ } else {
1045
+ postfixIncDec = true;
1046
+ yield ({
1047
+ type: "NoSubstitutionTemplate",
1048
+ value: match[0],
1049
+ closed: match[1] === "`"
1050
+ });
1051
+ }
1052
+ continue;
1053
+ }
1054
+ break;
1055
+ case "JSXTag":
1056
+ case "JSXTagEnd":
1057
+ JSXPunctuator.lastIndex = lastIndex;
1058
+ if (match = JSXPunctuator.exec(input)) {
1059
+ lastIndex = JSXPunctuator.lastIndex;
1060
+ nextLastSignificantToken = match[0];
1061
+ switch (match[0]) {
1062
+ case "<":
1063
+ stack.push({tag: "JSXTag"});
1064
+ break;
1065
+ case ">":
1066
+ stack.pop();
1067
+ if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
1068
+ nextLastSignificantToken = "?JSX";
1069
+ postfixIncDec = true;
1070
+ } else {
1071
+ stack.push({tag: "JSXChildren"});
1072
+ }
1073
+ break;
1074
+ case "{":
1075
+ stack.push({
1076
+ tag: "InterpolationInJSX",
1077
+ nesting: braces.length
1078
+ });
1079
+ nextLastSignificantToken = "?InterpolationInJSX";
1080
+ postfixIncDec = false;
1081
+ break;
1082
+ case "/":
1083
+ if (lastSignificantToken === "<") {
1084
+ stack.pop();
1085
+ if (stack[stack.length - 1].tag === "JSXChildren") {
1086
+ stack.pop();
1087
+ }
1088
+ stack.push({tag: "JSXTagEnd"});
1089
+ }
1090
+ }
1091
+ lastSignificantToken = nextLastSignificantToken;
1092
+ yield ({
1093
+ type: "JSXPunctuator",
1094
+ value: match[0]
1095
+ });
1096
+ continue;
1097
+ }
1098
+ JSXIdentifier.lastIndex = lastIndex;
1099
+ if (match = JSXIdentifier.exec(input)) {
1100
+ lastIndex = JSXIdentifier.lastIndex;
1101
+ lastSignificantToken = match[0];
1102
+ yield ({
1103
+ type: "JSXIdentifier",
1104
+ value: match[0]
1105
+ });
1106
+ continue;
1107
+ }
1108
+ JSXString.lastIndex = lastIndex;
1109
+ if (match = JSXString.exec(input)) {
1110
+ lastIndex = JSXString.lastIndex;
1111
+ lastSignificantToken = match[0];
1112
+ yield ({
1113
+ type: "JSXString",
1114
+ value: match[0],
1115
+ closed: match[2] !== void 0
1116
+ });
1117
+ continue;
1118
+ }
1119
+ break;
1120
+ case "JSXChildren":
1121
+ JSXText.lastIndex = lastIndex;
1122
+ if (match = JSXText.exec(input)) {
1123
+ lastIndex = JSXText.lastIndex;
1124
+ lastSignificantToken = match[0];
1125
+ yield ({
1126
+ type: "JSXText",
1127
+ value: match[0]
1128
+ });
1129
+ continue;
1130
+ }
1131
+ switch (input[lastIndex]) {
1132
+ case "<":
1133
+ stack.push({tag: "JSXTag"});
1134
+ lastIndex++;
1135
+ lastSignificantToken = "<";
1136
+ yield ({
1137
+ type: "JSXPunctuator",
1138
+ value: "<"
1139
+ });
1140
+ continue;
1141
+ case "{":
1142
+ stack.push({
1143
+ tag: "InterpolationInJSX",
1144
+ nesting: braces.length
1145
+ });
1146
+ lastIndex++;
1147
+ lastSignificantToken = "?InterpolationInJSX";
1148
+ postfixIncDec = false;
1149
+ yield ({
1150
+ type: "JSXPunctuator",
1151
+ value: "{"
1152
+ });
1153
+ continue;
1154
+ }
1155
+ }
1156
+ WhiteSpace.lastIndex = lastIndex;
1157
+ if (match = WhiteSpace.exec(input)) {
1158
+ lastIndex = WhiteSpace.lastIndex;
1159
+ yield ({
1160
+ type: "WhiteSpace",
1161
+ value: match[0]
1162
+ });
1163
+ continue;
1164
+ }
1165
+ LineTerminatorSequence.lastIndex = lastIndex;
1166
+ if (match = LineTerminatorSequence.exec(input)) {
1167
+ lastIndex = LineTerminatorSequence.lastIndex;
1168
+ postfixIncDec = false;
1169
+ if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
1170
+ lastSignificantToken = "?NoLineTerminatorHere";
1171
+ }
1172
+ yield ({
1173
+ type: "LineTerminatorSequence",
1174
+ value: match[0]
1175
+ });
1176
+ continue;
1177
+ }
1178
+ MultiLineComment.lastIndex = lastIndex;
1179
+ if (match = MultiLineComment.exec(input)) {
1180
+ lastIndex = MultiLineComment.lastIndex;
1181
+ if (Newline.test(match[0])) {
1182
+ postfixIncDec = false;
1183
+ if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
1184
+ lastSignificantToken = "?NoLineTerminatorHere";
1185
+ }
1186
+ }
1187
+ yield ({
1188
+ type: "MultiLineComment",
1189
+ value: match[0],
1190
+ closed: match[1] !== void 0
1191
+ });
1192
+ continue;
1193
+ }
1194
+ SingleLineComment.lastIndex = lastIndex;
1195
+ if (match = SingleLineComment.exec(input)) {
1196
+ lastIndex = SingleLineComment.lastIndex;
1197
+ postfixIncDec = false;
1198
+ yield ({
1199
+ type: "SingleLineComment",
1200
+ value: match[0]
1201
+ });
1202
+ continue;
1203
+ }
1204
+ firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
1205
+ lastIndex += firstCodePoint.length;
1206
+ lastSignificantToken = firstCodePoint;
1207
+ postfixIncDec = false;
1208
+ yield ({
1209
+ type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
1210
+ value: firstCodePoint
1211
+ });
1212
+ }
1213
+ return void 0;
1214
+ };
1215
+ return jsTokens_1;
1254
1216
  }
1255
1217
 
1256
- const COLUMN = 0;
1257
- const SOURCES_INDEX = 1;
1258
- const SOURCE_LINE = 2;
1259
- const SOURCE_COLUMN = 3;
1260
- const NAMES_INDEX = 4;
1261
-
1262
- function maybeSort(mappings, owned) {
1263
- const unsortedIndex = nextUnsortedSegmentLine(mappings, 0);
1264
- if (unsortedIndex === mappings.length)
1265
- return mappings;
1266
- // If we own the array (meaning we parsed it from JSON), then we're free to directly mutate it. If
1267
- // not, we do not want to modify the consumer's input array.
1268
- if (!owned)
1269
- mappings = mappings.slice();
1270
- for (let i = unsortedIndex; i < mappings.length; i = nextUnsortedSegmentLine(mappings, i + 1)) {
1271
- mappings[i] = sortSegments(mappings[i], owned);
1272
- }
1273
- return mappings;
1274
- }
1275
- function nextUnsortedSegmentLine(mappings, start) {
1276
- for (let i = start; i < mappings.length; i++) {
1277
- if (!isSorted(mappings[i]))
1278
- return i;
1279
- }
1280
- return mappings.length;
1281
- }
1282
- function isSorted(line) {
1283
- for (let j = 1; j < line.length; j++) {
1284
- if (line[j][COLUMN] < line[j - 1][COLUMN]) {
1285
- return false;
1286
- }
1287
- }
1288
- return true;
1289
- }
1290
- function sortSegments(line, owned) {
1291
- if (!owned)
1292
- line = line.slice();
1293
- return line.sort(sortComparator);
1294
- }
1295
- function sortComparator(a, b) {
1296
- return a[COLUMN] - b[COLUMN];
1297
- }
1218
+ requireJsTokens();
1298
1219
 
1299
- let found = false;
1300
- /**
1301
- * A binary search implementation that returns the index if a match is found.
1302
- * If no match is found, then the left-index (the index associated with the item that comes just
1303
- * before the desired index) is returned. To maintain proper sort order, a splice would happen at
1304
- * the next index:
1305
- *
1306
- * ```js
1307
- * const array = [1, 3];
1308
- * const needle = 2;
1309
- * const index = binarySearch(array, needle, (item, needle) => item - needle);
1310
- *
1311
- * assert.equal(index, 0);
1312
- * array.splice(index + 1, 0, needle);
1313
- * assert.deepEqual(array, [1, 2, 3]);
1314
- * ```
1315
- */
1316
- function binarySearch(haystack, needle, low, high) {
1317
- while (low <= high) {
1318
- const mid = low + ((high - low) >> 1);
1319
- const cmp = haystack[mid][COLUMN] - needle;
1320
- if (cmp === 0) {
1321
- found = true;
1322
- return mid;
1323
- }
1324
- if (cmp < 0) {
1325
- low = mid + 1;
1326
- }
1327
- else {
1328
- high = mid - 1;
1329
- }
1330
- }
1331
- found = false;
1332
- return low - 1;
1333
- }
1334
- function upperBound(haystack, needle, index) {
1335
- for (let i = index + 1; i < haystack.length; index = i++) {
1336
- if (haystack[i][COLUMN] !== needle)
1337
- break;
1338
- }
1339
- return index;
1340
- }
1341
- function lowerBound(haystack, needle, index) {
1342
- for (let i = index - 1; i >= 0; index = i--) {
1343
- if (haystack[i][COLUMN] !== needle)
1344
- break;
1345
- }
1346
- return index;
1347
- }
1348
- function memoizedState() {
1349
- return {
1350
- lastKey: -1,
1351
- lastNeedle: -1,
1352
- lastIndex: -1,
1353
- };
1354
- }
1355
- /**
1356
- * This overly complicated beast is just to record the last tested line/column and the resulting
1357
- * index, allowing us to skip a few tests if mappings are monotonically increasing.
1358
- */
1359
- function memoizedBinarySearch(haystack, needle, state, key) {
1360
- const { lastKey, lastNeedle, lastIndex } = state;
1361
- let low = 0;
1362
- let high = haystack.length - 1;
1363
- if (key === lastKey) {
1364
- if (needle === lastNeedle) {
1365
- found = lastIndex !== -1 && haystack[lastIndex][COLUMN] === needle;
1366
- return lastIndex;
1367
- }
1368
- if (needle >= lastNeedle) {
1369
- // lastIndex may be -1 if the previous needle was not found.
1370
- low = lastIndex === -1 ? 0 : lastIndex;
1371
- }
1372
- else {
1373
- high = lastIndex;
1374
- }
1375
- }
1376
- state.lastKey = key;
1377
- state.lastNeedle = needle;
1378
- return (state.lastIndex = binarySearch(haystack, needle, low, high));
1379
- }
1220
+ // src/index.ts
1221
+ var reservedWords = {
1222
+ keyword: [
1223
+ "break",
1224
+ "case",
1225
+ "catch",
1226
+ "continue",
1227
+ "debugger",
1228
+ "default",
1229
+ "do",
1230
+ "else",
1231
+ "finally",
1232
+ "for",
1233
+ "function",
1234
+ "if",
1235
+ "return",
1236
+ "switch",
1237
+ "throw",
1238
+ "try",
1239
+ "var",
1240
+ "const",
1241
+ "while",
1242
+ "with",
1243
+ "new",
1244
+ "this",
1245
+ "super",
1246
+ "class",
1247
+ "extends",
1248
+ "export",
1249
+ "import",
1250
+ "null",
1251
+ "true",
1252
+ "false",
1253
+ "in",
1254
+ "instanceof",
1255
+ "typeof",
1256
+ "void",
1257
+ "delete"
1258
+ ],
1259
+ strict: [
1260
+ "implements",
1261
+ "interface",
1262
+ "let",
1263
+ "package",
1264
+ "private",
1265
+ "protected",
1266
+ "public",
1267
+ "static",
1268
+ "yield"
1269
+ ]
1270
+ }; new Set(reservedWords.keyword); new Set(reservedWords.strict);
1380
1271
 
1381
- const LINE_GTR_ZERO = '`line` must be greater than 0 (lines start at line 1)';
1382
- const COL_GTR_EQ_ZERO = '`column` must be greater than or equal to 0 (columns start at column 0)';
1383
- const LEAST_UPPER_BOUND = -1;
1384
- const GREATEST_LOWER_BOUND = 1;
1385
- class TraceMap {
1386
- constructor(map, mapUrl) {
1387
- const isString = typeof map === 'string';
1388
- if (!isString && map._decodedMemo)
1389
- return map;
1390
- const parsed = (isString ? JSON.parse(map) : map);
1391
- const { version, file, names, sourceRoot, sources, sourcesContent } = parsed;
1392
- this.version = version;
1393
- this.file = file;
1394
- this.names = names || [];
1395
- this.sourceRoot = sourceRoot;
1396
- this.sources = sources;
1397
- this.sourcesContent = sourcesContent;
1398
- this.ignoreList = parsed.ignoreList || parsed.x_google_ignoreList || undefined;
1399
- const from = resolve(sourceRoot || '', stripFilename(mapUrl));
1400
- this.resolvedSources = sources.map((s) => resolve(s || '', from));
1401
- const { mappings } = parsed;
1402
- if (typeof mappings === 'string') {
1403
- this._encoded = mappings;
1404
- this._decoded = undefined;
1405
- }
1406
- else {
1407
- this._encoded = undefined;
1408
- this._decoded = maybeSort(mappings, isString);
1409
- }
1410
- this._decodedMemo = memoizedState();
1411
- this._bySources = undefined;
1412
- this._bySourceMemos = undefined;
1413
- }
1414
- }
1415
- /**
1416
- * Typescript doesn't allow friend access to private fields, so this just casts the map into a type
1417
- * with public access modifiers.
1418
- */
1419
- function cast(map) {
1420
- return map;
1421
- }
1422
- /**
1423
- * Returns the decoded (array of lines of segments) form of the SourceMap's mappings field.
1424
- */
1425
- function decodedMappings(map) {
1426
- var _a;
1427
- return ((_a = cast(map))._decoded || (_a._decoded = decode(cast(map)._encoded)));
1428
- }
1429
- /**
1430
- * A higher-level API to find the source/line/column associated with a generated line/column
1431
- * (think, from a stack trace). Line is 1-based, but column is 0-based, due to legacy behavior in
1432
- * `source-map` library.
1433
- */
1434
- function originalPositionFor(map, needle) {
1435
- let { line, column, bias } = needle;
1436
- line--;
1437
- if (line < 0)
1438
- throw new Error(LINE_GTR_ZERO);
1439
- if (column < 0)
1440
- throw new Error(COL_GTR_EQ_ZERO);
1441
- const decoded = decodedMappings(map);
1442
- // It's common for parent source maps to have pointers to lines that have no
1443
- // mapping (like a "//# sourceMappingURL=") at the end of the child file.
1444
- if (line >= decoded.length)
1445
- return OMapping(null, null, null, null);
1446
- const segments = decoded[line];
1447
- const index = traceSegmentInternal(segments, cast(map)._decodedMemo, line, column, bias || GREATEST_LOWER_BOUND);
1448
- if (index === -1)
1449
- return OMapping(null, null, null, null);
1450
- const segment = segments[index];
1451
- if (segment.length === 1)
1452
- return OMapping(null, null, null, null);
1453
- const { names, resolvedSources } = map;
1454
- return OMapping(resolvedSources[segment[SOURCES_INDEX]], segment[SOURCE_LINE] + 1, segment[SOURCE_COLUMN], segment.length === 5 ? names[segment[NAMES_INDEX]] : null);
1272
+ // src/index.ts
1273
+ var f = {
1274
+ reset: [0, 0],
1275
+ bold: [1, 22, "\x1B[22m\x1B[1m"],
1276
+ dim: [2, 22, "\x1B[22m\x1B[2m"],
1277
+ italic: [3, 23],
1278
+ underline: [4, 24],
1279
+ inverse: [7, 27],
1280
+ hidden: [8, 28],
1281
+ strikethrough: [9, 29],
1282
+ black: [30, 39],
1283
+ red: [31, 39],
1284
+ green: [32, 39],
1285
+ yellow: [33, 39],
1286
+ blue: [34, 39],
1287
+ magenta: [35, 39],
1288
+ cyan: [36, 39],
1289
+ white: [37, 39],
1290
+ gray: [90, 39],
1291
+ bgBlack: [40, 49],
1292
+ bgRed: [41, 49],
1293
+ bgGreen: [42, 49],
1294
+ bgYellow: [43, 49],
1295
+ bgBlue: [44, 49],
1296
+ bgMagenta: [45, 49],
1297
+ bgCyan: [46, 49],
1298
+ bgWhite: [47, 49],
1299
+ blackBright: [90, 39],
1300
+ redBright: [91, 39],
1301
+ greenBright: [92, 39],
1302
+ yellowBright: [93, 39],
1303
+ blueBright: [94, 39],
1304
+ magentaBright: [95, 39],
1305
+ cyanBright: [96, 39],
1306
+ whiteBright: [97, 39],
1307
+ bgBlackBright: [100, 49],
1308
+ bgRedBright: [101, 49],
1309
+ bgGreenBright: [102, 49],
1310
+ bgYellowBright: [103, 49],
1311
+ bgBlueBright: [104, 49],
1312
+ bgMagentaBright: [105, 49],
1313
+ bgCyanBright: [106, 49],
1314
+ bgWhiteBright: [107, 49]
1315
+ }, h = Object.entries(f);
1316
+ function a(n) {
1317
+ return String(n);
1455
1318
  }
1456
- function OMapping(source, line, column, name) {
1457
- return { source, line, column, name };
1319
+ a.open = "";
1320
+ a.close = "";
1321
+ function C(n = !1) {
1322
+ let e = typeof process != "undefined" ? process : void 0, i = (e == null ? void 0 : e.env) || {}, g = (e == null ? void 0 : e.argv) || [];
1323
+ return !("NO_COLOR" in i || g.includes("--no-color")) && ("FORCE_COLOR" in i || g.includes("--color") || (e == null ? void 0 : e.platform) === "win32" || n && i.TERM !== "dumb" || "CI" in i) || typeof window != "undefined" && !!window.chrome;
1458
1324
  }
1459
- function traceSegmentInternal(segments, memo, line, column, bias) {
1460
- let index = memoizedBinarySearch(segments, column, memo, line);
1461
- if (found) {
1462
- index = (bias === LEAST_UPPER_BOUND ? upperBound : lowerBound)(segments, column, index);
1463
- }
1464
- else if (bias === LEAST_UPPER_BOUND)
1465
- index++;
1466
- if (index === -1 || index === segments.length)
1467
- return -1;
1468
- return index;
1325
+ function p(n = !1) {
1326
+ let e = C(n), i = (r, t, c, o) => {
1327
+ let l = "", s = 0;
1328
+ do
1329
+ l += r.substring(s, o) + c, s = o + t.length, o = r.indexOf(t, s);
1330
+ while (~o);
1331
+ return l + r.substring(s);
1332
+ }, g = (r, t, c = r) => {
1333
+ let o = (l) => {
1334
+ let s = String(l), b = s.indexOf(t, r.length);
1335
+ return ~b ? r + i(s, t, c, b) + t : r + s + t;
1336
+ };
1337
+ return o.open = r, o.close = t, o;
1338
+ }, u = {
1339
+ isColorSupported: e
1340
+ }, d = (r) => `\x1B[${r}m`;
1341
+ for (let [r, t] of h)
1342
+ u[r] = e ? g(
1343
+ d(t[0]),
1344
+ d(t[1]),
1345
+ t[2]
1346
+ ) : a;
1347
+ return u;
1469
1348
  }
1470
1349
 
1471
- const CHROME_IE_STACK_REGEXP = /^\s*at .*(?:\S:\d+|\(native\))/m;
1472
- const SAFARI_NATIVE_CODE_REGEXP = /^(?:eval@)?(?:\[native code\])?$/;
1473
- const stackIgnorePatterns = [
1474
- "node:internal",
1475
- /\/packages\/\w+\/dist\//,
1476
- /\/@vitest\/\w+\/dist\//,
1477
- "/vitest/dist/",
1478
- "/vitest/src/",
1479
- "/vite-node/dist/",
1480
- "/vite-node/src/",
1481
- "/node_modules/chai/",
1482
- "/node_modules/tinypool/",
1483
- "/node_modules/tinyspy/",
1484
- // browser related deps
1485
- "/deps/chunk-",
1486
- "/deps/@vitest",
1487
- "/deps/loupe",
1488
- "/deps/chai",
1489
- /node:\w+/,
1490
- /__vitest_test__/,
1491
- /__vitest_browser__/,
1492
- /\/deps\/vitest_/
1493
- ];
1494
- function extractLocation(urlLike) {
1495
- if (!urlLike.includes(":")) {
1496
- return [urlLike];
1497
- }
1498
- const regExp = /(.+?)(?::(\d+))?(?::(\d+))?$/;
1499
- const parts = regExp.exec(urlLike.replace(/^\(|\)$/g, ""));
1500
- if (!parts) {
1501
- return [urlLike];
1502
- }
1503
- let url = parts[1];
1504
- if (url.startsWith("async ")) {
1505
- url = url.slice(6);
1506
- }
1507
- if (url.startsWith("http:") || url.startsWith("https:")) {
1508
- const urlObj = new URL(url);
1509
- url = urlObj.pathname;
1510
- }
1511
- if (url.startsWith("/@fs/")) {
1512
- const isWindows = /^\/@fs\/[a-zA-Z]:\//.test(url);
1513
- url = url.slice(isWindows ? 5 : 4);
1514
- }
1515
- return [url, parts[2] || void 0, parts[3] || void 0];
1516
- }
1517
- function parseSingleFFOrSafariStack(raw) {
1518
- let line = raw.trim();
1519
- if (SAFARI_NATIVE_CODE_REGEXP.test(line)) {
1520
- return null;
1521
- }
1522
- if (line.includes(" > eval")) {
1523
- line = line.replace(
1524
- / line (\d+)(?: > eval line \d+)* > eval:\d+:\d+/g,
1525
- ":$1"
1526
- );
1527
- }
1528
- if (!line.includes("@") && !line.includes(":")) {
1529
- return null;
1530
- }
1531
- const functionNameRegex = /((.*".+"[^@]*)?[^@]*)(@)/;
1532
- const matches = line.match(functionNameRegex);
1533
- const functionName = matches && matches[1] ? matches[1] : void 0;
1534
- const [url, lineNumber, columnNumber] = extractLocation(
1535
- line.replace(functionNameRegex, "")
1536
- );
1537
- if (!url || !lineNumber || !columnNumber) {
1538
- return null;
1539
- }
1540
- return {
1541
- file: url,
1542
- method: functionName || "",
1543
- line: Number.parseInt(lineNumber),
1544
- column: Number.parseInt(columnNumber)
1545
- };
1546
- }
1547
- function parseSingleV8Stack(raw) {
1548
- let line = raw.trim();
1549
- if (!CHROME_IE_STACK_REGEXP.test(line)) {
1550
- return null;
1551
- }
1552
- if (line.includes("(eval ")) {
1553
- line = line.replace(/eval code/g, "eval").replace(/(\(eval at [^()]*)|(,.*$)/g, "");
1554
- }
1555
- let sanitizedLine = line.replace(/^\s+/, "").replace(/\(eval code/g, "(").replace(/^.*?\s+/, "");
1556
- const location = sanitizedLine.match(/ (\(.+\)$)/);
1557
- sanitizedLine = location ? sanitizedLine.replace(location[0], "") : sanitizedLine;
1558
- const [url, lineNumber, columnNumber] = extractLocation(
1559
- location ? location[1] : sanitizedLine
1560
- );
1561
- let method = location && sanitizedLine || "";
1562
- let file = url && ["eval", "<anonymous>"].includes(url) ? void 0 : url;
1563
- if (!file || !lineNumber || !columnNumber) {
1564
- return null;
1565
- }
1566
- if (method.startsWith("async ")) {
1567
- method = method.slice(6);
1568
- }
1569
- if (file.startsWith("file://")) {
1570
- file = file.slice(7);
1350
+ // src/browser.ts
1351
+ p(!1);
1352
+
1353
+ const lineSplitRE = /\r?\n/;
1354
+ function positionToOffset(source, lineNumber, columnNumber) {
1355
+ const lines = source.split(lineSplitRE);
1356
+ const nl = /\r\n/.test(source) ? 2 : 1;
1357
+ let start = 0;
1358
+ if (lineNumber > lines.length) {
1359
+ return source.length;
1571
1360
  }
1572
- file = resolve$2(file);
1573
- if (method) {
1574
- method = method.replace(/__vite_ssr_import_\d+__\./g, "");
1361
+ for (let i = 0; i < lineNumber - 1; i++) {
1362
+ start += lines[i].length + nl;
1575
1363
  }
1576
- return {
1577
- method,
1578
- file,
1579
- line: Number.parseInt(lineNumber),
1580
- column: Number.parseInt(columnNumber)
1581
- };
1364
+ return start + columnNumber;
1582
1365
  }
1583
- function parseStacktrace(stack, options = {}) {
1584
- const { ignoreStackEntries = stackIgnorePatterns } = options;
1585
- let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack);
1586
- if (ignoreStackEntries.length) {
1587
- stacks = stacks.filter(
1588
- (stack2) => !ignoreStackEntries.some((p) => stack2.file.match(p))
1366
+ function offsetToLineNumber(source, offset) {
1367
+ if (offset > source.length) {
1368
+ throw new Error(
1369
+ `offset is longer than source length! offset ${offset} > length ${source.length}`
1589
1370
  );
1590
1371
  }
1591
- return stacks.map((stack2) => {
1592
- var _a;
1593
- if (options.getFileName) {
1594
- stack2.file = options.getFileName(stack2.file);
1595
- }
1596
- const map = (_a = options.getSourceMap) == null ? void 0 : _a.call(options, stack2.file);
1597
- if (!map || typeof map !== "object" || !map.version) {
1598
- return stack2;
1599
- }
1600
- const traceMap = new TraceMap(map);
1601
- const { line, column } = originalPositionFor(traceMap, stack2);
1602
- if (line != null && column != null) {
1603
- return { ...stack2, line, column };
1604
- }
1605
- return stack2;
1606
- });
1607
- }
1608
- function parseFFOrSafariStackTrace(stack) {
1609
- return stack.split("\n").map((line) => parseSingleFFOrSafariStack(line)).filter(notNullish);
1610
- }
1611
- function parseV8Stacktrace(stack) {
1612
- return stack.split("\n").map((line) => parseSingleV8Stack(line)).filter(notNullish);
1613
- }
1614
- function parseErrorStacktrace(e, options = {}) {
1615
- if (!e || isPrimitive(e)) {
1616
- return [];
1617
- }
1618
- if (e.stacks) {
1619
- return e.stacks;
1620
- }
1621
- const stackStr = e.stack || e.stackStr || "";
1622
- let stackFrames = parseStacktrace(stackStr, options);
1623
- if (options.frameFilter) {
1624
- stackFrames = stackFrames.filter(
1625
- (f) => options.frameFilter(e, f) !== false
1626
- );
1372
+ const lines = source.split(lineSplitRE);
1373
+ const nl = /\r\n/.test(source) ? 2 : 1;
1374
+ let counted = 0;
1375
+ let line = 0;
1376
+ for (; line < lines.length; line++) {
1377
+ const lineLength = lines[line].length + nl;
1378
+ if (counted + lineLength >= offset) {
1379
+ break;
1380
+ }
1381
+ counted += lineLength;
1627
1382
  }
1628
- e.stacks = stackFrames;
1629
- return stackFrames;
1383
+ return line + 1;
1630
1384
  }
1631
1385
 
1632
1386
  async function saveInlineSnapshots(environment, snapshots) {
@@ -1784,6 +1538,252 @@ async function saveRawSnapshots(environment, snapshots) {
1784
1538
  );
1785
1539
  }
1786
1540
 
1541
+ var naturalCompare$1 = {exports: {}};
1542
+
1543
+ var hasRequiredNaturalCompare;
1544
+
1545
+ function requireNaturalCompare () {
1546
+ if (hasRequiredNaturalCompare) return naturalCompare$1.exports;
1547
+ hasRequiredNaturalCompare = 1;
1548
+ /*
1549
+ * @version 1.4.0
1550
+ * @date 2015-10-26
1551
+ * @stability 3 - Stable
1552
+ * @author Lauri Rooden (https://github.com/litejs/natural-compare-lite)
1553
+ * @license MIT License
1554
+ */
1555
+
1556
+
1557
+ var naturalCompare = function(a, b) {
1558
+ var i, codeA
1559
+ , codeB = 1
1560
+ , posA = 0
1561
+ , posB = 0
1562
+ , alphabet = String.alphabet;
1563
+
1564
+ function getCode(str, pos, code) {
1565
+ if (code) {
1566
+ for (i = pos; code = getCode(str, i), code < 76 && code > 65;) ++i;
1567
+ return +str.slice(pos - 1, i)
1568
+ }
1569
+ code = alphabet && alphabet.indexOf(str.charAt(pos));
1570
+ return code > -1 ? code + 76 : ((code = str.charCodeAt(pos) || 0), code < 45 || code > 127) ? code
1571
+ : code < 46 ? 65 // -
1572
+ : code < 48 ? code - 1
1573
+ : code < 58 ? code + 18 // 0-9
1574
+ : code < 65 ? code - 11
1575
+ : code < 91 ? code + 11 // A-Z
1576
+ : code < 97 ? code - 37
1577
+ : code < 123 ? code + 5 // a-z
1578
+ : code - 63
1579
+ }
1580
+
1581
+
1582
+ if ((a+="") != (b+="")) for (;codeB;) {
1583
+ codeA = getCode(a, posA++);
1584
+ codeB = getCode(b, posB++);
1585
+
1586
+ if (codeA < 76 && codeB < 76 && codeA > 66 && codeB > 66) {
1587
+ codeA = getCode(a, posA, posA);
1588
+ codeB = getCode(b, posB, posA = i);
1589
+ posB = i;
1590
+ }
1591
+
1592
+ if (codeA != codeB) return (codeA < codeB) ? -1 : 1
1593
+ }
1594
+ return 0
1595
+ };
1596
+
1597
+ try {
1598
+ naturalCompare$1.exports = naturalCompare;
1599
+ } catch (e) {
1600
+ String.naturalCompare = naturalCompare;
1601
+ }
1602
+ return naturalCompare$1.exports;
1603
+ }
1604
+
1605
+ var naturalCompareExports = requireNaturalCompare();
1606
+ var naturalCompare = /*@__PURE__*/getDefaultExportFromCjs(naturalCompareExports);
1607
+
1608
+ const serialize$1 = (val, config, indentation, depth, refs, printer) => {
1609
+ const name = val.getMockName();
1610
+ const nameString = name === "vi.fn()" ? "" : ` ${name}`;
1611
+ let callsString = "";
1612
+ if (val.mock.calls.length !== 0) {
1613
+ const indentationNext = indentation + config.indent;
1614
+ callsString = ` {${config.spacingOuter}${indentationNext}"calls": ${printer(
1615
+ val.mock.calls,
1616
+ config,
1617
+ indentationNext,
1618
+ depth,
1619
+ refs
1620
+ )}${config.min ? ", " : ","}${config.spacingOuter}${indentationNext}"results": ${printer(
1621
+ val.mock.results,
1622
+ config,
1623
+ indentationNext,
1624
+ depth,
1625
+ refs
1626
+ )}${config.min ? "" : ","}${config.spacingOuter}${indentation}}`;
1627
+ }
1628
+ return `[MockFunction${nameString}]${callsString}`;
1629
+ };
1630
+ const test = (val) => val && !!val._isMockFunction;
1631
+ const plugin = { serialize: serialize$1, test };
1632
+
1633
+ const {
1634
+ DOMCollection,
1635
+ DOMElement,
1636
+ Immutable,
1637
+ ReactElement,
1638
+ ReactTestComponent,
1639
+ AsymmetricMatcher
1640
+ } = plugins;
1641
+ let PLUGINS = [
1642
+ ReactTestComponent,
1643
+ ReactElement,
1644
+ DOMElement,
1645
+ DOMCollection,
1646
+ Immutable,
1647
+ AsymmetricMatcher,
1648
+ plugin
1649
+ ];
1650
+ function addSerializer(plugin) {
1651
+ PLUGINS = [plugin].concat(PLUGINS);
1652
+ }
1653
+ function getSerializers() {
1654
+ return PLUGINS;
1655
+ }
1656
+
1657
+ function testNameToKey(testName, count) {
1658
+ return `${testName} ${count}`;
1659
+ }
1660
+ function keyToTestName(key) {
1661
+ if (!/ \d+$/.test(key)) {
1662
+ throw new Error("Snapshot keys must end with a number.");
1663
+ }
1664
+ return key.replace(/ \d+$/, "");
1665
+ }
1666
+ function getSnapshotData(content, options) {
1667
+ const update = options.updateSnapshot;
1668
+ const data = /* @__PURE__ */ Object.create(null);
1669
+ let snapshotContents = "";
1670
+ let dirty = false;
1671
+ if (content != null) {
1672
+ try {
1673
+ snapshotContents = content;
1674
+ const populate = new Function("exports", snapshotContents);
1675
+ populate(data);
1676
+ } catch {
1677
+ }
1678
+ }
1679
+ const isInvalid = snapshotContents;
1680
+ if ((update === "all" || update === "new") && isInvalid) {
1681
+ dirty = true;
1682
+ }
1683
+ return { data, dirty };
1684
+ }
1685
+ function addExtraLineBreaks(string) {
1686
+ return string.includes("\n") ? `
1687
+ ${string}
1688
+ ` : string;
1689
+ }
1690
+ function removeExtraLineBreaks(string) {
1691
+ return string.length > 2 && string.startsWith("\n") && string.endsWith("\n") ? string.slice(1, -1) : string;
1692
+ }
1693
+ const escapeRegex = true;
1694
+ const printFunctionName = false;
1695
+ function serialize(val, indent = 2, formatOverrides = {}) {
1696
+ return normalizeNewlines(
1697
+ format(val, {
1698
+ escapeRegex,
1699
+ indent,
1700
+ plugins: getSerializers(),
1701
+ printFunctionName,
1702
+ ...formatOverrides
1703
+ })
1704
+ );
1705
+ }
1706
+ function escapeBacktickString(str) {
1707
+ return str.replace(/`|\\|\$\{/g, "\\$&");
1708
+ }
1709
+ function printBacktickString(str) {
1710
+ return `\`${escapeBacktickString(str)}\``;
1711
+ }
1712
+ function normalizeNewlines(string) {
1713
+ return string.replace(/\r\n|\r/g, "\n");
1714
+ }
1715
+ async function saveSnapshotFile(environment, snapshotData, snapshotPath) {
1716
+ const snapshots = Object.keys(snapshotData).sort(naturalCompare).map(
1717
+ (key) => `exports[${printBacktickString(key)}] = ${printBacktickString(
1718
+ normalizeNewlines(snapshotData[key])
1719
+ )};`
1720
+ );
1721
+ const content = `${environment.getHeader()}
1722
+
1723
+ ${snapshots.join("\n\n")}
1724
+ `;
1725
+ const oldContent = await environment.readSnapshotFile(snapshotPath);
1726
+ const skipWriting = oldContent != null && oldContent === content;
1727
+ if (skipWriting) {
1728
+ return;
1729
+ }
1730
+ await environment.saveSnapshotFile(snapshotPath, content);
1731
+ }
1732
+ function prepareExpected(expected) {
1733
+ function findStartIndent() {
1734
+ var _a, _b;
1735
+ const matchObject = /^( +)\}\s+$/m.exec(expected || "");
1736
+ const objectIndent = (_a = matchObject == null ? void 0 : matchObject[1]) == null ? void 0 : _a.length;
1737
+ if (objectIndent) {
1738
+ return objectIndent;
1739
+ }
1740
+ const matchText = /^\n( +)"/.exec(expected || "");
1741
+ return ((_b = matchText == null ? void 0 : matchText[1]) == null ? void 0 : _b.length) || 0;
1742
+ }
1743
+ const startIndent = findStartIndent();
1744
+ let expectedTrimmed = expected == null ? void 0 : expected.trim();
1745
+ if (startIndent) {
1746
+ expectedTrimmed = expectedTrimmed == null ? void 0 : expectedTrimmed.replace(new RegExp(`^${" ".repeat(startIndent)}`, "gm"), "").replace(/ +\}$/, "}");
1747
+ }
1748
+ return expectedTrimmed;
1749
+ }
1750
+ function deepMergeArray(target = [], source = []) {
1751
+ const mergedOutput = Array.from(target);
1752
+ source.forEach((sourceElement, index) => {
1753
+ const targetElement = mergedOutput[index];
1754
+ if (Array.isArray(target[index])) {
1755
+ mergedOutput[index] = deepMergeArray(target[index], sourceElement);
1756
+ } else if (isObject(targetElement)) {
1757
+ mergedOutput[index] = deepMergeSnapshot(target[index], sourceElement);
1758
+ } else {
1759
+ mergedOutput[index] = sourceElement;
1760
+ }
1761
+ });
1762
+ return mergedOutput;
1763
+ }
1764
+ function deepMergeSnapshot(target, source) {
1765
+ if (isObject(target) && isObject(source)) {
1766
+ const mergedOutput = { ...target };
1767
+ Object.keys(source).forEach((key) => {
1768
+ if (isObject(source[key]) && !source[key].$$typeof) {
1769
+ if (!(key in target)) {
1770
+ Object.assign(mergedOutput, { [key]: source[key] });
1771
+ } else {
1772
+ mergedOutput[key] = deepMergeSnapshot(target[key], source[key]);
1773
+ }
1774
+ } else if (Array.isArray(source[key])) {
1775
+ mergedOutput[key] = deepMergeArray(target[key], source[key]);
1776
+ } else {
1777
+ Object.assign(mergedOutput, { [key]: source[key] });
1778
+ }
1779
+ });
1780
+ return mergedOutput;
1781
+ } else if (Array.isArray(target) && Array.isArray(source)) {
1782
+ return deepMergeArray(target, source);
1783
+ }
1784
+ return target;
1785
+ }
1786
+
1787
1787
  class SnapshotState {
1788
1788
  constructor(testFilePath, snapshotPath, snapshotContent, options) {
1789
1789
  this.testFilePath = testFilePath;