@vitest/utils 4.0.0-beta.1 → 4.0.0-beta.11
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/LICENSE +1 -1
- package/dist/chunk-_commonjsHelpers.js +1 -154
- package/dist/chunk-pathe.M-eThtNZ.js +156 -0
- package/dist/constants.d.ts +21 -0
- package/dist/constants.js +49 -0
- package/dist/diff.d.ts +2 -13
- package/dist/diff.js +6 -4
- package/dist/display.d.ts +28 -0
- package/dist/display.js +727 -0
- package/dist/error.d.ts +2 -4
- package/dist/error.js +5 -125
- package/dist/helpers.d.ts +22 -5
- package/dist/helpers.js +60 -16
- package/dist/highlight.d.ts +9 -0
- package/dist/highlight.js +538 -0
- package/dist/index.d.ts +4 -61
- package/dist/index.js +0 -632
- package/dist/offset.d.ts +5 -0
- package/dist/offset.js +32 -0
- package/dist/resolver.d.ts +7 -0
- package/dist/resolver.js +71 -0
- package/dist/serialize.d.ts +3 -0
- package/dist/serialize.js +118 -0
- package/dist/source-map.d.ts +33 -117
- package/dist/source-map.js +245 -763
- package/dist/timers.d.ts +18 -0
- package/dist/timers.js +32 -0
- package/dist/types.d.ts +1 -1
- package/package.json +32 -11
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
import { g as getDefaultExportFromCjs } from './chunk-_commonjsHelpers.js';
|
|
2
|
+
import c from 'tinyrainbow';
|
|
3
|
+
|
|
4
|
+
var jsTokens_1;
|
|
5
|
+
var hasRequiredJsTokens;
|
|
6
|
+
|
|
7
|
+
function requireJsTokens () {
|
|
8
|
+
if (hasRequiredJsTokens) return jsTokens_1;
|
|
9
|
+
hasRequiredJsTokens = 1;
|
|
10
|
+
// Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
|
|
11
|
+
// License: MIT.
|
|
12
|
+
var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
|
|
13
|
+
RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
|
|
14
|
+
Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
|
|
15
|
+
Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
|
|
16
|
+
StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
|
|
17
|
+
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;
|
|
18
|
+
Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
|
|
19
|
+
WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
|
|
20
|
+
LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
|
|
21
|
+
MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
|
|
22
|
+
SingleLineComment = /\/\/.*/y;
|
|
23
|
+
JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
|
|
24
|
+
JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
|
|
25
|
+
JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
|
|
26
|
+
JSXText = /[^<>{}]+/y;
|
|
27
|
+
TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
|
|
28
|
+
TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
|
|
29
|
+
KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
|
|
30
|
+
KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
|
|
31
|
+
Newline = RegExp(LineTerminatorSequence.source);
|
|
32
|
+
jsTokens_1 = function*(input, {jsx = false} = {}) {
|
|
33
|
+
var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
|
|
34
|
+
({length} = input);
|
|
35
|
+
lastIndex = 0;
|
|
36
|
+
lastSignificantToken = "";
|
|
37
|
+
stack = [
|
|
38
|
+
{tag: "JS"}
|
|
39
|
+
];
|
|
40
|
+
braces = [];
|
|
41
|
+
parenNesting = 0;
|
|
42
|
+
postfixIncDec = false;
|
|
43
|
+
while (lastIndex < length) {
|
|
44
|
+
mode = stack[stack.length - 1];
|
|
45
|
+
switch (mode.tag) {
|
|
46
|
+
case "JS":
|
|
47
|
+
case "JSNonExpressionParen":
|
|
48
|
+
case "InterpolationInTemplate":
|
|
49
|
+
case "InterpolationInJSX":
|
|
50
|
+
if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
|
51
|
+
RegularExpressionLiteral.lastIndex = lastIndex;
|
|
52
|
+
if (match = RegularExpressionLiteral.exec(input)) {
|
|
53
|
+
lastIndex = RegularExpressionLiteral.lastIndex;
|
|
54
|
+
lastSignificantToken = match[0];
|
|
55
|
+
postfixIncDec = true;
|
|
56
|
+
yield ({
|
|
57
|
+
type: "RegularExpressionLiteral",
|
|
58
|
+
value: match[0],
|
|
59
|
+
closed: match[1] !== void 0 && match[1] !== "\\"
|
|
60
|
+
});
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
Punctuator.lastIndex = lastIndex;
|
|
65
|
+
if (match = Punctuator.exec(input)) {
|
|
66
|
+
punctuator = match[0];
|
|
67
|
+
nextLastIndex = Punctuator.lastIndex;
|
|
68
|
+
nextLastSignificantToken = punctuator;
|
|
69
|
+
switch (punctuator) {
|
|
70
|
+
case "(":
|
|
71
|
+
if (lastSignificantToken === "?NonExpressionParenKeyword") {
|
|
72
|
+
stack.push({
|
|
73
|
+
tag: "JSNonExpressionParen",
|
|
74
|
+
nesting: parenNesting
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
parenNesting++;
|
|
78
|
+
postfixIncDec = false;
|
|
79
|
+
break;
|
|
80
|
+
case ")":
|
|
81
|
+
parenNesting--;
|
|
82
|
+
postfixIncDec = true;
|
|
83
|
+
if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
|
|
84
|
+
stack.pop();
|
|
85
|
+
nextLastSignificantToken = "?NonExpressionParenEnd";
|
|
86
|
+
postfixIncDec = false;
|
|
87
|
+
}
|
|
88
|
+
break;
|
|
89
|
+
case "{":
|
|
90
|
+
Punctuator.lastIndex = 0;
|
|
91
|
+
isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
|
|
92
|
+
braces.push(isExpression);
|
|
93
|
+
postfixIncDec = false;
|
|
94
|
+
break;
|
|
95
|
+
case "}":
|
|
96
|
+
switch (mode.tag) {
|
|
97
|
+
case "InterpolationInTemplate":
|
|
98
|
+
if (braces.length === mode.nesting) {
|
|
99
|
+
Template.lastIndex = lastIndex;
|
|
100
|
+
match = Template.exec(input);
|
|
101
|
+
lastIndex = Template.lastIndex;
|
|
102
|
+
lastSignificantToken = match[0];
|
|
103
|
+
if (match[1] === "${") {
|
|
104
|
+
lastSignificantToken = "?InterpolationInTemplate";
|
|
105
|
+
postfixIncDec = false;
|
|
106
|
+
yield ({
|
|
107
|
+
type: "TemplateMiddle",
|
|
108
|
+
value: match[0]
|
|
109
|
+
});
|
|
110
|
+
} else {
|
|
111
|
+
stack.pop();
|
|
112
|
+
postfixIncDec = true;
|
|
113
|
+
yield ({
|
|
114
|
+
type: "TemplateTail",
|
|
115
|
+
value: match[0],
|
|
116
|
+
closed: match[1] === "`"
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
break;
|
|
122
|
+
case "InterpolationInJSX":
|
|
123
|
+
if (braces.length === mode.nesting) {
|
|
124
|
+
stack.pop();
|
|
125
|
+
lastIndex += 1;
|
|
126
|
+
lastSignificantToken = "}";
|
|
127
|
+
yield ({
|
|
128
|
+
type: "JSXPunctuator",
|
|
129
|
+
value: "}"
|
|
130
|
+
});
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
postfixIncDec = braces.pop();
|
|
135
|
+
nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
|
|
136
|
+
break;
|
|
137
|
+
case "]":
|
|
138
|
+
postfixIncDec = true;
|
|
139
|
+
break;
|
|
140
|
+
case "++":
|
|
141
|
+
case "--":
|
|
142
|
+
nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
|
|
143
|
+
break;
|
|
144
|
+
case "<":
|
|
145
|
+
if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
|
|
146
|
+
stack.push({tag: "JSXTag"});
|
|
147
|
+
lastIndex += 1;
|
|
148
|
+
lastSignificantToken = "<";
|
|
149
|
+
yield ({
|
|
150
|
+
type: "JSXPunctuator",
|
|
151
|
+
value: punctuator
|
|
152
|
+
});
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
postfixIncDec = false;
|
|
156
|
+
break;
|
|
157
|
+
default:
|
|
158
|
+
postfixIncDec = false;
|
|
159
|
+
}
|
|
160
|
+
lastIndex = nextLastIndex;
|
|
161
|
+
lastSignificantToken = nextLastSignificantToken;
|
|
162
|
+
yield ({
|
|
163
|
+
type: "Punctuator",
|
|
164
|
+
value: punctuator
|
|
165
|
+
});
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
Identifier.lastIndex = lastIndex;
|
|
169
|
+
if (match = Identifier.exec(input)) {
|
|
170
|
+
lastIndex = Identifier.lastIndex;
|
|
171
|
+
nextLastSignificantToken = match[0];
|
|
172
|
+
switch (match[0]) {
|
|
173
|
+
case "for":
|
|
174
|
+
case "if":
|
|
175
|
+
case "while":
|
|
176
|
+
case "with":
|
|
177
|
+
if (lastSignificantToken !== "." && lastSignificantToken !== "?.") {
|
|
178
|
+
nextLastSignificantToken = "?NonExpressionParenKeyword";
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
lastSignificantToken = nextLastSignificantToken;
|
|
182
|
+
postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
|
|
183
|
+
yield ({
|
|
184
|
+
type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
|
|
185
|
+
value: match[0]
|
|
186
|
+
});
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
StringLiteral.lastIndex = lastIndex;
|
|
190
|
+
if (match = StringLiteral.exec(input)) {
|
|
191
|
+
lastIndex = StringLiteral.lastIndex;
|
|
192
|
+
lastSignificantToken = match[0];
|
|
193
|
+
postfixIncDec = true;
|
|
194
|
+
yield ({
|
|
195
|
+
type: "StringLiteral",
|
|
196
|
+
value: match[0],
|
|
197
|
+
closed: match[2] !== void 0
|
|
198
|
+
});
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
NumericLiteral.lastIndex = lastIndex;
|
|
202
|
+
if (match = NumericLiteral.exec(input)) {
|
|
203
|
+
lastIndex = NumericLiteral.lastIndex;
|
|
204
|
+
lastSignificantToken = match[0];
|
|
205
|
+
postfixIncDec = true;
|
|
206
|
+
yield ({
|
|
207
|
+
type: "NumericLiteral",
|
|
208
|
+
value: match[0]
|
|
209
|
+
});
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
Template.lastIndex = lastIndex;
|
|
213
|
+
if (match = Template.exec(input)) {
|
|
214
|
+
lastIndex = Template.lastIndex;
|
|
215
|
+
lastSignificantToken = match[0];
|
|
216
|
+
if (match[1] === "${") {
|
|
217
|
+
lastSignificantToken = "?InterpolationInTemplate";
|
|
218
|
+
stack.push({
|
|
219
|
+
tag: "InterpolationInTemplate",
|
|
220
|
+
nesting: braces.length
|
|
221
|
+
});
|
|
222
|
+
postfixIncDec = false;
|
|
223
|
+
yield ({
|
|
224
|
+
type: "TemplateHead",
|
|
225
|
+
value: match[0]
|
|
226
|
+
});
|
|
227
|
+
} else {
|
|
228
|
+
postfixIncDec = true;
|
|
229
|
+
yield ({
|
|
230
|
+
type: "NoSubstitutionTemplate",
|
|
231
|
+
value: match[0],
|
|
232
|
+
closed: match[1] === "`"
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
break;
|
|
238
|
+
case "JSXTag":
|
|
239
|
+
case "JSXTagEnd":
|
|
240
|
+
JSXPunctuator.lastIndex = lastIndex;
|
|
241
|
+
if (match = JSXPunctuator.exec(input)) {
|
|
242
|
+
lastIndex = JSXPunctuator.lastIndex;
|
|
243
|
+
nextLastSignificantToken = match[0];
|
|
244
|
+
switch (match[0]) {
|
|
245
|
+
case "<":
|
|
246
|
+
stack.push({tag: "JSXTag"});
|
|
247
|
+
break;
|
|
248
|
+
case ">":
|
|
249
|
+
stack.pop();
|
|
250
|
+
if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
|
|
251
|
+
nextLastSignificantToken = "?JSX";
|
|
252
|
+
postfixIncDec = true;
|
|
253
|
+
} else {
|
|
254
|
+
stack.push({tag: "JSXChildren"});
|
|
255
|
+
}
|
|
256
|
+
break;
|
|
257
|
+
case "{":
|
|
258
|
+
stack.push({
|
|
259
|
+
tag: "InterpolationInJSX",
|
|
260
|
+
nesting: braces.length
|
|
261
|
+
});
|
|
262
|
+
nextLastSignificantToken = "?InterpolationInJSX";
|
|
263
|
+
postfixIncDec = false;
|
|
264
|
+
break;
|
|
265
|
+
case "/":
|
|
266
|
+
if (lastSignificantToken === "<") {
|
|
267
|
+
stack.pop();
|
|
268
|
+
if (stack[stack.length - 1].tag === "JSXChildren") {
|
|
269
|
+
stack.pop();
|
|
270
|
+
}
|
|
271
|
+
stack.push({tag: "JSXTagEnd"});
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
lastSignificantToken = nextLastSignificantToken;
|
|
275
|
+
yield ({
|
|
276
|
+
type: "JSXPunctuator",
|
|
277
|
+
value: match[0]
|
|
278
|
+
});
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
JSXIdentifier.lastIndex = lastIndex;
|
|
282
|
+
if (match = JSXIdentifier.exec(input)) {
|
|
283
|
+
lastIndex = JSXIdentifier.lastIndex;
|
|
284
|
+
lastSignificantToken = match[0];
|
|
285
|
+
yield ({
|
|
286
|
+
type: "JSXIdentifier",
|
|
287
|
+
value: match[0]
|
|
288
|
+
});
|
|
289
|
+
continue;
|
|
290
|
+
}
|
|
291
|
+
JSXString.lastIndex = lastIndex;
|
|
292
|
+
if (match = JSXString.exec(input)) {
|
|
293
|
+
lastIndex = JSXString.lastIndex;
|
|
294
|
+
lastSignificantToken = match[0];
|
|
295
|
+
yield ({
|
|
296
|
+
type: "JSXString",
|
|
297
|
+
value: match[0],
|
|
298
|
+
closed: match[2] !== void 0
|
|
299
|
+
});
|
|
300
|
+
continue;
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
case "JSXChildren":
|
|
304
|
+
JSXText.lastIndex = lastIndex;
|
|
305
|
+
if (match = JSXText.exec(input)) {
|
|
306
|
+
lastIndex = JSXText.lastIndex;
|
|
307
|
+
lastSignificantToken = match[0];
|
|
308
|
+
yield ({
|
|
309
|
+
type: "JSXText",
|
|
310
|
+
value: match[0]
|
|
311
|
+
});
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
switch (input[lastIndex]) {
|
|
315
|
+
case "<":
|
|
316
|
+
stack.push({tag: "JSXTag"});
|
|
317
|
+
lastIndex++;
|
|
318
|
+
lastSignificantToken = "<";
|
|
319
|
+
yield ({
|
|
320
|
+
type: "JSXPunctuator",
|
|
321
|
+
value: "<"
|
|
322
|
+
});
|
|
323
|
+
continue;
|
|
324
|
+
case "{":
|
|
325
|
+
stack.push({
|
|
326
|
+
tag: "InterpolationInJSX",
|
|
327
|
+
nesting: braces.length
|
|
328
|
+
});
|
|
329
|
+
lastIndex++;
|
|
330
|
+
lastSignificantToken = "?InterpolationInJSX";
|
|
331
|
+
postfixIncDec = false;
|
|
332
|
+
yield ({
|
|
333
|
+
type: "JSXPunctuator",
|
|
334
|
+
value: "{"
|
|
335
|
+
});
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
WhiteSpace.lastIndex = lastIndex;
|
|
340
|
+
if (match = WhiteSpace.exec(input)) {
|
|
341
|
+
lastIndex = WhiteSpace.lastIndex;
|
|
342
|
+
yield ({
|
|
343
|
+
type: "WhiteSpace",
|
|
344
|
+
value: match[0]
|
|
345
|
+
});
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
LineTerminatorSequence.lastIndex = lastIndex;
|
|
349
|
+
if (match = LineTerminatorSequence.exec(input)) {
|
|
350
|
+
lastIndex = LineTerminatorSequence.lastIndex;
|
|
351
|
+
postfixIncDec = false;
|
|
352
|
+
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
|
|
353
|
+
lastSignificantToken = "?NoLineTerminatorHere";
|
|
354
|
+
}
|
|
355
|
+
yield ({
|
|
356
|
+
type: "LineTerminatorSequence",
|
|
357
|
+
value: match[0]
|
|
358
|
+
});
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
MultiLineComment.lastIndex = lastIndex;
|
|
362
|
+
if (match = MultiLineComment.exec(input)) {
|
|
363
|
+
lastIndex = MultiLineComment.lastIndex;
|
|
364
|
+
if (Newline.test(match[0])) {
|
|
365
|
+
postfixIncDec = false;
|
|
366
|
+
if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
|
|
367
|
+
lastSignificantToken = "?NoLineTerminatorHere";
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
yield ({
|
|
371
|
+
type: "MultiLineComment",
|
|
372
|
+
value: match[0],
|
|
373
|
+
closed: match[1] !== void 0
|
|
374
|
+
});
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
SingleLineComment.lastIndex = lastIndex;
|
|
378
|
+
if (match = SingleLineComment.exec(input)) {
|
|
379
|
+
lastIndex = SingleLineComment.lastIndex;
|
|
380
|
+
postfixIncDec = false;
|
|
381
|
+
yield ({
|
|
382
|
+
type: "SingleLineComment",
|
|
383
|
+
value: match[0]
|
|
384
|
+
});
|
|
385
|
+
continue;
|
|
386
|
+
}
|
|
387
|
+
firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
|
|
388
|
+
lastIndex += firstCodePoint.length;
|
|
389
|
+
lastSignificantToken = firstCodePoint;
|
|
390
|
+
postfixIncDec = false;
|
|
391
|
+
yield ({
|
|
392
|
+
type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
|
|
393
|
+
value: firstCodePoint
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
return void 0;
|
|
397
|
+
};
|
|
398
|
+
return jsTokens_1;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
var jsTokensExports = /*@__PURE__*/ requireJsTokens();
|
|
402
|
+
var jsTokens = /*@__PURE__*/getDefaultExportFromCjs(jsTokensExports);
|
|
403
|
+
|
|
404
|
+
// src/index.ts
|
|
405
|
+
var reservedWords = {
|
|
406
|
+
keyword: [
|
|
407
|
+
"break",
|
|
408
|
+
"case",
|
|
409
|
+
"catch",
|
|
410
|
+
"continue",
|
|
411
|
+
"debugger",
|
|
412
|
+
"default",
|
|
413
|
+
"do",
|
|
414
|
+
"else",
|
|
415
|
+
"finally",
|
|
416
|
+
"for",
|
|
417
|
+
"function",
|
|
418
|
+
"if",
|
|
419
|
+
"return",
|
|
420
|
+
"switch",
|
|
421
|
+
"throw",
|
|
422
|
+
"try",
|
|
423
|
+
"var",
|
|
424
|
+
"const",
|
|
425
|
+
"while",
|
|
426
|
+
"with",
|
|
427
|
+
"new",
|
|
428
|
+
"this",
|
|
429
|
+
"super",
|
|
430
|
+
"class",
|
|
431
|
+
"extends",
|
|
432
|
+
"export",
|
|
433
|
+
"import",
|
|
434
|
+
"null",
|
|
435
|
+
"true",
|
|
436
|
+
"false",
|
|
437
|
+
"in",
|
|
438
|
+
"instanceof",
|
|
439
|
+
"typeof",
|
|
440
|
+
"void",
|
|
441
|
+
"delete"
|
|
442
|
+
],
|
|
443
|
+
strict: [
|
|
444
|
+
"implements",
|
|
445
|
+
"interface",
|
|
446
|
+
"let",
|
|
447
|
+
"package",
|
|
448
|
+
"private",
|
|
449
|
+
"protected",
|
|
450
|
+
"public",
|
|
451
|
+
"static",
|
|
452
|
+
"yield"
|
|
453
|
+
]
|
|
454
|
+
}, keywords = new Set(reservedWords.keyword), reservedWordsStrictSet = new Set(reservedWords.strict), sometimesKeywords = /* @__PURE__ */ new Set(["as", "async", "from", "get", "of", "set"]);
|
|
455
|
+
function isReservedWord(word) {
|
|
456
|
+
return word === "await" || word === "enum";
|
|
457
|
+
}
|
|
458
|
+
function isStrictReservedWord(word) {
|
|
459
|
+
return isReservedWord(word) || reservedWordsStrictSet.has(word);
|
|
460
|
+
}
|
|
461
|
+
function isKeyword(word) {
|
|
462
|
+
return keywords.has(word);
|
|
463
|
+
}
|
|
464
|
+
var BRACKET = /^[()[\]{}]$/, getTokenType = function(token) {
|
|
465
|
+
if (token.type === "IdentifierName") {
|
|
466
|
+
if (isKeyword(token.value) || isStrictReservedWord(token.value) || sometimesKeywords.has(token.value))
|
|
467
|
+
return "Keyword";
|
|
468
|
+
if (token.value[0] && token.value[0] !== token.value[0].toLowerCase())
|
|
469
|
+
return "IdentifierCapitalized";
|
|
470
|
+
}
|
|
471
|
+
return token.type === "Punctuator" && BRACKET.test(token.value) ? "Bracket" : token.type === "Invalid" && (token.value === "@" || token.value === "#") ? "Punctuator" : token.type;
|
|
472
|
+
};
|
|
473
|
+
function getCallableType(token) {
|
|
474
|
+
if (token.type === "IdentifierName")
|
|
475
|
+
return "IdentifierCallable";
|
|
476
|
+
if (token.type === "PrivateIdentifier")
|
|
477
|
+
return "PrivateIdentifierCallable";
|
|
478
|
+
throw new Error("Not a callable token");
|
|
479
|
+
}
|
|
480
|
+
var colorize = (defs, type, value) => {
|
|
481
|
+
let colorize2 = defs[type];
|
|
482
|
+
return colorize2 ? colorize2(value) : value;
|
|
483
|
+
}, highlightTokens = (defs, text, jsx) => {
|
|
484
|
+
let highlighted = "", lastPotentialCallable = null, stackedHighlight = "";
|
|
485
|
+
for (let token of jsTokens(text, { jsx })) {
|
|
486
|
+
let type = getTokenType(token);
|
|
487
|
+
if (type === "IdentifierName" || type === "PrivateIdentifier") {
|
|
488
|
+
lastPotentialCallable && (highlighted += colorize(defs, getTokenType(lastPotentialCallable), lastPotentialCallable.value) + stackedHighlight, stackedHighlight = ""), lastPotentialCallable = token;
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
if (lastPotentialCallable && (token.type === "WhiteSpace" || token.type === "LineTerminatorSequence" || token.type === "Punctuator" && (token.value === "?." || token.value === "!"))) {
|
|
492
|
+
stackedHighlight += colorize(defs, type, token.value);
|
|
493
|
+
continue;
|
|
494
|
+
}
|
|
495
|
+
if (stackedHighlight && !lastPotentialCallable && (highlighted += stackedHighlight, stackedHighlight = ""), lastPotentialCallable) {
|
|
496
|
+
let type2 = token.type === "Punctuator" && token.value === "(" ? getCallableType(lastPotentialCallable) : getTokenType(lastPotentialCallable);
|
|
497
|
+
highlighted += colorize(defs, type2, lastPotentialCallable.value) + stackedHighlight, stackedHighlight = "", lastPotentialCallable = null;
|
|
498
|
+
}
|
|
499
|
+
highlighted += colorize(defs, type, token.value);
|
|
500
|
+
}
|
|
501
|
+
return highlighted;
|
|
502
|
+
};
|
|
503
|
+
function highlight$1(code, options = { jsx: false, colors: {} }) {
|
|
504
|
+
return code && highlightTokens(options.colors || {}, code, options.jsx);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function getDefs(c) {
|
|
508
|
+
const Invalid = (text) => c.white(c.bgRed(c.bold(text)));
|
|
509
|
+
return {
|
|
510
|
+
Keyword: c.magenta,
|
|
511
|
+
IdentifierCapitalized: c.yellow,
|
|
512
|
+
Punctuator: c.yellow,
|
|
513
|
+
StringLiteral: c.green,
|
|
514
|
+
NoSubstitutionTemplate: c.green,
|
|
515
|
+
MultiLineComment: c.gray,
|
|
516
|
+
SingleLineComment: c.gray,
|
|
517
|
+
RegularExpressionLiteral: c.cyan,
|
|
518
|
+
NumericLiteral: c.blue,
|
|
519
|
+
TemplateHead: (text) => c.green(text.slice(0, text.length - 2)) + c.cyan(text.slice(-2)),
|
|
520
|
+
TemplateTail: (text) => c.cyan(text.slice(0, 1)) + c.green(text.slice(1)),
|
|
521
|
+
TemplateMiddle: (text) => c.cyan(text.slice(0, 1)) + c.green(text.slice(1, text.length - 2)) + c.cyan(text.slice(-2)),
|
|
522
|
+
IdentifierCallable: c.blue,
|
|
523
|
+
PrivateIdentifierCallable: (text) => `#${c.blue(text.slice(1))}`,
|
|
524
|
+
Invalid,
|
|
525
|
+
JSXString: c.green,
|
|
526
|
+
JSXIdentifier: c.yellow,
|
|
527
|
+
JSXInvalid: Invalid,
|
|
528
|
+
JSXPunctuator: c.yellow
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
function highlight(code, options = { jsx: false }) {
|
|
532
|
+
return highlight$1(code, {
|
|
533
|
+
jsx: options.jsx,
|
|
534
|
+
colors: getDefs(options.colors || c)
|
|
535
|
+
});
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
export { highlight };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,62 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
export { DeferPromise
|
|
3
|
-
|
|
1
|
+
export { LoupeOptions, StringifyOptions } from './display.js';
|
|
2
|
+
export { DeferPromise } from './helpers.js';
|
|
3
|
+
export { SafeTimers } from './timers.js';
|
|
4
4
|
export { ArgumentsType, Arrayable, Awaitable, Constructable, DeepMerge, MergeInsertions, Nullable, ParsedStack, SerializedError, TestError } from './types.js';
|
|
5
|
-
|
|
6
|
-
type Inspect = (value: unknown, options: Options) => string;
|
|
7
|
-
interface Options {
|
|
8
|
-
showHidden: boolean;
|
|
9
|
-
depth: number;
|
|
10
|
-
colors: boolean;
|
|
11
|
-
customInspect: boolean;
|
|
12
|
-
showProxy: boolean;
|
|
13
|
-
maxArrayLength: number;
|
|
14
|
-
breakLength: number;
|
|
15
|
-
truncate: number;
|
|
16
|
-
seen: unknown[];
|
|
17
|
-
inspect: Inspect;
|
|
18
|
-
stylize: (value: string, styleType: string) => string;
|
|
19
|
-
}
|
|
20
|
-
type LoupeOptions = Partial<Options>;
|
|
21
|
-
interface StringifyOptions extends PrettyFormatOptions {
|
|
22
|
-
maxLength?: number;
|
|
23
|
-
}
|
|
24
|
-
declare function stringify(object: unknown, maxDepth?: number, { maxLength,...options }?: StringifyOptions): string;
|
|
25
|
-
declare function format(...args: unknown[]): string;
|
|
26
|
-
declare function inspect(obj: unknown, options?: LoupeOptions): string;
|
|
27
|
-
declare function objDisplay(obj: unknown, options?: LoupeOptions): string;
|
|
28
|
-
|
|
29
|
-
interface HighlightOptions {
|
|
30
|
-
jsx?: boolean;
|
|
31
|
-
colors?: Colors;
|
|
32
|
-
}
|
|
33
|
-
declare function highlight(code: string, options?: HighlightOptions): string;
|
|
34
|
-
|
|
35
|
-
declare function nanoid(size?: number): string;
|
|
36
|
-
|
|
37
|
-
declare const lineSplitRE: RegExp;
|
|
38
|
-
declare function positionToOffset(source: string, lineNumber: number, columnNumber: number): number;
|
|
39
|
-
declare function offsetToLineNumber(source: string, offset: number): number;
|
|
40
|
-
|
|
41
|
-
declare function shuffle<T>(array: T[], seed?: number): T[];
|
|
42
|
-
|
|
43
|
-
interface SafeTimers {
|
|
44
|
-
// node.js timers
|
|
45
|
-
nextTick?: (cb: () => void) => void;
|
|
46
|
-
setImmediate?: {
|
|
47
|
-
<TArgs extends any[]>(callback: (...args: TArgs) => void, ...args: TArgs): any
|
|
48
|
-
__promisify__: <T = void>(value?: T, options?: any) => Promise<T>
|
|
49
|
-
};
|
|
50
|
-
clearImmediate?: (immediateId: any) => void;
|
|
51
|
-
// cross-platform timers
|
|
52
|
-
setTimeout: typeof setTimeout;
|
|
53
|
-
setInterval: typeof setInterval;
|
|
54
|
-
clearInterval: typeof clearInterval;
|
|
55
|
-
clearTimeout: typeof clearTimeout;
|
|
56
|
-
queueMicrotask: typeof queueMicrotask;
|
|
57
|
-
}
|
|
58
|
-
declare function getSafeTimers(): SafeTimers;
|
|
59
|
-
declare function setSafeTimers(): void;
|
|
60
|
-
|
|
61
|
-
export { format, getSafeTimers, highlight, inspect, lineSplitRE, nanoid, objDisplay, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle, stringify };
|
|
62
|
-
export type { LoupeOptions, SafeTimers, StringifyOptions };
|
|
5
|
+
import '@vitest/pretty-format';
|