@vitest/utils 2.1.1 → 2.1.3

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,5 +1,6 @@
1
1
  export { assertTypes, clone, createDefer, createSimpleStackTrace, deepClone, getCallLastIndex, getOwnProperties, getType, isNegativeNaN, isObject, isPrimitive, noop, notNullish, objectAttr, parseRegexp, slash, toArray } from './helpers.js';
2
- export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-display.js';
2
+ import { g as getDefaultExportFromCjs } from './chunk-_commonjsHelpers.js';
3
+ export { f as format, i as inspect, o as objDisplay, s as stringify } from './chunk-_commonjsHelpers.js';
3
4
  import c from 'tinyrainbow';
4
5
  import 'loupe';
5
6
  import '@vitest/pretty-format';
@@ -99,400 +100,405 @@ function offsetToLineNumber(source, offset) {
99
100
  return line + 1;
100
101
  }
101
102
 
102
- function getDefaultExportFromCjs (x) {
103
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
104
- }
103
+ var jsTokens_1;
104
+ var hasRequiredJsTokens;
105
105
 
106
- // Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
107
- // License: MIT.
108
- var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
109
- RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
110
- Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
111
- Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
112
- StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
113
- 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;
114
- Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
115
- WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
116
- LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
117
- MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
118
- SingleLineComment = /\/\/.*/y;
119
- JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
120
- JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
121
- JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
122
- JSXText = /[^<>{}]+/y;
123
- TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
124
- TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
125
- KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
126
- KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
127
- Newline = RegExp(LineTerminatorSequence.source);
128
- var jsTokens_1 = function*(input, {jsx = false} = {}) {
129
- var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
130
- ({length} = input);
131
- lastIndex = 0;
132
- lastSignificantToken = "";
133
- stack = [
134
- {tag: "JS"}
135
- ];
136
- braces = [];
137
- parenNesting = 0;
138
- postfixIncDec = false;
139
- while (lastIndex < length) {
140
- mode = stack[stack.length - 1];
141
- switch (mode.tag) {
142
- case "JS":
143
- case "JSNonExpressionParen":
144
- case "InterpolationInTemplate":
145
- case "InterpolationInJSX":
146
- if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
147
- RegularExpressionLiteral.lastIndex = lastIndex;
148
- if (match = RegularExpressionLiteral.exec(input)) {
149
- lastIndex = RegularExpressionLiteral.lastIndex;
150
- lastSignificantToken = match[0];
151
- postfixIncDec = true;
152
- yield ({
153
- type: "RegularExpressionLiteral",
154
- value: match[0],
155
- closed: match[1] !== void 0 && match[1] !== "\\"
156
- });
157
- continue;
158
- }
159
- }
160
- Punctuator.lastIndex = lastIndex;
161
- if (match = Punctuator.exec(input)) {
162
- punctuator = match[0];
163
- nextLastIndex = Punctuator.lastIndex;
164
- nextLastSignificantToken = punctuator;
165
- switch (punctuator) {
166
- case "(":
167
- if (lastSignificantToken === "?NonExpressionParenKeyword") {
168
- stack.push({
169
- tag: "JSNonExpressionParen",
170
- nesting: parenNesting
171
- });
172
- }
173
- parenNesting++;
174
- postfixIncDec = false;
175
- break;
176
- case ")":
177
- parenNesting--;
106
+ function requireJsTokens () {
107
+ if (hasRequiredJsTokens) return jsTokens_1;
108
+ hasRequiredJsTokens = 1;
109
+ // Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell
110
+ // License: MIT.
111
+ var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace;
112
+ RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu;
113
+ Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y;
114
+ Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu;
115
+ StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y;
116
+ 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;
117
+ Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y;
118
+ WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu;
119
+ LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y;
120
+ MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y;
121
+ SingleLineComment = /\/\/.*/y;
122
+ JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y;
123
+ JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu;
124
+ JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y;
125
+ JSXText = /[^<>{}]+/y;
126
+ TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/;
127
+ TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/;
128
+ KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/;
129
+ KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/;
130
+ Newline = RegExp(LineTerminatorSequence.source);
131
+ jsTokens_1 = function*(input, {jsx = false} = {}) {
132
+ var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack;
133
+ ({length} = input);
134
+ lastIndex = 0;
135
+ lastSignificantToken = "";
136
+ stack = [
137
+ {tag: "JS"}
138
+ ];
139
+ braces = [];
140
+ parenNesting = 0;
141
+ postfixIncDec = false;
142
+ while (lastIndex < length) {
143
+ mode = stack[stack.length - 1];
144
+ switch (mode.tag) {
145
+ case "JS":
146
+ case "JSNonExpressionParen":
147
+ case "InterpolationInTemplate":
148
+ case "InterpolationInJSX":
149
+ if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
150
+ RegularExpressionLiteral.lastIndex = lastIndex;
151
+ if (match = RegularExpressionLiteral.exec(input)) {
152
+ lastIndex = RegularExpressionLiteral.lastIndex;
153
+ lastSignificantToken = match[0];
178
154
  postfixIncDec = true;
179
- if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
180
- stack.pop();
181
- nextLastSignificantToken = "?NonExpressionParenEnd";
155
+ yield ({
156
+ type: "RegularExpressionLiteral",
157
+ value: match[0],
158
+ closed: match[1] !== void 0 && match[1] !== "\\"
159
+ });
160
+ continue;
161
+ }
162
+ }
163
+ Punctuator.lastIndex = lastIndex;
164
+ if (match = Punctuator.exec(input)) {
165
+ punctuator = match[0];
166
+ nextLastIndex = Punctuator.lastIndex;
167
+ nextLastSignificantToken = punctuator;
168
+ switch (punctuator) {
169
+ case "(":
170
+ if (lastSignificantToken === "?NonExpressionParenKeyword") {
171
+ stack.push({
172
+ tag: "JSNonExpressionParen",
173
+ nesting: parenNesting
174
+ });
175
+ }
176
+ parenNesting++;
182
177
  postfixIncDec = false;
183
- }
184
- break;
185
- case "{":
186
- Punctuator.lastIndex = 0;
187
- isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
188
- braces.push(isExpression);
189
- postfixIncDec = false;
190
- break;
191
- case "}":
192
- switch (mode.tag) {
193
- case "InterpolationInTemplate":
194
- if (braces.length === mode.nesting) {
195
- Template.lastIndex = lastIndex;
196
- match = Template.exec(input);
197
- lastIndex = Template.lastIndex;
198
- lastSignificantToken = match[0];
199
- if (match[1] === "${") {
200
- lastSignificantToken = "?InterpolationInTemplate";
201
- postfixIncDec = false;
202
- yield ({
203
- type: "TemplateMiddle",
204
- value: match[0]
205
- });
206
- } else {
178
+ break;
179
+ case ")":
180
+ parenNesting--;
181
+ postfixIncDec = true;
182
+ if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) {
183
+ stack.pop();
184
+ nextLastSignificantToken = "?NonExpressionParenEnd";
185
+ postfixIncDec = false;
186
+ }
187
+ break;
188
+ case "{":
189
+ Punctuator.lastIndex = 0;
190
+ isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken));
191
+ braces.push(isExpression);
192
+ postfixIncDec = false;
193
+ break;
194
+ case "}":
195
+ switch (mode.tag) {
196
+ case "InterpolationInTemplate":
197
+ if (braces.length === mode.nesting) {
198
+ Template.lastIndex = lastIndex;
199
+ match = Template.exec(input);
200
+ lastIndex = Template.lastIndex;
201
+ lastSignificantToken = match[0];
202
+ if (match[1] === "${") {
203
+ lastSignificantToken = "?InterpolationInTemplate";
204
+ postfixIncDec = false;
205
+ yield ({
206
+ type: "TemplateMiddle",
207
+ value: match[0]
208
+ });
209
+ } else {
210
+ stack.pop();
211
+ postfixIncDec = true;
212
+ yield ({
213
+ type: "TemplateTail",
214
+ value: match[0],
215
+ closed: match[1] === "`"
216
+ });
217
+ }
218
+ continue;
219
+ }
220
+ break;
221
+ case "InterpolationInJSX":
222
+ if (braces.length === mode.nesting) {
207
223
  stack.pop();
208
- postfixIncDec = true;
224
+ lastIndex += 1;
225
+ lastSignificantToken = "}";
209
226
  yield ({
210
- type: "TemplateTail",
211
- value: match[0],
212
- closed: match[1] === "`"
227
+ type: "JSXPunctuator",
228
+ value: "}"
213
229
  });
230
+ continue;
214
231
  }
215
- continue;
216
- }
217
- break;
218
- case "InterpolationInJSX":
219
- if (braces.length === mode.nesting) {
220
- stack.pop();
221
- lastIndex += 1;
222
- lastSignificantToken = "}";
223
- yield ({
224
- type: "JSXPunctuator",
225
- value: "}"
226
- });
227
- continue;
228
- }
229
- }
230
- postfixIncDec = braces.pop();
231
- nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
232
- break;
233
- case "]":
234
- postfixIncDec = true;
235
- break;
236
- case "++":
237
- case "--":
238
- nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
239
- break;
240
- case "<":
241
- if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
242
- stack.push({tag: "JSXTag"});
243
- lastIndex += 1;
244
- lastSignificantToken = "<";
245
- yield ({
246
- type: "JSXPunctuator",
247
- value: punctuator
248
- });
249
- continue;
250
- }
251
- postfixIncDec = false;
252
- break;
253
- default:
254
- postfixIncDec = false;
255
- }
256
- lastIndex = nextLastIndex;
257
- lastSignificantToken = nextLastSignificantToken;
258
- yield ({
259
- type: "Punctuator",
260
- value: punctuator
261
- });
262
- continue;
263
- }
264
- Identifier.lastIndex = lastIndex;
265
- if (match = Identifier.exec(input)) {
266
- lastIndex = Identifier.lastIndex;
267
- nextLastSignificantToken = match[0];
268
- switch (match[0]) {
269
- case "for":
270
- case "if":
271
- case "while":
272
- case "with":
273
- if (lastSignificantToken !== "." && lastSignificantToken !== "?.") {
274
- nextLastSignificantToken = "?NonExpressionParenKeyword";
275
- }
276
- }
277
- lastSignificantToken = nextLastSignificantToken;
278
- postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
279
- yield ({
280
- type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
281
- value: match[0]
282
- });
283
- continue;
284
- }
285
- StringLiteral.lastIndex = lastIndex;
286
- if (match = StringLiteral.exec(input)) {
287
- lastIndex = StringLiteral.lastIndex;
288
- lastSignificantToken = match[0];
289
- postfixIncDec = true;
290
- yield ({
291
- type: "StringLiteral",
292
- value: match[0],
293
- closed: match[2] !== void 0
294
- });
295
- continue;
296
- }
297
- NumericLiteral.lastIndex = lastIndex;
298
- if (match = NumericLiteral.exec(input)) {
299
- lastIndex = NumericLiteral.lastIndex;
300
- lastSignificantToken = match[0];
301
- postfixIncDec = true;
302
- yield ({
303
- type: "NumericLiteral",
304
- value: match[0]
305
- });
306
- continue;
307
- }
308
- Template.lastIndex = lastIndex;
309
- if (match = Template.exec(input)) {
310
- lastIndex = Template.lastIndex;
311
- lastSignificantToken = match[0];
312
- if (match[1] === "${") {
313
- lastSignificantToken = "?InterpolationInTemplate";
314
- stack.push({
315
- tag: "InterpolationInTemplate",
316
- nesting: braces.length
232
+ }
233
+ postfixIncDec = braces.pop();
234
+ nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}";
235
+ break;
236
+ case "]":
237
+ postfixIncDec = true;
238
+ break;
239
+ case "++":
240
+ case "--":
241
+ nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec";
242
+ break;
243
+ case "<":
244
+ if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) {
245
+ stack.push({tag: "JSXTag"});
246
+ lastIndex += 1;
247
+ lastSignificantToken = "<";
248
+ yield ({
249
+ type: "JSXPunctuator",
250
+ value: punctuator
251
+ });
252
+ continue;
253
+ }
254
+ postfixIncDec = false;
255
+ break;
256
+ default:
257
+ postfixIncDec = false;
258
+ }
259
+ lastIndex = nextLastIndex;
260
+ lastSignificantToken = nextLastSignificantToken;
261
+ yield ({
262
+ type: "Punctuator",
263
+ value: punctuator
317
264
  });
318
- postfixIncDec = false;
265
+ continue;
266
+ }
267
+ Identifier.lastIndex = lastIndex;
268
+ if (match = Identifier.exec(input)) {
269
+ lastIndex = Identifier.lastIndex;
270
+ nextLastSignificantToken = match[0];
271
+ switch (match[0]) {
272
+ case "for":
273
+ case "if":
274
+ case "while":
275
+ case "with":
276
+ if (lastSignificantToken !== "." && lastSignificantToken !== "?.") {
277
+ nextLastSignificantToken = "?NonExpressionParenKeyword";
278
+ }
279
+ }
280
+ lastSignificantToken = nextLastSignificantToken;
281
+ postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]);
319
282
  yield ({
320
- type: "TemplateHead",
283
+ type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName",
321
284
  value: match[0]
322
285
  });
323
- } else {
286
+ continue;
287
+ }
288
+ StringLiteral.lastIndex = lastIndex;
289
+ if (match = StringLiteral.exec(input)) {
290
+ lastIndex = StringLiteral.lastIndex;
291
+ lastSignificantToken = match[0];
324
292
  postfixIncDec = true;
325
293
  yield ({
326
- type: "NoSubstitutionTemplate",
294
+ type: "StringLiteral",
327
295
  value: match[0],
328
- closed: match[1] === "`"
296
+ closed: match[2] !== void 0
329
297
  });
298
+ continue;
330
299
  }
331
- continue;
332
- }
333
- break;
334
- case "JSXTag":
335
- case "JSXTagEnd":
336
- JSXPunctuator.lastIndex = lastIndex;
337
- if (match = JSXPunctuator.exec(input)) {
338
- lastIndex = JSXPunctuator.lastIndex;
339
- nextLastSignificantToken = match[0];
340
- switch (match[0]) {
341
- case "<":
342
- stack.push({tag: "JSXTag"});
343
- break;
344
- case ">":
345
- stack.pop();
346
- if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
347
- nextLastSignificantToken = "?JSX";
348
- postfixIncDec = true;
349
- } else {
350
- stack.push({tag: "JSXChildren"});
351
- }
352
- break;
353
- case "{":
300
+ NumericLiteral.lastIndex = lastIndex;
301
+ if (match = NumericLiteral.exec(input)) {
302
+ lastIndex = NumericLiteral.lastIndex;
303
+ lastSignificantToken = match[0];
304
+ postfixIncDec = true;
305
+ yield ({
306
+ type: "NumericLiteral",
307
+ value: match[0]
308
+ });
309
+ continue;
310
+ }
311
+ Template.lastIndex = lastIndex;
312
+ if (match = Template.exec(input)) {
313
+ lastIndex = Template.lastIndex;
314
+ lastSignificantToken = match[0];
315
+ if (match[1] === "${") {
316
+ lastSignificantToken = "?InterpolationInTemplate";
354
317
  stack.push({
355
- tag: "InterpolationInJSX",
318
+ tag: "InterpolationInTemplate",
356
319
  nesting: braces.length
357
320
  });
358
- nextLastSignificantToken = "?InterpolationInJSX";
359
321
  postfixIncDec = false;
360
- break;
361
- case "/":
362
- if (lastSignificantToken === "<") {
322
+ yield ({
323
+ type: "TemplateHead",
324
+ value: match[0]
325
+ });
326
+ } else {
327
+ postfixIncDec = true;
328
+ yield ({
329
+ type: "NoSubstitutionTemplate",
330
+ value: match[0],
331
+ closed: match[1] === "`"
332
+ });
333
+ }
334
+ continue;
335
+ }
336
+ break;
337
+ case "JSXTag":
338
+ case "JSXTagEnd":
339
+ JSXPunctuator.lastIndex = lastIndex;
340
+ if (match = JSXPunctuator.exec(input)) {
341
+ lastIndex = JSXPunctuator.lastIndex;
342
+ nextLastSignificantToken = match[0];
343
+ switch (match[0]) {
344
+ case "<":
345
+ stack.push({tag: "JSXTag"});
346
+ break;
347
+ case ">":
363
348
  stack.pop();
364
- if (stack[stack.length - 1].tag === "JSXChildren") {
349
+ if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") {
350
+ nextLastSignificantToken = "?JSX";
351
+ postfixIncDec = true;
352
+ } else {
353
+ stack.push({tag: "JSXChildren"});
354
+ }
355
+ break;
356
+ case "{":
357
+ stack.push({
358
+ tag: "InterpolationInJSX",
359
+ nesting: braces.length
360
+ });
361
+ nextLastSignificantToken = "?InterpolationInJSX";
362
+ postfixIncDec = false;
363
+ break;
364
+ case "/":
365
+ if (lastSignificantToken === "<") {
365
366
  stack.pop();
367
+ if (stack[stack.length - 1].tag === "JSXChildren") {
368
+ stack.pop();
369
+ }
370
+ stack.push({tag: "JSXTagEnd"});
366
371
  }
367
- stack.push({tag: "JSXTagEnd"});
368
- }
369
- }
370
- lastSignificantToken = nextLastSignificantToken;
371
- yield ({
372
- type: "JSXPunctuator",
373
- value: match[0]
374
- });
375
- continue;
376
- }
377
- JSXIdentifier.lastIndex = lastIndex;
378
- if (match = JSXIdentifier.exec(input)) {
379
- lastIndex = JSXIdentifier.lastIndex;
380
- lastSignificantToken = match[0];
381
- yield ({
382
- type: "JSXIdentifier",
383
- value: match[0]
384
- });
385
- continue;
386
- }
387
- JSXString.lastIndex = lastIndex;
388
- if (match = JSXString.exec(input)) {
389
- lastIndex = JSXString.lastIndex;
390
- lastSignificantToken = match[0];
391
- yield ({
392
- type: "JSXString",
393
- value: match[0],
394
- closed: match[2] !== void 0
395
- });
396
- continue;
397
- }
398
- break;
399
- case "JSXChildren":
400
- JSXText.lastIndex = lastIndex;
401
- if (match = JSXText.exec(input)) {
402
- lastIndex = JSXText.lastIndex;
403
- lastSignificantToken = match[0];
404
- yield ({
405
- type: "JSXText",
406
- value: match[0]
407
- });
408
- continue;
409
- }
410
- switch (input[lastIndex]) {
411
- case "<":
412
- stack.push({tag: "JSXTag"});
413
- lastIndex++;
414
- lastSignificantToken = "<";
372
+ }
373
+ lastSignificantToken = nextLastSignificantToken;
415
374
  yield ({
416
375
  type: "JSXPunctuator",
417
- value: "<"
376
+ value: match[0]
418
377
  });
419
378
  continue;
420
- case "{":
421
- stack.push({
422
- tag: "InterpolationInJSX",
423
- nesting: braces.length
379
+ }
380
+ JSXIdentifier.lastIndex = lastIndex;
381
+ if (match = JSXIdentifier.exec(input)) {
382
+ lastIndex = JSXIdentifier.lastIndex;
383
+ lastSignificantToken = match[0];
384
+ yield ({
385
+ type: "JSXIdentifier",
386
+ value: match[0]
424
387
  });
425
- lastIndex++;
426
- lastSignificantToken = "?InterpolationInJSX";
427
- postfixIncDec = false;
388
+ continue;
389
+ }
390
+ JSXString.lastIndex = lastIndex;
391
+ if (match = JSXString.exec(input)) {
392
+ lastIndex = JSXString.lastIndex;
393
+ lastSignificantToken = match[0];
428
394
  yield ({
429
- type: "JSXPunctuator",
430
- value: "{"
395
+ type: "JSXString",
396
+ value: match[0],
397
+ closed: match[2] !== void 0
431
398
  });
432
399
  continue;
433
- }
434
- }
435
- WhiteSpace.lastIndex = lastIndex;
436
- if (match = WhiteSpace.exec(input)) {
437
- lastIndex = WhiteSpace.lastIndex;
438
- yield ({
439
- type: "WhiteSpace",
440
- value: match[0]
441
- });
442
- continue;
443
- }
444
- LineTerminatorSequence.lastIndex = lastIndex;
445
- if (match = LineTerminatorSequence.exec(input)) {
446
- lastIndex = LineTerminatorSequence.lastIndex;
447
- postfixIncDec = false;
448
- if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
449
- lastSignificantToken = "?NoLineTerminatorHere";
400
+ }
401
+ break;
402
+ case "JSXChildren":
403
+ JSXText.lastIndex = lastIndex;
404
+ if (match = JSXText.exec(input)) {
405
+ lastIndex = JSXText.lastIndex;
406
+ lastSignificantToken = match[0];
407
+ yield ({
408
+ type: "JSXText",
409
+ value: match[0]
410
+ });
411
+ continue;
412
+ }
413
+ switch (input[lastIndex]) {
414
+ case "<":
415
+ stack.push({tag: "JSXTag"});
416
+ lastIndex++;
417
+ lastSignificantToken = "<";
418
+ yield ({
419
+ type: "JSXPunctuator",
420
+ value: "<"
421
+ });
422
+ continue;
423
+ case "{":
424
+ stack.push({
425
+ tag: "InterpolationInJSX",
426
+ nesting: braces.length
427
+ });
428
+ lastIndex++;
429
+ lastSignificantToken = "?InterpolationInJSX";
430
+ postfixIncDec = false;
431
+ yield ({
432
+ type: "JSXPunctuator",
433
+ value: "{"
434
+ });
435
+ continue;
436
+ }
450
437
  }
