@rspack-canary/test-tools 1.6.0-canary-beafb11e-20251019174144 → 1.6.0-canary-0eb13821-20251021173640

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.
Files changed (39) hide show
  1. package/dist/case/cache.js +3 -0
  2. package/dist/case/common.d.ts +1 -0
  3. package/dist/case/common.js +15 -12
  4. package/dist/case/config.js +4 -1
  5. package/dist/case/esm-output.js +28 -2
  6. package/dist/case/hot.d.ts +1 -1
  7. package/dist/case/hot.js +4 -3
  8. package/dist/case/incremental.d.ts +1 -1
  9. package/dist/case/incremental.js +1 -20
  10. package/dist/case/normal.js +3 -0
  11. package/dist/case/runner.d.ts +1 -1
  12. package/dist/case/runner.js +4 -3
  13. package/dist/case/watch.d.ts +3 -1
  14. package/dist/case/watch.js +5 -4
  15. package/dist/helper/hot-update/plugin.js +1 -1
  16. package/dist/helper/legacy/asModule.js +0 -2
  17. package/dist/helper/legacy/createLazyTestEnv.d.ts +1 -0
  18. package/dist/helper/legacy/createLazyTestEnv.js +3 -1
  19. package/dist/helper/legacy/supportsTextDecoder.d.ts +2 -0
  20. package/dist/helper/legacy/supportsTextDecoder.js +9 -0
  21. package/dist/helper/setup-env.js +15 -0
  22. package/dist/runner/node/index.js +7 -3
  23. package/dist/runner/web/index.d.ts +20 -7
  24. package/dist/runner/web/index.js +293 -18
  25. package/dist/test/creator.js +13 -7
  26. package/dist/test/tester.d.ts +1 -0
  27. package/dist/test/tester.js +5 -0
  28. package/dist/type.d.ts +5 -5
  29. package/dist/type.js +1 -6
  30. package/jest.d.ts +2 -0
  31. package/package.json +3 -3
  32. package/dist/helper/legacy/FakeDocument.d.ts +0 -54
  33. package/dist/helper/legacy/FakeDocument.js +0 -280
  34. package/dist/helper/legacy/walkCssTokens.d.ts +0 -40
  35. package/dist/helper/legacy/walkCssTokens.js +0 -761
  36. package/dist/runner/web/fake.d.ts +0 -15
  37. package/dist/runner/web/fake.js +0 -215
  38. package/dist/runner/web/jsdom.d.ts +0 -24
  39. package/dist/runner/web/jsdom.js +0 -241
