@vitest/utils 1.1.3 → 1.2.1
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/chunk-colors.js +1 -1
- package/dist/chunk-display.js +3 -2
- package/dist/diff.js +1 -1
- package/dist/error.js +1 -1
- package/dist/index.d.ts +20 -12
- package/dist/index.js +532 -3
- package/dist/source-map.d.ts +17 -17
- package/dist/types.d.ts +1 -0
- package/package.json +4 -3
package/dist/chunk-colors.js
CHANGED
@@ -74,4 +74,4 @@ function setupColors(colors) {
|
|
74
74
|
globalThis[SAFE_COLORS_SYMBOL] = colors;
|
75
75
|
}
|
76
76
|
|
77
|
-
export { SAFE_TIMERS_SYMBOL as S, SAFE_COLORS_SYMBOL as a,
|
77
|
+
export { SAFE_TIMERS_SYMBOL as S, SAFE_COLORS_SYMBOL as a, getDefaultColors as b, createColors as c, getColors as g, setupColors as s };
|
package/dist/chunk-display.js
CHANGED
@@ -120,10 +120,11 @@ function inspect(obj, options = {}) {
|
|
120
120
|
return inspect$1(obj, options);
|
121
121
|
}
|
122
122
|
function objDisplay(obj, options = {}) {
|
123
|
-
|
123
|
+
if (typeof options.truncate === "undefined")
|
124
|
+
options.truncate = 40;
|
124
125
|
const str = inspect(obj, options);
|
125
126
|
const type = Object.prototype.toString.call(obj);
|
126
|
-
if (
|
127
|
+
if (options.truncate && str.length >= options.truncate) {
|
127
128
|
if (type === "[object Function]") {
|
128
129
|
const fn = obj;
|
129
130
|
return !fn.name || fn.name === "" ? "[Function]" : `[Function: ${fn.name}]`;
|
package/dist/diff.js
CHANGED
package/dist/error.js
CHANGED
@@ -70,7 +70,7 @@ function serializeError(val, seen = /* @__PURE__ */ new WeakMap()) {
|
|
70
70
|
}
|
71
71
|
}
|
72
72
|
function normalizeErrorMessage(message) {
|
73
|
-
return message.replace(/
|
73
|
+
return message.replace(/__(vite_ssr_import|vi_import)_\d+__\./g, "");
|
74
74
|
}
|
75
75
|
function processError(err, diffOptions) {
|
76
76
|
if (!err || typeof err !== "object")
|
package/dist/index.d.ts
CHANGED
@@ -35,7 +35,7 @@ interface LoupeOptions {
|
|
35
35
|
truncate?: number;
|
36
36
|
}
|
37
37
|
declare function format(...args: unknown[]): string;
|
38
|
-
declare function inspect(obj: unknown, options?: LoupeOptions):
|
38
|
+
declare function inspect(obj: unknown, options?: LoupeOptions): string;
|
39
39
|
declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
|
40
40
|
|
41
41
|
declare const SAFE_TIMERS_SYMBOL: unique symbol;
|
@@ -68,21 +68,22 @@ declare const colorsMap: {
|
|
68
68
|
readonly bgWhite: readonly ["\u001B[47m", "\u001B[49m"];
|
69
69
|
};
|
70
70
|
type ColorName = keyof typeof colorsMap;
|
71
|
+
interface ColorMethod {
|
72
|
+
(input: unknown): string;
|
73
|
+
open: string;
|
74
|
+
close: string;
|
75
|
+
}
|
71
76
|
type ColorsMethods = {
|
72
|
-
[Key in ColorName]:
|
73
|
-
(input: unknown): string;
|
74
|
-
open: string;
|
75
|
-
close: string;
|
76
|
-
};
|
77
|
+
[Key in ColorName]: ColorMethod;
|
77
78
|
};
|
78
|
-
type Colors = ColorsMethods & {
|
79
|
+
type Colors$1 = ColorsMethods & {
|
79
80
|
isColorSupported: boolean;
|
80
81
|
reset: (input: unknown) => string;
|
81
82
|
};
|
82
|
-
declare function getDefaultColors(): Colors;
|
83
|
-
declare function getColors(): Colors;
|
84
|
-
declare function createColors(isTTY?: boolean): Colors;
|
85
|
-
declare function setupColors(colors: Colors): void;
|
83
|
+
declare function getDefaultColors(): Colors$1;
|
84
|
+
declare function getColors(): Colors$1;
|
85
|
+
declare function createColors(isTTY?: boolean): Colors$1;
|
86
|
+
declare function setupColors(colors: Colors$1): void;
|
86
87
|
|
87
88
|
interface ErrorOptions {
|
88
89
|
message?: string;
|
@@ -99,4 +100,11 @@ declare const lineSplitRE: RegExp;
|
|
99
100
|
declare function positionToOffset(source: string, lineNumber: number, columnNumber: number): number;
|
100
101
|
declare function offsetToLineNumber(source: string, offset: number): number;
|
101
102
|
|
102
|
-
|
103
|
+
type Colors = Record<ColorName, (input: string) => string>;
|
104
|
+
interface HighlightOptions {
|
105
|
+
jsx?: boolean;
|
106
|
+
colors?: Colors;
|
107
|
+
}
|
108
|
+
declare function highlight(code: string, options?: HighlightOptions): string;
|
109
|
+
|
110
|
+
export { type ColorMethod, type ColorName, type Colors$1 as Colors, type ColorsMethods, SAFE_COLORS_SYMBOL, SAFE_TIMERS_SYMBOL, createColors, createSimpleStackTrace, format, getColors, getDefaultColors, getSafeTimers, highlight, inspect, lineSplitRE, objDisplay, offsetToLineNumber, positionToOffset, setSafeTimers, setupColors, shuffle, stringify };
|
package/dist/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
export { assertTypes, clone, createDefer, deepClone, getCallLastIndex, getOwnProperties, getType, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
|
2
2
|
export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-display.js';
|
3
|
-
import { S as SAFE_TIMERS_SYMBOL } from './chunk-colors.js';
|
4
|
-
export { a as SAFE_COLORS_SYMBOL, c as createColors, b as
|
3
|
+
import { S as SAFE_TIMERS_SYMBOL, g as getColors } from './chunk-colors.js';
|
4
|
+
export { a as SAFE_COLORS_SYMBOL, c as createColors, b as getDefaultColors, s as setupColors } from './chunk-colors.js';
|
5
5
|
import 'pretty-format';
|
6
6
|
import 'loupe';
|
7
7
|
|
@@ -111,4 +111,533 @@ function offsetToLineNumber(source, offset) {
|
|
111
111
|
return line + 1;
|
112
112
|
}
|
113
113
|
|
114
|
-
|
114
|
+
function getDefaultExportFromCjs (x) {
|
115
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
116
|
+
}
|
117
|
+
|
118
|
+
// Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
|
119
|
+
// License: MIT.
|
120
|
+
var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
|
121
|
+
RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
|
122
|
+
Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
|
123
|
+
Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
|
124
|
+
StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
|
125
|
+
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;
|
126
|
+
Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
|
127
|
+
WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
|
128
|
+
LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
|
129
|
+
MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
|
130
|
+
SingleLineComment = /\/\/.*/y;
|
131
|
+
JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
|
132
|
+
JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
|
133
|
+
JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
|
134
|
+
JSXText = /[^<>{}]+/y;
|
135
|
+
TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
|
136
|
+
TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
|
137
|
+
KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
|
138
|
+
KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
|
139
|
+
Newline = RegExp(LineTerminatorSequence.source);
|
140
|
+
var jsTokens_1 = function*(input, {jsx = false} = {}) {
|
141
|
+
var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
|
142
|
+
({length} = input);
|
143
|
+
lastIndex = 0;
|
144
|
+
lastSignificantToken = "";
|
145
|
+
stack = [
|
146
|
+
{tag: "JS"}
|
147
|
+
];
|
148
|
+
braces = [];
|
149
|
+
parenNesting = 0;
|
150
|
+
postfixIncDec = false;
|
151
|
+
while (lastIndex < length) {
|
152
|
+
mode = stack[stack.length - 1];
|
153
|
+
switch (mode.tag) {
|
154
|
+
case "JS":
|
155
|
+
case "JSNonExpressionParen":
|
156
|
+
case "InterpolationInTemplate":
|
157
|
+
case "InterpolationInJSX":
|
158
|
+
if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
159
|
+
RegularExpressionLiteral.lastIndex = lastIndex;
|
160
|
+
if (match = RegularExpressionLiteral.exec(input)) {
|
161
|
+
lastIndex = RegularExpressionLiteral.lastIndex;
|
162
|
+
lastSignificantToken = match[0];
|
163
|
+
postfixIncDec = true;
|
164
|
+
yield ({
|
165
|
+
type: "RegularExpressionLiteral",
|
166
|
+
value: match[0],
|
167
|
+
closed: match[1] !== void 0 && match[1] !== "\\"
|
168
|
+
});
|
169
|
+
continue;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
Punctuator.lastIndex = lastIndex;
|
173
|
+
if (match = Punctuator.exec(input)) {
|
174
|
+
punctuator = match[0];
|
175
|
+
nextLastIndex = Punctuator.lastIndex;
|
176
|
+
nextLastSignificantToken = punctuator;
|
177
|
+
switch (punctuator) {
|
178
|
+
case "(":
|
179
|
+
if (lastSignificantToken === "?NonExpressionParenKeyword") {
|
180
|
+
stack.push({
|
181
|
+
tag: "JSNonExpressionParen",
|
182
|
+
nesting: parenNesting
|
183
|
+
});
|
184
|
+
}
|
185
|
+
parenNesting++;
|
186
|
+
postfixIncDec = false;
|
187
|
+
break;
|
188
|
+
case ")":
|
189
|
+
parenNesting--;
|
190
|
+
postfixIncDec = true;
|
191
|
+
if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
|
192
|
+
stack.pop();
|
193
|
+
nextLastSignificantToken = "?NonExpressionParenEnd";
|
194
|
+
postfixIncDec = false;
|
195
|
+
}
|
196
|
+
break;
|
197
|
+
case "{":
|
198
|
+
Punctuator.lastIndex = 0;
|
199
|
+
isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
|
200
|
+
braces.push(isExpression);
|
201
|
+
postfixIncDec = false;
|
202
|
+
break;
|
203
|
+
case "}":
|
204
|
+
switch (mode.tag) {
|
205
|
+
case "InterpolationInTemplate":
|
206
|
+
if (braces.length === mode.nesting) {
|
207
|
+
Template.lastIndex = lastIndex;
|
208
|
+
match = Template.exec(input);
|
209
|
+
lastIndex = Template.lastIndex;
|
210
|
+
lastSignificantToken = match[0];
|
211
|
+
if (match[1] === "${") {
|
212
|
+
lastSignificantToken = "?InterpolationInTemplate";
|
213
|
+
postfixIncDec = false;
|
214
|
+
yield ({
|
215
|
+
type: "TemplateMiddle",
|
216
|
+
value: match[0]
|
217
|
+
});
|
218
|
+
} else {
|
219
|
+
stack.pop();
|
220
|
+
postfixIncDec = true;
|
221
|
+
yield ({
|
222
|
+
type: "TemplateTail",
|
223
|
+
value: match[0],
|
224
|
+
closed: match[1] === "`"
|
225
|
+
});
|
226
|
+
}
|
227
|
+
continue;
|
228
|
+
}
|
229
|
+
break;
|
230
|
+
case "InterpolationInJSX":
|
231
|
+
if (braces.length === mode.nesting) {
|
232
|
+
stack.pop();
|
233
|
+
lastIndex += 1;
|
234
|
+
lastSignificantToken = "}";
|
235
|
+
yield ({
|
236
|
+
type: "JSXPunctuator",
|
237
|
+
value: "}"
|
238
|
+
});
|
239
|
+
continue;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
postfixIncDec = braces.pop();
|
243
|
+
nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
|
244
|
+
break;
|
245
|
+
case "]":
|
246
|
+
postfixIncDec = true;
|
247
|
+
break;
|
248
|
+
case "++":
|
249
|
+
case "--":
|
250
|
+
nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
|
251
|
+
break;
|
252
|
+
case "<":
|
253
|
+
if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
254
|
+
stack.push({tag: "JSXTag"});
|
255
|
+
lastIndex += 1;
|
256
|
+
lastSignificantToken = "<";
|
257
|
+
yield ({
|
258
|
+
type: "JSXPunctuator",
|
259
|
+
value: punctuator
|
260
|
+
});
|
261
|
+
continue;
|
262
|
+
}
|
263
|
+
postfixIncDec = false;
|
264
|
+
break;
|
265
|
+
default:
|
266
|
+
postfixIncDec = false;
|
267
|
+
}
|
268
|
+
lastIndex = nextLastIndex;
|
269
|
+
lastSignificantToken = nextLastSignificantToken;
|
270
|
+
yield ({
|
271
|
+
type: "Punctuator",
|
272
|
+
value: punctuator
|
273
|
+
});
|
274
|
+
continue;
|
275
|
+
}
|
276
|
+
Identifier.lastIndex = lastIndex;
|
277
|
+
if (match = Identifier.exec(input)) {
|
278
|
+
lastIndex = Identifier.lastIndex;
|
279
|
+
nextLastSignificantToken = match[0];
|
280
|
+
switch (match[0]) {
|
281
|
+
case "for":
|
282
|
+
case "if":
|
283
|
+
case "while":
|
284
|
+
case "with":
|
285
|
+
if (lastSignificantToken !== "." && lastSignificantToken !== "?.") {
|
286
|
+
nextLastSignificantToken = "?NonExpressionParenKeyword";
|
287
|
+
}
|
288
|
+
}
|
289
|
+
lastSignificantToken = nextLastSignificantToken;
|
290
|
+
postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
|
291
|
+
yield ({
|
292
|
+
type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
|
293
|
+
value: match[0]
|
294
|
+
});
|
295
|
+
continue;
|
296
|
+
}
|
297
|
+
StringLiteral.lastIndex = lastIndex;
|
298
|
+
if (match = StringLiteral.exec(input)) {
|
299
|
+
lastIndex = StringLiteral.lastIndex;
|
300
|
+
lastSignificantToken = match[0];
|
301
|
+
postfixIncDec = true;
|
302
|
+
yield ({
|
303
|
+
type: "StringLiteral",
|
304
|
+
value: match[0],
|
305
|
+
closed: match[2] !== void 0
|
306
|
+
});
|
307
|
+
continue;
|
308
|
+
}
|
309
|
+
NumericLiteral.lastIndex = lastIndex;
|
310
|
+
if (match = NumericLiteral.exec(input)) {
|
311
|
+
lastIndex = NumericLiteral.lastIndex;
|
312
|
+
lastSignificantToken = match[0];
|
313
|
+
postfixIncDec = true;
|
314
|
+
yield ({
|
315
|
+
type: "NumericLiteral",
|
316
|
+
value: match[0]
|
317
|
+
});
|
318
|
+
continue;
|
319
|
+
}
|
320
|
+
Template.lastIndex = lastIndex;
|
321
|
+
if (match = Template.exec(input)) {
|
322
|
+
lastIndex = Template.lastIndex;
|
323
|
+
lastSignificantToken = match[0];
|
324
|
+
if (match[1] === "${") {
|
325
|
+
lastSignificantToken = "?InterpolationInTemplate";
|
326
|
+
stack.push({
|
327
|
+
tag: "InterpolationInTemplate",
|
328
|
+
nesting: braces.length
|
329
|
+
});
|
330
|
+
postfixIncDec = false;
|
331
|
+
yield ({
|
332
|
+
type: "TemplateHead",
|
333
|
+
value: match[0]
|
334
|
+
});
|
335
|
+
} else {
|
336
|
+
postfixIncDec = true;
|
337
|
+
yield ({
|
338
|
+
type: "NoSubstitutionTemplate",
|
339
|
+
value: match[0],
|
340
|
+
closed: match[1] === "`"
|
341
|
+
});
|
342
|
+
}
|
343
|
+
continue;
|
344
|
+
}
|
345
|
+
break;
|
346
|
+
case "JSXTag":
|
347
|
+
case "JSXTagEnd":
|
348
|
+
JSXPunctuator.lastIndex = lastIndex;
|
349
|
+
if (match = JSXPunctuator.exec(input)) {
|
350
|
+
lastIndex = JSXPunctuator.lastIndex;
|
351
|
+
nextLastSignificantToken = match[0];
|
352
|
+
switch (match[0]) {
|
353
|
+
case "<":
|
354
|
+
stack.push({tag: "JSXTag"});
|
355
|
+
break;
|
356
|
+
case ">":
|
357
|
+
stack.pop();
|
358
|
+
if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
|
359
|
+
nextLastSignificantToken = "?JSX";
|
360
|
+
postfixIncDec = true;
|
361
|
+
} else {
|
362
|
+
stack.push({tag: "JSXChildren"});
|
363
|
+
}
|
364
|
+
break;
|
365
|
+
case "{":
|
366
|
+
stack.push({
|
367
|
+
tag: "InterpolationInJSX",
|
368
|
+
nesting: braces.length
|
369
|
+
});
|
370
|
+
nextLastSignificantToken = "?InterpolationInJSX";
|
371
|
+
postfixIncDec = false;
|
372
|
+
break;
|
373
|
+
case "/":
|
374
|
+
if (lastSignificantToken === "<") {
|
375
|
+
stack.pop();
|
376
|
+
if (stack[stack.length - 1].tag === "JSXChildren") {
|
377
|
+
stack.pop();
|
378
|
+
}
|
379
|
+
stack.push({tag: "JSXTagEnd"});
|
380
|
+
}
|
381
|
+
}
|
382
|
+
lastSignificantToken = nextLastSignificantToken;
|
383
|
+
yield ({
|
384
|
+
type: "JSXPunctuator",
|
385
|
+
value: match[0]
|
386
|
+
});
|
387
|
+
continue;
|
388
|
+
}
|
389
|
+
JSXIdentifier.lastIndex = lastIndex;
|
390
|
+
if (match = JSXIdentifier.exec(input)) {
|
391
|
+
lastIndex = JSXIdentifier.lastIndex;
|
392
|
+
lastSignificantToken = match[0];
|
393
|
+
yield ({
|
394
|
+
type: "JSXIdentifier",
|
395
|
+
value: match[0]
|
396
|
+
});
|
397
|
+
continue;
|
398
|
+
}
|
399
|
+
JSXString.lastIndex = lastIndex;
|
400
|
+
if (match = JSXString.exec(input)) {
|
401
|
+
lastIndex = JSXString.lastIndex;
|
402
|
+
lastSignificantToken = match[0];
|
403
|
+
yield ({
|
404
|
+
type: "JSXString",
|
405
|
+
value: match[0],
|
406
|
+
closed: match[2] !== void 0
|
407
|
+
});
|
408
|
+
continue;
|
409
|
+
}
|
410
|
+
break;
|
411
|
+
case "JSXChildren":
|
412
|
+
JSXText.lastIndex = lastIndex;
|
413
|
+
if (match = JSXText.exec(input)) {
|
414
|
+
lastIndex = JSXText.lastIndex;
|
415
|
+
lastSignificantToken = match[0];
|
416
|
+
yield ({
|
417
|
+
type: "JSXText",
|
418
|
+
value: match[0]
|
419
|
+
});
|
420
|
+
continue;
|
421
|
+
}
|
422
|
+
switch (input[lastIndex]) {
|
423
|
+
case "<":
|
424
|
+
stack.push({tag: "JSXTag"});
|
425
|
+
lastIndex++;
|
426
|
+
lastSignificantToken = "<";
|
427
|
+
yield ({
|
428
|
+
type: "JSXPunctuator",
|
429
|
+
value: "<"
|
430
|
+
});
|
431
|
+
continue;
|
432
|
+
case "{":
|
433
|
+
stack.push({
|
434
|
+
tag: "InterpolationInJSX",
|
435
|
+
nesting: braces.length
|
436
|
+
});
|
437
|
+
lastIndex++;
|
438
|
+
lastSignificantToken = "?InterpolationInJSX";
|
439
|
+
postfixIncDec = false;
|
440
|
+
yield ({
|
441
|
+
type: "JSXPunctuator",
|
442
|
+
value: "{"
|
443
|
+
});
|
444
|
+
continue;
|
445
|
+
}
|
446
|
+
}
|
447
|
+
WhiteSpace.lastIndex = lastIndex;
|
448
|
+
if (match = WhiteSpace.exec(input)) {
|
449
|
+
lastIndex = WhiteSpace.lastIndex;
|
450
|
+
yield ({
|
451
|
+
type: "WhiteSpace",
|
452
|
+
value: match[0]
|
453
|
+
});
|
454
|
+
continue;
|
455
|
+
}
|
456
|
+
LineTerminatorSequence.lastIndex = lastIndex;
|
457
|
+
if (match = LineTerminatorSequence.exec(input)) {
|
458
|
+
lastIndex = LineTerminatorSequence.lastIndex;
|
459
|
+
postfixIncDec = false;
|
460
|
+
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
|
461
|
+
lastSignificantToken = "?NoLineTerminatorHere";
|
462
|
+
}
|
463
|
+
yield ({
|
464
|
+
type: "LineTerminatorSequence",
|
465
|
+
value: match[0]
|
466
|
+
});
|
467
|
+
continue;
|
468
|
+
}
|
469
|
+
MultiLineComment.lastIndex = lastIndex;
|
470
|
+
if (match = MultiLineComment.exec(input)) {
|
471
|
+
lastIndex = MultiLineComment.lastIndex;
|
472
|
+
if (Newline.test(match[0])) {
|
473
|
+
postfixIncDec = false;
|
474
|
+
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
|
475
|
+
lastSignificantToken = "?NoLineTerminatorHere";
|
476
|
+
}
|
477
|
+
}
|
478
|
+
yield ({
|
479
|
+
type: "MultiLineComment",
|
480
|
+
value: match[0],
|
481
|
+
closed: match[1] !== void 0
|
482
|
+
});
|
483
|
+
continue;
|
484
|
+
}
|
485
|
+
SingleLineComment.lastIndex = lastIndex;
|
486
|
+
if (match = SingleLineComment.exec(input)) {
|
487
|
+
lastIndex = SingleLineComment.lastIndex;
|
488
|
+
postfixIncDec = false;
|
489
|
+
yield ({
|
490
|
+
type: "SingleLineComment",
|
491
|
+
value: match[0]
|
492
|
+
});
|
493
|
+
continue;
|
494
|
+
}
|
495
|
+
firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
|
496
|
+
lastIndex += firstCodePoint.length;
|
497
|
+
lastSignificantToken = firstCodePoint;
|
498
|
+
postfixIncDec = false;
|
499
|
+
yield ({
|
500
|
+
type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
|
501
|
+
value: firstCodePoint
|
502
|
+
});
|
503
|
+
}
|
504
|
+
return void 0;
|
505
|
+
};
|
506
|
+
|
507
|
+
var jsTokens = /*@__PURE__*/getDefaultExportFromCjs(jsTokens_1);
|
508
|
+
|
509
|
+
// src/index.ts
|
510
|
+
var reservedWords = {
|
511
|
+
keyword: [
|
512
|
+
"break",
|
513
|
+
"case",
|
514
|
+
"catch",
|
515
|
+
"continue",
|
516
|
+
"debugger",
|
517
|
+
"default",
|
518
|
+
"do",
|
519
|
+
"else",
|
520
|
+
"finally",
|
521
|
+
"for",
|
522
|
+
"function",
|
523
|
+
"if",
|
524
|
+
"return",
|
525
|
+
"switch",
|
526
|
+
"throw",
|
527
|
+
"try",
|
528
|
+
"var",
|
529
|
+
"const",
|
530
|
+
"while",
|
531
|
+
"with",
|
532
|
+
"new",
|
533
|
+
"this",
|
534
|
+
"super",
|
535
|
+
"class",
|
536
|
+
"extends",
|
537
|
+
"export",
|
538
|
+
"import",
|
539
|
+
"null",
|
540
|
+
"true",
|
541
|
+
"false",
|
542
|
+
"in",
|
543
|
+
"instanceof",
|
544
|
+
"typeof",
|
545
|
+
"void",
|
546
|
+
"delete"
|
547
|
+
],
|
548
|
+
strict: [
|
549
|
+
"implements",
|
550
|
+
"interface",
|
551
|
+
"let",
|
552
|
+
"package",
|
553
|
+
"private",
|
554
|
+
"protected",
|
555
|
+
"public",
|
556
|
+
"static",
|
557
|
+
"yield"
|
558
|
+
]
|
559
|
+
}, keywords = new Set(reservedWords.keyword), reservedWordsStrictSet = new Set(reservedWords.strict), sometimesKeywords = /* @__PURE__ */ new Set(["as", "async", "from", "get", "of", "set"]);
|
560
|
+
function isReservedWord(word) {
|
561
|
+
return word === "await" || word === "enum";
|
562
|
+
}
|
563
|
+
function isStrictReservedWord(word) {
|
564
|
+
return isReservedWord(word) || reservedWordsStrictSet.has(word);
|
565
|
+
}
|
566
|
+
function isKeyword(word) {
|
567
|
+
return keywords.has(word);
|
568
|
+
}
|
569
|
+
var BRACKET = /^[()[\]{}]$/, getTokenType = function(token) {
|
570
|
+
if (token.type === "IdentifierName") {
|
571
|
+
if (isKeyword(token.value) || isStrictReservedWord(token.value) || sometimesKeywords.has(token.value))
|
572
|
+
return "Keyword";
|
573
|
+
if (token.value[0] && token.value[0] !== token.value[0].toLowerCase())
|
574
|
+
return "IdentifierCapitalized";
|
575
|
+
}
|
576
|
+
return token.type === "Punctuator" && BRACKET.test(token.value) ? "Bracket" : token.type === "Invalid" && (token.value === "@" || token.value === "#") ? "Punctuator" : token.type;
|
577
|
+
};
|
578
|
+
function getCallableType(token) {
|
579
|
+
if (token.type === "IdentifierName")
|
580
|
+
return "IdentifierCallable";
|
581
|
+
if (token.type === "PrivateIdentifier")
|
582
|
+
return "PrivateIdentifierCallable";
|
583
|
+
throw new Error("Not a callable token");
|
584
|
+
}
|
585
|
+
var colorize = (defs, type, value) => {
|
586
|
+
let colorize2 = defs[type];
|
587
|
+
return colorize2 ? colorize2(value) : value;
|
588
|
+
}, highlightTokens = (defs, text, jsx) => {
|
589
|
+
let highlighted = "", lastPotentialCallable = null, stackedHighlight = "";
|
590
|
+
for (let token of jsTokens(text, { jsx })) {
|
591
|
+
let type = getTokenType(token);
|
592
|
+
if (type === "IdentifierName" || type === "PrivateIdentifier") {
|
593
|
+
lastPotentialCallable && (highlighted += colorize(defs, getTokenType(lastPotentialCallable), lastPotentialCallable.value) + stackedHighlight, stackedHighlight = ""), lastPotentialCallable = token;
|
594
|
+
continue;
|
595
|
+
}
|
596
|
+
if (lastPotentialCallable && (token.type === "WhiteSpace" || token.type === "LineTerminatorSequence" || token.type === "Punctuator" && (token.value === "?." || token.value === "!"))) {
|
597
|
+
stackedHighlight += colorize(defs, type, token.value);
|
598
|
+
continue;
|
599
|
+
}
|
600
|
+
if (stackedHighlight && !lastPotentialCallable && (highlighted += stackedHighlight, stackedHighlight = ""), lastPotentialCallable) {
|
601
|
+
let type2 = token.type === "Punctuator" && token.value === "(" ? getCallableType(lastPotentialCallable) : getTokenType(lastPotentialCallable);
|
602
|
+
highlighted += colorize(defs, type2, lastPotentialCallable.value) + stackedHighlight, stackedHighlight = "", lastPotentialCallable = null;
|
603
|
+
}
|
604
|
+
highlighted += colorize(defs, type, token.value);
|
605
|
+
}
|
606
|
+
return highlighted;
|
607
|
+
};
|
608
|
+
function highlight$1(code, options = { jsx: !1, colors: {} }) {
|
609
|
+
return code && highlightTokens(options.colors || {}, code, options.jsx);
|
610
|
+
}
|
611
|
+
|
612
|
+
function getDefs(c) {
|
613
|
+
const Invalid = (text) => c.white(c.bgRed(c.bold(text)));
|
614
|
+
return {
|
615
|
+
Keyword: c.magenta,
|
616
|
+
IdentifierCapitalized: c.yellow,
|
617
|
+
Punctuator: c.yellow,
|
618
|
+
StringLiteral: c.green,
|
619
|
+
NoSubstitutionTemplate: c.green,
|
620
|
+
MultiLineComment: c.gray,
|
621
|
+
SingleLineComment: c.gray,
|
622
|
+
RegularExpressionLiteral: c.cyan,
|
623
|
+
NumericLiteral: c.blue,
|
624
|
+
TemplateHead: (text) => c.green(text.slice(0, text.length - 2)) + c.cyan(text.slice(-2)),
|
625
|
+
TemplateTail: (text) => c.cyan(text.slice(0, 1)) + c.green(text.slice(1)),
|
626
|
+
TemplateMiddle: (text) => c.cyan(text.slice(0, 1)) + c.green(text.slice(1, text.length - 2)) + c.cyan(text.slice(-2)),
|
627
|
+
IdentifierCallable: c.blue,
|
628
|
+
PrivateIdentifierCallable: (text) => `#${c.blue(text.slice(1))}`,
|
629
|
+
Invalid,
|
630
|
+
JSXString: c.green,
|
631
|
+
JSXIdentifier: c.yellow,
|
632
|
+
JSXInvalid: Invalid,
|
633
|
+
JSXPunctuator: c.yellow
|
634
|
+
};
|
635
|
+
}
|
636
|
+
function highlight(code, options = { jsx: false }) {
|
637
|
+
return highlight$1(code, {
|
638
|
+
jsx: options.jsx,
|
639
|
+
colors: getDefs(options.colors || getColors())
|
640
|
+
});
|
641
|
+
}
|
642
|
+
|
643
|
+
export { SAFE_TIMERS_SYMBOL, createSimpleStackTrace, getColors, getSafeTimers, highlight, lineSplitRE, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle };
|
package/dist/source-map.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import { ParsedStack, ErrorWithDiff } from './types.js';
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
type GeneratedColumn = number;
|
4
|
+
type SourcesIndex = number;
|
5
|
+
type SourceLine = number;
|
6
|
+
type SourceColumn = number;
|
7
|
+
type NamesIndex = number;
|
8
|
+
type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
|
9
9
|
|
10
10
|
interface SourceMapV3 {
|
11
11
|
file?: string | null;
|
@@ -21,34 +21,34 @@ interface EncodedSourceMap extends SourceMapV3 {
|
|
21
21
|
interface DecodedSourceMap extends SourceMapV3 {
|
22
22
|
mappings: SourceMapSegment[][];
|
23
23
|
}
|
24
|
-
|
24
|
+
type OriginalMapping = {
|
25
25
|
source: string | null;
|
26
26
|
line: number;
|
27
27
|
column: number;
|
28
28
|
name: string | null;
|
29
29
|
};
|
30
|
-
|
30
|
+
type InvalidOriginalMapping = {
|
31
31
|
source: null;
|
32
32
|
line: null;
|
33
33
|
column: null;
|
34
34
|
name: null;
|
35
35
|
};
|
36
|
-
|
36
|
+
type GeneratedMapping = {
|
37
37
|
line: number;
|
38
38
|
column: number;
|
39
39
|
};
|
40
|
-
|
40
|
+
type InvalidGeneratedMapping = {
|
41
41
|
line: null;
|
42
42
|
column: null;
|
43
43
|
};
|
44
|
-
|
45
|
-
|
46
|
-
|
44
|
+
type Bias = typeof GREATEST_LOWER_BOUND | typeof LEAST_UPPER_BOUND;
|
45
|
+
type SourceMapInput = string | Ro<EncodedSourceMap> | Ro<DecodedSourceMap> | TraceMap;
|
46
|
+
type Needle = {
|
47
47
|
line: number;
|
48
48
|
column: number;
|
49
49
|
bias?: Bias;
|
50
50
|
};
|
51
|
-
|
51
|
+
type SourceNeedle = {
|
52
52
|
source: string;
|
53
53
|
line: number;
|
54
54
|
column: number;
|
@@ -63,9 +63,9 @@ declare abstract class SourceMap {
|
|
63
63
|
sourcesContent: SourceMapV3['sourcesContent'];
|
64
64
|
resolvedSources: SourceMapV3['sources'];
|
65
65
|
}
|
66
|
-
|
67
|
-
|
68
|
-
|
66
|
+
type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
|
67
|
+
type RoArray<T> = Ro<T>[];
|
68
|
+
type RoObject<T> = {
|
69
69
|
[K in keyof T]: T[K] | Ro<T[K]>;
|
70
70
|
};
|
71
71
|
|
package/dist/types.d.ts
CHANGED
@@ -33,6 +33,7 @@ interface ErrorWithDiff extends Error {
|
|
33
33
|
type?: string;
|
34
34
|
frame?: string;
|
35
35
|
diff?: string;
|
36
|
+
codeFrame?: string;
|
36
37
|
}
|
37
38
|
|
38
39
|
export type { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, ErrorWithDiff, MergeInsertions, MutableArray, Nullable, ParsedStack };
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitest/utils",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.1
|
4
|
+
"version": "1.2.1",
|
5
5
|
"description": "Shared Vitest utility functions",
|
6
6
|
"license": "MIT",
|
7
7
|
"funding": "https://opencollective.com/vitest",
|
@@ -63,8 +63,9 @@
|
|
63
63
|
"pretty-format": "^29.7.0"
|
64
64
|
},
|
65
65
|
"devDependencies": {
|
66
|
-
"@jridgewell/trace-mapping": "^0.3.
|
67
|
-
"@types/estree": "^1.0.5"
|
66
|
+
"@jridgewell/trace-mapping": "^0.3.21",
|
67
|
+
"@types/estree": "^1.0.5",
|
68
|
+
"tinyhighlight": "^0.3.2"
|
68
69
|
},
|
69
70
|
"scripts": {
|
70
71
|
"build": "rimraf dist && rollup -c",
|