451
- yield ({
452
- type: "LineTerminatorSequence",
453
- value: match[0]
454
- });
455
- continue;
456
- }
457
- MultiLineComment.lastIndex = lastIndex;
458
- if (match = MultiLineComment.exec(input)) {
459
- lastIndex = MultiLineComment.lastIndex;
460
- if (Newline.test(match[0])) {
438
+ WhiteSpace.lastIndex = lastIndex;
439
+ if (match = WhiteSpace.exec(input)) {
440
+ lastIndex = WhiteSpace.lastIndex;
441
+ yield ({
442
+ type: "WhiteSpace",
443
+ value: match[0]
444
+ });
445
+ continue;
446
+ }
447
+ LineTerminatorSequence.lastIndex = lastIndex;
448
+ if (match = LineTerminatorSequence.exec(input)) {
449
+ lastIndex = LineTerminatorSequence.lastIndex;
461
450
  postfixIncDec = false;
462
451
  if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
463
452
  lastSignificantToken = "?NoLineTerminatorHere";
464
453
  }
454
+ yield ({
455
+ type: "LineTerminatorSequence",
456
+ value: match[0]
457
+ });
458
+ continue;
465
459
  }
466
- yield ({
467
- type: "MultiLineComment",
468
- value: match[0],
469
- closed: match[1] !== void 0
470
- });
471
- continue;
472
- }
473
- SingleLineComment.lastIndex = lastIndex;
474
- if (match = SingleLineComment.exec(input)) {
475
- lastIndex = SingleLineComment.lastIndex;
460
+ MultiLineComment.lastIndex = lastIndex;
461
+ if (match = MultiLineComment.exec(input)) {
462
+ lastIndex = MultiLineComment.lastIndex;
463
+ if (Newline.test(match[0])) {
464
+ postfixIncDec = false;
465
+ if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) {
466
+ lastSignificantToken = "?NoLineTerminatorHere";
467
+ }
468
+ }
469
+ yield ({
470
+ type: "MultiLineComment",
471
+ value: match[0],
472
+ closed: match[1] !== void 0
473
+ });
474
+ continue;
475
+ }
476
+ SingleLineComment.lastIndex = lastIndex;
477
+ if (match = SingleLineComment.exec(input)) {
478
+ lastIndex = SingleLineComment.lastIndex;
479
+ postfixIncDec = false;
480
+ yield ({
481
+ type: "SingleLineComment",
482
+ value: match[0]
483
+ });
484
+ continue;
485
+ }
486
+ firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
487
+ lastIndex += firstCodePoint.length;
488
+ lastSignificantToken = firstCodePoint;
476
489
  postfixIncDec = false;