@@ -1,761 +0,0 @@
1
- // @ts-nocheck
2
- /*
3
- MIT License http://www.opensource.org/licenses/mit-license.php
4
- Author Tobias Koppers @sokra
5
- */
6
- "use strict";
7
- /**
8
- * @typedef {Object} CssTokenCallbacks
9
- * @property {function(string, number): boolean=} isSelector
10
- * @property {function(string, number, number, number, number): number=} url
11
- * @property {function(string, number, number): number=} string
12
- * @property {function(string, number, number): number=} leftParenthesis
13
- * @property {function(string, number, number): number=} rightParenthesis
14
- * @property {function(string, number, number): number=} pseudoFunction
15
- * @property {function(string, number, number): number=} function
16
- * @property {function(string, number, number): number=} pseudoClass
17
- * @property {function(string, number, number): number=} atKeyword
18
- * @property {function(string, number, number): number=} class
19
- * @property {function(string, number, number): number=} identifier
20
- * @property {function(string, number, number): number=} id
21
- * @property {function(string, number, number): number=} leftCurlyBracket
22
- * @property {function(string, number, number): number=} rightCurlyBracket
23
- * @property {function(string, number, number): number=} semicolon
24
- * @property {function(string, number, number): number=} comma
25
- */
26
- /** @typedef {function(string, number, CssTokenCallbacks): number} CharHandler */
27
- // spec: https://drafts.csswg.org/css-syntax/
28
- const CC_LINE_FEED = "\n".charCodeAt(0);
29
- const CC_CARRIAGE_RETURN = "\r".charCodeAt(0);
30
- const CC_FORM_FEED = "\f".charCodeAt(0);
31
- const CC_TAB = "\t".charCodeAt(0);
32
- const CC_SPACE = " ".charCodeAt(0);
33
- const CC_SOLIDUS = "/".charCodeAt(0);
34
- const CC_REVERSE_SOLIDUS = "\\".charCodeAt(0);
35
- const CC_ASTERISK = "*".charCodeAt(0);
36
- const CC_LEFT_PARENTHESIS = "(".charCodeAt(0);
37
- const CC_RIGHT_PARENTHESIS = ")".charCodeAt(0);
38
- const CC_LEFT_CURLY = "{".charCodeAt(0);
39
- const CC_RIGHT_CURLY = "}".charCodeAt(0);
40
- const CC_LEFT_SQUARE = "[".charCodeAt(0);
41
- const CC_RIGHT_SQUARE = "]".charCodeAt(0);
42
- const CC_QUOTATION_MARK = '"'.charCodeAt(0);
43
- const CC_APOSTROPHE = "'".charCodeAt(0);
44
- const CC_FULL_STOP = ".".charCodeAt(0);
45
- const CC_COLON = ":".charCodeAt(0);
46
- const CC_SEMICOLON = ";".charCodeAt(0);
47
- const CC_COMMA = ",".charCodeAt(0);
48
- const CC_PERCENTAGE = "%".charCodeAt(0);
49
- const CC_AT_SIGN = "@".charCodeAt(0);
50
- const CC_LOW_LINE = "_".charCodeAt(0);
51
- const CC_LOWER_A = "a".charCodeAt(0);
52
- const CC_LOWER_U = "u".charCodeAt(0);
53
- const CC_LOWER_E = "e".charCodeAt(0);
54
- const CC_LOWER_Z = "z".charCodeAt(0);
55
- const CC_UPPER_A = "A".charCodeAt(0);
56
- const CC_UPPER_E = "E".charCodeAt(0);
57
- const CC_UPPER_U = "U".charCodeAt(0);
58
- const CC_UPPER_Z = "Z".charCodeAt(0);
59
- const CC_0 = "0".charCodeAt(0);
60
- const CC_9 = "9".charCodeAt(0);
61
- const CC_NUMBER_SIGN = "#".charCodeAt(0);
62
- const CC_PLUS_SIGN = "+".charCodeAt(0);
63
- const CC_HYPHEN_MINUS = "-".charCodeAt(0);
64
- const CC_LESS_THAN_SIGN = "<".charCodeAt(0);
65
- const CC_GREATER_THAN_SIGN = ">".charCodeAt(0);
66
- /**
67
- * @param {number} cc char code
68
- * @returns {boolean} true, if cc is a newline
69
- */
70
- const _isNewLine = cc => {
71
- return (cc === CC_LINE_FEED || cc === CC_CARRIAGE_RETURN || cc === CC_FORM_FEED);
72
- };
73
- /** @type {CharHandler} */
74
- const consumeSpace = (input, pos, callbacks) => {
75
- /** @type {number} */
76
- let cc;
77
- do {
78
- pos++;
79
- cc = input.charCodeAt(pos);
80
- } while (_isWhiteSpace(cc));
81
- return pos;
82
- };
83
- /**
84
- * @param {number} cc char code
85
- * @returns {boolean} true, if cc is a newline
86
- */
87
- const _isNewline = cc => {
88
- return (cc === CC_LINE_FEED || cc === CC_CARRIAGE_RETURN || cc === CC_FORM_FEED);
89
- };
90
- /**
91
- * @param {number} cc char code
92
- * @returns {boolean} true, if cc is a space (U+0009 CHARACTER TABULATION or U+0020 SPACE)
93
- */
94
- const _isSpace = cc => {
95
- return cc === CC_TAB || cc === CC_SPACE;
96
- };
97
- /**
98
- * @param {number} cc char code
99
- * @returns {boolean} true, if cc is a whitespace
100
- */
101
- const _isWhiteSpace = cc => {
102
- return _isNewline(cc) || _isSpace(cc);
103
- };
104
- /**
105
- * ident-start code point
106
- *
107
- * A letter, a non-ASCII code point, or U+005F LOW LINE (_).
108
- *
109
- * @param {number} cc char code
110
- * @returns {boolean} true, if cc is a start code point of an identifier
111
- */
112
- const isIdentStartCodePoint = cc => {
113
- return ((cc >= CC_LOWER_A && cc <= CC_LOWER_Z) ||
114
- (cc >= CC_UPPER_A && cc <= CC_UPPER_Z) ||
115
- cc === CC_LOW_LINE ||
116
- cc >= 0x80);
117
- };
118
- /** @type {CharHandler} */
119
- const consumeDelimToken = (input, pos, callbacks) => {
120
- return pos + 1;
121
- };
122
- /** @type {CharHandler} */
123
- const consumeComments = (input, pos, callbacks) => {
124
- // If the next two input code point are U+002F SOLIDUS (/) followed by a U+002A
125
- // ASTERISK (*), consume them and all following code points up to and including
126
- // the first U+002A ASTERISK (*) followed by a U+002F SOLIDUS (/), or up to an
127
- // EOF code point. Return to the start of this step.
128
- //
129
- // If the preceding paragraph ended by consuming an EOF code point, this is a parse error.
130
- // But we are silent on errors.
131
- if (input.charCodeAt(pos) === CC_SOLIDUS &&
132
- input.charCodeAt(pos + 1) === CC_ASTERISK) {
133
- pos += 1;
134
- while (pos < input.length) {
135
- if (input.charCodeAt(pos) === CC_ASTERISK &&
136
- input.charCodeAt(pos + 1) === CC_SOLIDUS) {
137
- pos += 2;
138
- break;
139
- }
140
- pos++;
141
- }
142
- }
143
- return pos;
144
- };
145
- /** @type {function(number): CharHandler} */
146
- const consumeString = quote_cc => (input, pos, callbacks) => {
147
- const start = pos;
148
- pos = _consumeString(input, pos, quote_cc);
149
- if (callbacks.string !== undefined) {
150
- pos = callbacks.string(input, start, pos);
151
- }
152
- return pos;
153
- };
154
- /**
155
- * @param {string} input input
156
- * @param {number} pos position
157
- * @param {number} quote_cc quote char code
158
- * @returns {number} new position
159
- */
160
- const _consumeString = (input, pos, quote_cc) => {
161
- pos++;
162
- for (;;) {
163
- if (pos === input.length)
164
- return pos;
165
- const cc = input.charCodeAt(pos);
166
- if (cc === quote_cc)
167
- return pos + 1;
168
- if (_isNewLine(cc)) {
169
- // bad string
170
- return pos;
171
- }
172
- if (cc === CC_REVERSE_SOLIDUS) {
173
- // we don't need to fully parse the escaped code point
174
- // just skip over a potential new line
175
- pos++;
176
- if (pos === input.length)
177
- return pos;
178
- pos++;
179
- }
180
- else {
181
- pos++;
182
- }
183
- }
184
- };
185
- /**
186
- * @param {number} cc char code
187
- * @returns {boolean} is identifier start code
188
- */
189
- const _isIdentifierStartCode = cc => {
190
- return (cc === CC_LOW_LINE ||
191
- (cc >= CC_LOWER_A && cc <= CC_LOWER_Z) ||
192
- (cc >= CC_UPPER_A && cc <= CC_UPPER_Z) ||
193
- cc > 0x80);
194
- };
195
- /**
196
- * @param {number} first first code point
197
- * @param {number} second second code point
198
- * @returns {boolean} true if two code points are a valid escape
199
- */
200
- const _isTwoCodePointsAreValidEscape = (first, second) => {
201
- if (first !== CC_REVERSE_SOLIDUS)
202
- return false;
203
- if (_isNewLine(second))
204
- return false;
205
- return true;
206
- };
207
- /**
208
- * @param {number} cc char code
209
- * @returns {boolean} is digit
210
- */
211
- const _isDigit = cc => {
212
- return cc >= CC_0 && cc <= CC_9;
213
- };
214
- /**
215
- * @param {string} input input
216
- * @param {number} pos position
217
- * @returns {boolean} true, if input at pos starts an identifier
218
- */
219
- const _startsIdentifier = (input, pos) => {
220
- const cc = input.charCodeAt(pos);
221
- if (cc === CC_HYPHEN_MINUS) {
222
- if (pos === input.length)
223
- return false;
224
- const cc = input.charCodeAt(pos + 1);
225
- if (cc === CC_HYPHEN_MINUS)
226
- return true;
227
- if (cc === CC_REVERSE_SOLIDUS) {
228
- const cc = input.charCodeAt(pos + 2);
229
- return !_isNewLine(cc);
230
- }
231
- return _isIdentifierStartCode(cc);
232
- }
233
- if (cc === CC_REVERSE_SOLIDUS) {
234
- const cc = input.charCodeAt(pos + 1);
235
- return !_isNewLine(cc);
236
- }
237
- return _isIdentifierStartCode(cc);
238
- };
239
- /** @type {CharHandler} */
240
- const consumeNumberSign = (input, pos, callbacks) => {
241
- const start = pos;
242
- pos++;
243
- if (pos === input.length)
244
- return pos;
245
- if (callbacks.isSelector(input, pos) && _startsIdentifier(input, pos)) {
246
- pos = _consumeIdentifier(input, pos, callbacks);
247
- if (callbacks.id !== undefined) {
248
- return callbacks.id(input, start, pos);
249
- }
250
- }
251
- return pos;
252
- };
253
- /** @type {CharHandler} */
254
- const consumeMinus = (input, pos, callbacks) => {
255
- const start = pos;
256
- pos++;
257
- if (pos === input.length)
258
- return pos;
259
- const cc = input.charCodeAt(pos);
260
- // If the input stream starts with a number, reconsume the current input code point, consume a numeric token, and return it.
261
- if (cc === CC_FULL_STOP || _isDigit(cc)) {
262
- return consumeNumericToken(input, pos, callbacks);
263
- }
264
- else if (cc === CC_HYPHEN_MINUS) {
265
- pos++;
266
- if (pos === input.length)
267
- return pos;
268
- const cc = input.charCodeAt(pos);
269
- if (cc === CC_GREATER_THAN_SIGN) {
270
- return pos + 1;
271
- }
272
- else {
273
- pos = _consumeIdentifier(input, pos, callbacks);
274
- if (callbacks.identifier !== undefined) {
275
- return callbacks.identifier(input, start, pos);
276
- }
277
- }
278
- }
279
- else if (cc === CC_REVERSE_SOLIDUS) {
280
- if (pos + 1 === input.length)
281
- return pos;
282
- const cc = input.charCodeAt(pos + 1);
283
- if (_isNewLine(cc))
284
- return pos;
285
- pos = _consumeIdentifier(input, pos, callbacks);
286
- if (callbacks.identifier !== undefined) {
287
- return callbacks.identifier(input, start, pos);
288
- }
289
- }
290
- else if (_isIdentifierStartCode(cc)) {
291
- pos = consumeOtherIdentifier(input, pos - 1, callbacks);
292
- }
293
- return pos;
294
- };
295
- /** @type {CharHandler} */
296
- const consumeDot = (input, pos, callbacks) => {
297
- const start = pos;
298
- pos++;
299
- if (pos === input.length)
300
- return pos;
301
- const cc = input.charCodeAt(pos);
302
- if (_isDigit(cc))
303
- return consumeNumericToken(input, pos - 2, callbacks);
304
- if (!callbacks.isSelector(input, pos) || !_startsIdentifier(input, pos))
305
- return pos;
306
- pos = _consumeIdentifier(input, pos, callbacks);
307
- if (callbacks.class !== undefined)
308
- return callbacks.class(input, start, pos);
309
- return pos;
310
- };
311
- /** @type {CharHandler} */
312
- const consumeNumericToken = (input, pos, callbacks) => {
313
- pos = _consumeNumber(input, pos, callbacks);
314
- if (pos === input.length)
315
- return pos;
316
- if (_startsIdentifier(input, pos))
317
- return _consumeIdentifier(input, pos, callbacks);
318
- const cc = input.charCodeAt(pos);
319
- if (cc === CC_PERCENTAGE)
320
- return pos + 1;
321
- return pos;
322
- };
323
- /** @type {CharHandler} */
324
- const consumeOtherIdentifier = (input, pos, callbacks) => {
325
- const start = pos;
326
- pos = _consumeIdentifier(input, pos, callbacks);
327
- if (pos !== input.length && input.charCodeAt(pos) === CC_LEFT_PARENTHESIS) {
328
- pos++;
329
- if (callbacks.function !== undefined) {
330
- return callbacks.function(input, start, pos);
331
- }
332
- }
333
- else {
334
- if (callbacks.identifier !== undefined) {
335
- return callbacks.identifier(input, start, pos);
336
- }
337
- }
338
- return pos;
339
- };
340
- /** @type {CharHandler} */
341
- const consumePotentialUrl = (input, pos, callbacks) => {
342
- const start = pos;
343
- pos = _consumeIdentifier(input, pos, callbacks);
344
- const nextPos = pos + 1;
345
- if (pos === start + 3 &&
346
- input.slice(start, nextPos).toLowerCase() === "url(") {
347
- pos++;
348
- let cc = input.charCodeAt(pos);
349
- while (_isWhiteSpace(cc)) {
350
- pos++;
351
- if (pos === input.length)
352
- return pos;
353
- cc = input.charCodeAt(pos);
354
- }
355
- if (cc === CC_QUOTATION_MARK || cc === CC_APOSTROPHE) {
356
- if (callbacks.function !== undefined) {
357
- return callbacks.function(input, start, nextPos);
358
- }
359
- return nextPos;
360
- }
361
- else {
362
- const contentStart = pos;
363
- /** @type {number} */
364
- let contentEnd;
365
- for (;;) {
366
- if (cc === CC_REVERSE_SOLIDUS) {
367
- pos++;
368
- if (pos === input.length)
369
- return pos;
370
- pos++;
371
- }
372
- else if (_isWhiteSpace(cc)) {
373
- contentEnd = pos;
374
- do {
375
- pos++;
376
- if (pos === input.length)
377
- return pos;
378
- cc = input.charCodeAt(pos);
379
- } while (_isWhiteSpace(cc));
380
- if (cc !== CC_RIGHT_PARENTHESIS)
381
- return pos;
382
- pos++;
383
- if (callbacks.url !== undefined) {
384
- return callbacks.url(input, start, pos, contentStart, contentEnd);
385
- }
386
- return pos;
387
- }
388
- else if (cc === CC_RIGHT_PARENTHESIS) {
389
- contentEnd = pos;
390
- pos++;
391
- if (callbacks.url !== undefined) {
392
- return callbacks.url(input, start, pos, contentStart, contentEnd);
393
- }
394
- return pos;
395
- }
396
- else if (cc === CC_LEFT_PARENTHESIS) {
397
- return pos;
398
- }
399
- else {
400
- pos++;
401
- }
402
- if (pos === input.length)
403
- return pos;
404
- cc = input.charCodeAt(pos);
405
- }
406
- }
407
- }
408
- else {
409
- if (callbacks.identifier !== undefined) {
410
- return callbacks.identifier(input, start, pos);
411
- }
412
- return pos;
413
- }
414
- };
415
- /** @type {CharHandler} */
416
- const consumePotentialPseudo = (input, pos, callbacks) => {
417
- const start = pos;
418
- pos++;
419
- if (!callbacks.isSelector(input, pos) || !_startsIdentifier(input, pos))
420
- return pos;
421
- pos = _consumeIdentifier(input, pos, callbacks);
422
- let cc = input.charCodeAt(pos);
423
- if (cc === CC_LEFT_PARENTHESIS) {
424
- pos++;
425
- if (callbacks.pseudoFunction !== undefined) {
426
- return callbacks.pseudoFunction(input, start, pos);
427
- }
428
- return pos;
429
- }
430
- if (callbacks.pseudoClass !== undefined) {
431
- return callbacks.pseudoClass(input, start, pos);
432
- }
433
- return pos;
434
- };
435
- /** @type {CharHandler} */
436
- const consumeLeftParenthesis = (input, pos, callbacks) => {
437
- pos++;
438
- if (callbacks.leftParenthesis !== undefined) {
439
- return callbacks.leftParenthesis(input, pos - 1, pos);
440
- }
441
- return pos;
442
- };
443
- /** @type {CharHandler} */
444
- const consumeRightParenthesis = (input, pos, callbacks) => {
445
- pos++;
446
- if (callbacks.rightParenthesis !== undefined) {
447
- return callbacks.rightParenthesis(input, pos - 1, pos);
448
- }
449
- return pos;
450
- };
451
- /** @type {CharHandler} */
452
- const consumeLeftCurlyBracket = (input, pos, callbacks) => {
453
- pos++;
454
- if (callbacks.leftCurlyBracket !== undefined) {
455
- return callbacks.leftCurlyBracket(input, pos - 1, pos);
456
- }
457
- return pos;
458
- };
459
- /** @type {CharHandler} */
460
- const consumeRightCurlyBracket = (input, pos, callbacks) => {
461
- pos++;
462
- if (callbacks.rightCurlyBracket !== undefined) {
463
- return callbacks.rightCurlyBracket(input, pos - 1, pos);
464
- }
465
- return pos;
466
- };
467
- /** @type {CharHandler} */
468
- const consumeSemicolon = (input, pos, callbacks) => {
469
- pos++;
470
- if (callbacks.semicolon !== undefined) {
471
- return callbacks.semicolon(input, pos - 1, pos);
472
- }
473
- return pos;
474
- };
475
- /** @type {CharHandler} */
476
- const consumeComma = (input, pos, callbacks) => {
477
- pos++;
478
- if (callbacks.comma !== undefined) {
479
- return callbacks.comma(input, pos - 1, pos);
480
- }
481
- return pos;
482
- };
483
- /** @type {CharHandler} */
484
- const _consumeIdentifier = (input, pos) => {
485
- for (;;) {
486
- const cc = input.charCodeAt(pos);
487
- if (cc === CC_REVERSE_SOLIDUS) {
488
- pos++;
489
- if (pos === input.length)
490
- return pos;
491
- pos++;
492
- }
493
- else if (_isIdentifierStartCode(cc) ||
494
- _isDigit(cc) ||
495
- cc === CC_HYPHEN_MINUS) {
496
- pos++;
497
- }
498
- else {
499
- return pos;
500
- }
501
- }
502
- };
503
- /** @type {CharHandler} */
504
- const _consumeNumber = (input, pos) => {
505
- pos++;
506
- if (pos === input.length)
507
- return pos;
508
- let cc = input.charCodeAt(pos);
509
- while (_isDigit(cc)) {
510
- pos++;
511
- if (pos === input.length)
512
- return pos;
513
- cc = input.charCodeAt(pos);
514
- }
515
- if (cc === CC_FULL_STOP && pos + 1 !== input.length) {
516
- const next = input.charCodeAt(pos + 1);
517
- if (_isDigit(next)) {
518
- pos += 2;
519
- cc = input.charCodeAt(pos);
520
- while (_isDigit(cc)) {
521
- pos++;
522
- if (pos === input.length)
523
- return pos;
524
- cc = input.charCodeAt(pos);
525
- }
526
- }
527
- }
528
- if (cc === CC_LOWER_E || cc === CC_UPPER_E) {
529
- if (pos + 1 !== input.length) {
530
- const next = input.charCodeAt(pos + 2);
531
- if (_isDigit(next)) {
532
- pos += 2;
533
- }
534
- else if ((next === CC_HYPHEN_MINUS || next === CC_PLUS_SIGN) &&
535
- pos + 2 !== input.length) {
536
- const next = input.charCodeAt(pos + 2);
537
- if (_isDigit(next)) {
538
- pos += 3;
539
- }
540
- else {
541
- return pos;
542
- }
543
- }
544
- else {
545
- return pos;
546
- }
547
- }
548
- }
549
- else {
550
- return pos;
551
- }
552
- cc = input.charCodeAt(pos);
553
- while (_isDigit(cc)) {
554
- pos++;
555
- if (pos === input.length)
556
- return pos;
557
- cc = input.charCodeAt(pos);
558
- }
559
- return pos;
560
- };
561
- /** @type {CharHandler} */
562
- const consumeLessThan = (input, pos, callbacks) => {
563
- if (input.slice(pos + 1, pos + 4) === "!--")
564
- return pos + 4;
565
- return pos + 1;
566
- };
567
- /** @type {CharHandler} */
568
- const consumeAt = (input, pos, callbacks) => {
569
- const start = pos;
570
- pos++;
571
- if (pos === input.length)
572
- return pos;
573
- if (_startsIdentifier(input, pos)) {
574
- pos = _consumeIdentifier(input, pos, callbacks);
575
- if (callbacks.atKeyword !== undefined) {
576
- pos = callbacks.atKeyword(input, start, pos);
577
- }
578
- }
579
- return pos;
580
- };
581
- /** @type {CharHandler} */
582
- const consumeReverseSolidus = (input, pos, callbacks) => {
583
- const start = pos;
584
- pos++;
585
- if (pos === input.length)
586
- return pos;
587
- // If the input stream starts with a valid escape, reconsume the current input code point, consume an ident-like token, and return it.
588
- if (_isTwoCodePointsAreValidEscape(input.charCodeAt(start), input.charCodeAt(pos))) {
589
- return consumeOtherIdentifier(input, pos - 1, callbacks);
590
- }
591
- // Otherwise, this is a parse error. Return a <delim-token> with its value set to the current input code point.
592
- return pos;
593
- };
594
- const CHAR_MAP = Array.from({ length: 0x80 }, (_, cc) => {
595
- // https://drafts.csswg.org/css-syntax/#consume-token
596
- switch (cc) {
597
- // whitespace
598
- case CC_LINE_FEED:
599
- case CC_CARRIAGE_RETURN:
600
- case CC_FORM_FEED:
601
- case CC_TAB:
602
- case CC_SPACE:
603
- return consumeSpace;
604
- // U+0022 QUOTATION MARK (")
605
- case CC_QUOTATION_MARK:
606
- return consumeString(cc);
607
- // U+0023 NUMBER SIGN (#)
608
- case CC_NUMBER_SIGN:
609
- return consumeNumberSign;
610
- // U+0027 APOSTROPHE (')
611
- case CC_APOSTROPHE:
612
- return consumeString(cc);
613
- // U+0028 LEFT PARENTHESIS (()
614
- case CC_LEFT_PARENTHESIS:
615
- return consumeLeftParenthesis;
616
- // U+0029 RIGHT PARENTHESIS ())
617
- case CC_RIGHT_PARENTHESIS:
618
- return consumeRightParenthesis;
619
- // U+002B PLUS SIGN (+)
620
- case CC_PLUS_SIGN:
621
- return consumeNumericToken;
622
- // U+002C COMMA (,)
623
- case CC_COMMA:
624
- return consumeComma;
625
- // U+002D HYPHEN-MINUS (-)
626
- case CC_HYPHEN_MINUS:
627
- return consumeMinus;
628
- // U+002E FULL STOP (.)
629
- case CC_FULL_STOP:
630
- return consumeDot;
631
- // U+003A COLON (:)
632
- case CC_COLON:
633
- return consumePotentialPseudo;
634
- // U+003B SEMICOLON (;)
635
- case CC_SEMICOLON:
636
- return consumeSemicolon;
637
- // U+003C LESS-THAN SIGN (<)
638
- case CC_LESS_THAN_SIGN:
639
- return consumeLessThan;
640
- // U+0040 COMMERCIAL AT (@)
641
- case CC_AT_SIGN:
642
- return consumeAt;
643
- // U+005B LEFT SQUARE BRACKET ([)
644
- case CC_LEFT_SQUARE:
645
- return consumeDelimToken;
646
- // U+005C REVERSE SOLIDUS (\)
647
- case CC_REVERSE_SOLIDUS:
648
- return consumeReverseSolidus;
649
- // U+005D RIGHT SQUARE BRACKET (])
650
- case CC_RIGHT_SQUARE:
651
- return consumeDelimToken;
652
- // U+007B LEFT CURLY BRACKET ({)
653
- case CC_LEFT_CURLY:
654
- return consumeLeftCurlyBracket;
655
- // U+007D RIGHT CURLY BRACKET (})
656
- case CC_RIGHT_CURLY:
657
- return consumeRightCurlyBracket;
658
- // Optimization
659
- case CC_LOWER_U:
660
- case CC_UPPER_U:
661
- return consumePotentialUrl;
662
- default:
663
- // digit
664
- if (_isDigit(cc))
665
- return consumeNumericToken;
666
- // ident-start code point
667
- if (isIdentStartCodePoint(cc)) {
668
- return consumeOtherIdentifier;
669
- }
670
- // EOF, but we don't have it
671
- // anything else
672
- return consumeDelimToken;
673
- }
674
- });
675
- /**
676
- * @param {string} input input css
677
- * @param {CssTokenCallbacks} callbacks callbacks
678
- * @returns {void}
679
- */
680
- module.exports = (input, callbacks) => {
681
- // This section describes how to consume a token from a stream of code points. It will return a single token of any type.
682
- let pos = 0;
683
- while (pos < input.length) {
684
- // Consume comments.
685
- pos = consumeComments(input, pos, callbacks);
686
- const cc = input.charCodeAt(pos);
687
- // Consume the next input code point.
688
- if (cc < 0x80) {
689
- pos = CHAR_MAP[cc](input, pos, callbacks);
690
- }
691
- else {
692
- pos++;
693
- }
694
- }
695
- };
696
- module.exports.isIdentStartCodePoint = isIdentStartCodePoint;
697
- /**
698
- * @param {string} input input
699
- * @param {number} pos position
700
- * @returns {number} position after comments
701
- */
702
- module.exports.eatComments = (input, pos) => {
703
- for (;;) {
704
- let originalPos = pos;
705
- pos = consumeComments(input, pos, {});
706
- if (originalPos === pos) {
707
- break;
708
- }
709
- }
710
- return pos;
711
- };
712
- /**
713
- * @param {string} input input
714
- * @param {number} pos position
715
- * @returns {number} position after whitespace
716
- */
717
- module.exports.eatWhitespace = (input, pos) => {
718
- while (_isWhiteSpace(input.charCodeAt(pos))) {
719
- pos++;
720
- }
721
- return pos;
722
- };
723
- /**
724
- * @param {string} input input
725
- * @param {number} pos position
726
- * @returns {number} position after whitespace and comments
727
- */
728
- module.exports.eatWhitespaceAndComments = (input, pos) => {
729
- for (;;) {
730
- let originalPos = pos;
731
- pos = consumeComments(input, pos, {});
732
- while (_isWhiteSpace(input.charCodeAt(pos))) {
733
- pos++;
734
- }
735
- if (originalPos === pos) {
736
- break;
737
- }
738
- }
739
- return pos;
740
- };
741
- /**
742
- * @param {string} input input
743
- * @param {number} pos position
744
- * @returns {number} position after whitespace
745
- */
746
- module.exports.eatWhiteLine = (input, pos) => {
747
- for (;;) {
748
- const cc = input.charCodeAt(pos);
749
- if (_isSpace(cc)) {
750
- pos++;
751
- continue;
752
- }
753
- if (_isNewLine(cc))
754
- pos++;
755
- // For `\r\n`
756
- if (cc === CC_CARRIAGE_RETURN && input.charCodeAt(pos + 1) === CC_LINE_FEED)
757
- pos++;
758
- break;
759
- }
760
- return pos;
761
- };