477
490
  yield ({
478
- type: "SingleLineComment",
479
- value: match[0]
491
+ type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
492
+ value: firstCodePoint
480
493
  });
481
- continue;
482
494
  }
483
- firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex));
484
- lastIndex += firstCodePoint.length;
485
- lastSignificantToken = firstCodePoint;
486
- postfixIncDec = false;
487
- yield ({
488
- type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid",
489
- value: firstCodePoint
490
- });
491
- }
492
- return void 0;
493
- };
495
+ return void 0;
496
+ };
497
+ return jsTokens_1;
498
+ }
494
499
 
495
- var jsTokens = /*@__PURE__*/getDefaultExportFromCjs(jsTokens_1);
500
+ var jsTokensExports = requireJsTokens();
501
+ var jsTokens = /*@__PURE__*/getDefaultExportFromCjs(jsTokensExports);
496
502
 
497
503
  // src/index.ts
498
504
  var reservedWords = {
@@ -628,4 +634,14 @@ function highlight(code, options = { jsx: false }) {
628
634
  });
629
635
  }
630
636
 
631
- export { getSafeTimers, highlight, lineSplitRE, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle };
637
+ const urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
638
+ function nanoid(size = 21) {
639
+ let id = "";
640
+ let i = size;
641
+ while (i--) {
642
+ id += urlAlphabet[Math.random() * 64 | 0];
643
+ }
644
+ return id;
645
+ }
646
+
647
+ export { getSafeTimers, highlight, lineSplitRE, nanoid, offsetToLineNumber, positionToOffset, setSafeTimers, shuffle };