@tbela99/css-parser 1.4.11 → 1.5.0
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/CHANGELOG.md +6 -0
- package/README.md +11 -4
- package/dist/index-umd-web.js +2116 -1699
- package/dist/index.cjs +2128 -1694
- package/dist/index.d.ts +781 -269
- package/dist/lib/ast/clone.js +13 -8
- package/dist/lib/ast/expand.js +45 -9
- package/dist/lib/ast/features/calc.js +2 -1
- package/dist/lib/ast/features/if.js +24 -4
- package/dist/lib/ast/features/prefix.js +13 -31
- package/dist/lib/ast/features/shorthand.js +1 -1
- package/dist/lib/ast/features/transform.js +5 -2
- package/dist/lib/ast/find.js +7 -5
- package/dist/lib/ast/minify.js +80 -35
- package/dist/lib/ast/node.js +50 -0
- package/dist/lib/ast/types.js +1 -1
- package/dist/lib/ast/walk.js +27 -7
- package/dist/lib/fs/resolve.js +60 -28
- package/dist/lib/parser/declaration/map.js +14 -5
- package/dist/lib/parser/linesmap.js +5 -13
- package/dist/lib/parser/parse.js +489 -719
- package/dist/lib/parser/source.js +16 -2
- package/dist/lib/parser/tokenize.js +382 -278
- package/dist/lib/parser/utils/at-rule-container.js +2 -1
- package/dist/lib/parser/utils/selector.js +88 -10
- package/dist/lib/renderer/render.js +174 -99
- package/dist/lib/renderer/sourcemap/lib/codec.js +78 -0
- package/dist/lib/renderer/sourcemap/sourcemap.js +190 -34
- package/dist/lib/syntax/syntax.js +14 -151
- package/dist/lib/validation/match.js +81 -1
- package/dist/node.js +41 -26
- package/dist/utils/sync.d.ts +16 -0
- package/dist/utils/sync.js +52 -0
- package/dist/web.js +26 -28
- package/llms.txt +12 -5
- package/package.json +1 -1
- package/dist/lib/renderer/sourcemap/lib/encode.js +0 -37
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EnumToken, ColorType } from '../ast/types.js';
|
|
2
2
|
import { LOC, wildCardFuncs, whenElseFunc, transformFunctions, mathFuncs, colorsFunc, timingFunc, supportFunc, timelineFunc, imageFunc, gridTemplateFunc, urlFunc, containerFunc, pseudoElements } from '../syntax/constants.js';
|
|
3
|
-
import { isDigit,
|
|
3
|
+
import { isDigit, isWhiteSpace, isIdent, isHexColor, isHash, isNumber, isPercentage, parseDimension, isNewLine, isIdentStart, isIdentCodepoint, isNonPrintable } from '../syntax/syntax.js';
|
|
4
4
|
import { SourceFile } from './source.js';
|
|
5
5
|
import { equalsIgnoreCase } from './utils/text.js';
|
|
6
6
|
|
|
@@ -136,17 +136,17 @@ var TokenMap;
|
|
|
136
136
|
TokenMap[TokenMap["GREATERTHAN"] = 62] = "GREATERTHAN";
|
|
137
137
|
})(TokenMap || (TokenMap = {}));
|
|
138
138
|
function consumeString(parseInfo) {
|
|
139
|
-
const quote = next(parseInfo);
|
|
140
|
-
let
|
|
141
|
-
let
|
|
139
|
+
const quote = next(parseInfo).charCodeAt(0);
|
|
140
|
+
let charCode;
|
|
141
|
+
let decodeSegments = false;
|
|
142
142
|
const result = [];
|
|
143
|
-
while ((
|
|
144
|
-
if (
|
|
145
|
-
if (
|
|
146
|
-
|
|
143
|
+
while ((charCode = parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset)) == charCode) {
|
|
144
|
+
if (charCode == 92 /* TokenMap.REVERSE_SOLIDUS */) {
|
|
145
|
+
if (charCode == parseInfo.stream.charCodeAt(parseInfo.currentPosition - parseInfo.offset + 1)) {
|
|
146
|
+
next(parseInfo, 2);
|
|
147
147
|
continue;
|
|
148
148
|
}
|
|
149
|
-
const sequence = peek(parseInfo,
|
|
149
|
+
const sequence = peek(parseInfo, 7);
|
|
150
150
|
let escapeSequence = "";
|
|
151
151
|
let codepoint;
|
|
152
152
|
let i;
|
|
@@ -165,50 +165,66 @@ function consumeString(parseInfo) {
|
|
|
165
165
|
break;
|
|
166
166
|
}
|
|
167
167
|
if (escapeSequence.trimEnd().length > 0) {
|
|
168
|
-
const codepoint = parseInt(escapeSequence, 16);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
|
|
168
|
+
// const codepoint = parseInt(escapeSequence, 16);
|
|
169
|
+
// TODO set decode flag ON
|
|
170
|
+
// if (
|
|
171
|
+
// codepoint == 0 ||
|
|
172
|
+
// // leading surrogate
|
|
173
|
+
// (0xd800 <= codepoint && codepoint <= 0xdbff) ||
|
|
174
|
+
// // trailing surrogate
|
|
175
|
+
// (0xdc00 <= codepoint && codepoint <= 0xdfff)
|
|
176
|
+
// ) {
|
|
177
|
+
// buffer += String.fromCodePoint(0xfffd);
|
|
178
|
+
// } else {
|
|
179
|
+
// buffer += String.fromCodePoint(codepoint);
|
|
180
|
+
// }
|
|
181
|
+
const length = escapeSequence.length +
|
|
180
182
|
1 +
|
|
181
|
-
(isWhiteSpace(parseInfo.stream.charAt(parseInfo.currentPosition - parseInfo.offset
|
|
183
|
+
(isWhiteSpace(parseInfo.stream.charAt(parseInfo.currentPosition - parseInfo.offset)?.charCodeAt(0))
|
|
182
184
|
? 1
|
|
183
|
-
: 0)
|
|
185
|
+
: 0);
|
|
186
|
+
decodeSegments = true;
|
|
187
|
+
next(parseInfo, length);
|
|
184
188
|
continue;
|
|
185
189
|
}
|
|
186
|
-
|
|
190
|
+
next(parseInfo, 2);
|
|
187
191
|
continue;
|
|
188
192
|
}
|
|
189
|
-
if (
|
|
190
|
-
buffer += value;
|
|
191
|
-
result.push(yieldResult(buffer, parseInfo,
|
|
192
|
-
/* hasNewLine ? EnumToken.BadStringTokenType : */ EnumToken.StringTokenType));
|
|
193
|
+
if (charCode == quote) {
|
|
193
194
|
next(parseInfo);
|
|
194
|
-
|
|
195
|
+
result.push(yieldResult(parseInfo,
|
|
196
|
+
/* hasNewLine ? EnumToken.BadStringTokenType : */ EnumToken.StringTokenType, decodeSegments ? { decodeSegments } : null));
|
|
195
197
|
return result;
|
|
196
198
|
}
|
|
197
|
-
if (isNewLine(
|
|
198
|
-
|
|
199
|
+
if (isNewLine(charCode)) {
|
|
200
|
+
next(parseInfo);
|
|
201
|
+
result.push(yieldResult(parseInfo, EnumToken.BadStringTokenType));
|
|
199
202
|
return result;
|
|
200
203
|
}
|
|
201
|
-
buffer += value;
|
|
202
204
|
next(parseInfo);
|
|
203
205
|
}
|
|
204
206
|
// EOF - 'Unclosed-string' fixed
|
|
205
|
-
result.push(yieldResult(
|
|
207
|
+
result.push(yieldResult(parseInfo, EnumToken.StringTokenType));
|
|
206
208
|
return result;
|
|
207
209
|
}
|
|
208
|
-
function yieldResult(
|
|
210
|
+
function yieldResult(parseInfo, hint, options) {
|
|
211
|
+
let val = parseInfo.stream.slice(parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset);
|
|
209
212
|
let token = null;
|
|
210
213
|
let dimension;
|
|
211
|
-
|
|
214
|
+
if (options?.decodeSegments) {
|
|
215
|
+
val = val.replace(/\\([0-9a-fA-F]{1,6})(?:\s)?/g, (_, sequence) => {
|
|
216
|
+
const codepoint = parseInt(sequence, 16);
|
|
217
|
+
if (codepoint == 0 ||
|
|
218
|
+
// leading surrogate
|
|
219
|
+
(0xd800 <= codepoint && codepoint <= 0xdbff) ||
|
|
220
|
+
// trailing surrogate
|
|
221
|
+
(0xdc00 <= codepoint && codepoint <= 0xdfff) ||
|
|
222
|
+
codepoint > 0x10ffff) {
|
|
223
|
+
return "\uFFFD";
|
|
224
|
+
}
|
|
225
|
+
return String.fromCodePoint(codepoint);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
212
228
|
if (hint != null) {
|
|
213
229
|
let searchArray = null;
|
|
214
230
|
switch (hint) {
|
|
@@ -260,7 +276,12 @@ function yieldResult(val, parseInfo, hint) {
|
|
|
260
276
|
else {
|
|
261
277
|
let slice = val.slice(1);
|
|
262
278
|
const chr = val.charAt(0);
|
|
263
|
-
if (chr == "
|
|
279
|
+
if (chr == "!" && equalsIgnoreCase("!important", val)) {
|
|
280
|
+
token = {
|
|
281
|
+
typ: EnumToken.ImportantTokenType,
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
else if (chr == "@" && isIdent(slice)) {
|
|
264
285
|
token = {
|
|
265
286
|
typ: EnumToken.AtRuleTokenType,
|
|
266
287
|
nam: slice,
|
|
@@ -335,12 +356,12 @@ function yieldResult(val, parseInfo, hint) {
|
|
|
335
356
|
end: parseInfo.currentPosition,
|
|
336
357
|
};
|
|
337
358
|
parseInfo.position = parseInfo.currentPosition;
|
|
338
|
-
return { token, bytesIn: parseInfo.currentPosition
|
|
359
|
+
return { token, bytesIn: parseInfo.currentPosition };
|
|
339
360
|
}
|
|
340
361
|
function match(parseInfo, input) {
|
|
341
362
|
let position = parseInfo.currentPosition - parseInfo.offset;
|
|
342
363
|
for (let i = 0; i < input.length; i++) {
|
|
343
|
-
if (parseInfo.stream[position + i
|
|
364
|
+
if (parseInfo.stream[position + i] != input.charAt(i)) {
|
|
344
365
|
return false;
|
|
345
366
|
}
|
|
346
367
|
}
|
|
@@ -348,14 +369,14 @@ function match(parseInfo, input) {
|
|
|
348
369
|
}
|
|
349
370
|
function peek(parseInfo, count = 1) {
|
|
350
371
|
if (count == 1) {
|
|
351
|
-
return parseInfo.stream.charAt(parseInfo.currentPosition - parseInfo.offset
|
|
372
|
+
return parseInfo.stream.charAt(parseInfo.currentPosition - parseInfo.offset);
|
|
352
373
|
}
|
|
353
374
|
const position = parseInfo.currentPosition - parseInfo.offset;
|
|
354
|
-
return parseInfo.stream.slice(position
|
|
375
|
+
return parseInfo.stream.slice(position, position + count);
|
|
355
376
|
}
|
|
356
377
|
function next(parseInfo, count = 1) {
|
|
357
378
|
let position = parseInfo.currentPosition - parseInfo.offset;
|
|
358
|
-
let char = count == 1 ? parseInfo.stream.charAt(position
|
|
379
|
+
let char = count == 1 ? parseInfo.stream.charAt(position) : parseInfo.stream.slice(position, position + count);
|
|
359
380
|
let i = 0;
|
|
360
381
|
let codepoint;
|
|
361
382
|
for (; i < char.length; i++) {
|
|
@@ -377,195 +398,292 @@ function next(parseInfo, count = 1) {
|
|
|
377
398
|
parseInfo.currentPosition += char.length;
|
|
378
399
|
return char;
|
|
379
400
|
}
|
|
401
|
+
function isIdentToken(parseInfo, start, end) {
|
|
402
|
+
let j = parseInfo.currentPosition - parseInfo.offset;
|
|
403
|
+
let i = parseInfo.position - parseInfo.offset;
|
|
404
|
+
if (start != null) {
|
|
405
|
+
if (end == null) {
|
|
406
|
+
if (start < 0) {
|
|
407
|
+
j += start;
|
|
408
|
+
}
|
|
409
|
+
else {
|
|
410
|
+
i += start;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
if (end < 0) {
|
|
415
|
+
j += end;
|
|
416
|
+
}
|
|
417
|
+
else {
|
|
418
|
+
j = parseInfo.position + end;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
j--;
|
|
423
|
+
let codepoint = parseInfo.stream.charCodeAt(i);
|
|
424
|
+
// -
|
|
425
|
+
if (codepoint == 0x2d) {
|
|
426
|
+
let nextCodepoint;
|
|
427
|
+
if ((nextCodepoint = parseInfo.stream.charCodeAt(i + 1)) != nextCodepoint) {
|
|
428
|
+
return false;
|
|
429
|
+
}
|
|
430
|
+
if (isDigit(nextCodepoint)) {
|
|
431
|
+
return false;
|
|
432
|
+
}
|
|
433
|
+
codepoint = nextCodepoint;
|
|
434
|
+
i++;
|
|
435
|
+
}
|
|
436
|
+
if (codepoint !== 0x2d && !isIdentStart(codepoint)) {
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
if (codepoint == 92 /* TokenMap.REVERSE_SOLIDUS */) {
|
|
440
|
+
codepoint = parseInfo.stream.charCodeAt(i + 1);
|
|
441
|
+
// if (!isIdentCodepoint(codepoint)) {
|
|
442
|
+
// return false;
|
|
443
|
+
// }
|
|
444
|
+
i += String.fromCodePoint(codepoint).length;
|
|
445
|
+
// if (i < j) {
|
|
446
|
+
// codepoint = name.charCodeAt(i) as number;
|
|
447
|
+
// if (!isIdentCodepoint(codepoint)) {
|
|
448
|
+
// return false;
|
|
449
|
+
// }
|
|
450
|
+
// }
|
|
451
|
+
}
|
|
452
|
+
while (i < j) {
|
|
453
|
+
i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
|
|
454
|
+
codepoint = parseInfo.stream.charCodeAt(i);
|
|
455
|
+
if (codepoint == 92 /* TokenMap.REVERSE_SOLIDUS */) {
|
|
456
|
+
i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
|
|
457
|
+
codepoint = parseInfo.stream.charCodeAt(i);
|
|
458
|
+
i += codepoint < 0x80 ? 1 : String.fromCodePoint(codepoint).length;
|
|
459
|
+
continue;
|
|
460
|
+
}
|
|
461
|
+
if (codepoint !== 0x2d && !isIdentCodepoint(codepoint)) {
|
|
462
|
+
return false;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
function isPseudo(parseInfo) {
|
|
468
|
+
let position = parseInfo.currentPosition - parseInfo.offset;
|
|
469
|
+
let endPosition = parseInfo.currentPosition - parseInfo.offset;
|
|
470
|
+
return (parseInfo.stream.charAt(position) == ":" &&
|
|
471
|
+
parseInfo.stream.charAt(endPosition - 1) == "(" &&
|
|
472
|
+
(parseInfo.stream.charAt(position + 1) == ":"
|
|
473
|
+
? isIdentToken(parseInfo, 2, -1)
|
|
474
|
+
: isIdentToken(parseInfo, 1, -1))) ||
|
|
475
|
+
parseInfo.stream.charAt(position + 1) == ":"
|
|
476
|
+
? isIdentToken(parseInfo, 2)
|
|
477
|
+
: isIdentToken(parseInfo, 1);
|
|
478
|
+
}
|
|
479
|
+
function startsWith(parseInfo, input) {
|
|
480
|
+
let i = 0;
|
|
481
|
+
let j = input.length;
|
|
482
|
+
while (i < j) {
|
|
483
|
+
if (parseInfo.stream.charAt(parseInfo.position - parseInfo.offset + i) != input.charAt(i)) {
|
|
484
|
+
return false;
|
|
485
|
+
}
|
|
486
|
+
i++;
|
|
487
|
+
}
|
|
488
|
+
return true;
|
|
489
|
+
}
|
|
490
|
+
function isURLToken(parseInfo) {
|
|
491
|
+
let i = parseInfo.position - parseInfo.offset;
|
|
492
|
+
let c;
|
|
493
|
+
while (++i < parseInfo.currentPosition) {
|
|
494
|
+
c = parseInfo.stream.charCodeAt(i);
|
|
495
|
+
// single quote or double quote or start parenthesis or close parenthesis
|
|
496
|
+
if (isNonPrintable(c) || c == 0x27 || c == 0x22 || c == 0x28 || c == 0x29) {
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
// valid escape
|
|
500
|
+
if (c == 92 /* TokenMap.REVERSE_SOLIDUS */) {
|
|
501
|
+
i++;
|
|
502
|
+
if (i >= parseInfo.currentPosition) {
|
|
503
|
+
return false;
|
|
504
|
+
}
|
|
505
|
+
c = parseInfo.stream.charCodeAt(i);
|
|
506
|
+
// c is not '\n' or '\r' or '\f'
|
|
507
|
+
if (c == 0x6e || c == 0x72 || c == 0x66) {
|
|
508
|
+
return false;
|
|
509
|
+
}
|
|
510
|
+
continue;
|
|
511
|
+
}
|
|
512
|
+
// is white space
|
|
513
|
+
if (c == 0x20 || c == 0x09) {
|
|
514
|
+
break;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
return i == parseInfo.currentPosition;
|
|
518
|
+
}
|
|
380
519
|
/**
|
|
381
|
-
* Tokenize
|
|
520
|
+
* Tokenize CSS string
|
|
382
521
|
* @param parseInfo
|
|
383
522
|
* @param yieldEOFToken
|
|
384
523
|
*/
|
|
385
524
|
function tokenize(parseInfo, yieldEOFToken = true) {
|
|
386
525
|
if (typeof parseInfo == "string") {
|
|
387
526
|
parseInfo = {
|
|
388
|
-
buffer: "",
|
|
389
527
|
stream: parseInfo,
|
|
390
528
|
source: new SourceFile(parseInfo, [], ""),
|
|
391
529
|
offset: 0,
|
|
392
530
|
time: 0,
|
|
393
531
|
position: 0,
|
|
394
|
-
currentPosition:
|
|
532
|
+
currentPosition: 0,
|
|
395
533
|
};
|
|
396
534
|
}
|
|
397
|
-
let value;
|
|
398
|
-
let buffer = parseInfo.buffer;
|
|
399
535
|
let charCode;
|
|
400
536
|
let nextCharCode;
|
|
401
537
|
const startTime = performance.now();
|
|
402
538
|
const result = [];
|
|
403
539
|
// allow 10 characters buffer for the streaming parser to avoid incomplete tokens
|
|
404
|
-
const endPosition = parseInfo.stream.length -
|
|
405
|
-
|
|
406
|
-
while ((
|
|
407
|
-
charCode = value.charCodeAt(0);
|
|
408
|
-
// nextCharCode = nextValue.charCodeAt(0);
|
|
409
|
-
// console.debug({value, buffer});
|
|
540
|
+
const endPosition = parseInfo.stream.length - 1;
|
|
541
|
+
// NaN is not equal to NaN
|
|
542
|
+
while ((charCode = peek(parseInfo).charCodeAt(0)) == charCode) {
|
|
410
543
|
switch (charCode) {
|
|
411
544
|
case 61 /* TokenMap.EQUALS */:
|
|
412
|
-
if (
|
|
413
|
-
result.push(yieldResult(
|
|
414
|
-
buffer = "";
|
|
545
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
546
|
+
result.push(yieldResult(parseInfo));
|
|
415
547
|
}
|
|
416
|
-
|
|
548
|
+
next(parseInfo);
|
|
549
|
+
result.push(yieldResult(parseInfo, EnumToken.DelimTokenType));
|
|
417
550
|
break;
|
|
418
551
|
// '+' or '-'
|
|
419
552
|
case 43 /* TokenMap.PLUS */:
|
|
420
553
|
case 45 /* TokenMap.MINUS */:
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
554
|
+
nextCharCode = peek(parseInfo).charCodeAt(0);
|
|
555
|
+
// not a number
|
|
556
|
+
if (charCode === 43 /* TokenMap.PLUS */ && !(nextCharCode >= 0x30 && nextCharCode <= 0x39)) {
|
|
557
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
558
|
+
result.push(yieldResult(parseInfo));
|
|
426
559
|
}
|
|
427
|
-
|
|
560
|
+
next(parseInfo);
|
|
561
|
+
result.push(yieldResult(parseInfo, SymbolsMapTokens[parseInfo.stream
|
|
562
|
+
.slice(parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset)
|
|
563
|
+
.toLowerCase()]));
|
|
428
564
|
break;
|
|
429
565
|
}
|
|
430
|
-
|
|
566
|
+
next(parseInfo);
|
|
431
567
|
break;
|
|
432
568
|
// '{'
|
|
433
569
|
case 123 /* TokenMap.LEFT_BRACE */:
|
|
434
|
-
if (
|
|
435
|
-
result.push(yieldResult(
|
|
436
|
-
buffer = "";
|
|
570
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
571
|
+
result.push(yieldResult(parseInfo));
|
|
437
572
|
}
|
|
438
|
-
|
|
573
|
+
next(parseInfo);
|
|
574
|
+
result.push(yieldResult(parseInfo, EnumToken.BlockStartTokenType));
|
|
439
575
|
break;
|
|
440
576
|
// '}'
|
|
441
577
|
case 125 /* TokenMap.RIGHT_BRACE */:
|
|
442
|
-
if (
|
|
443
|
-
result.push(yieldResult(
|
|
444
|
-
buffer = "";
|
|
578
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
579
|
+
result.push(yieldResult(parseInfo));
|
|
445
580
|
}
|
|
446
|
-
|
|
581
|
+
next(parseInfo);
|
|
582
|
+
result.push(yieldResult(parseInfo, EnumToken.BlockEndTokenType));
|
|
447
583
|
break;
|
|
448
584
|
// '('
|
|
449
585
|
case 40 /* TokenMap.LEFT_PARENTHESIS */:
|
|
450
|
-
if (
|
|
451
|
-
if (
|
|
586
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
587
|
+
if (parseInfo.stream[parseInfo.position - parseInfo.offset] === ":" && isPseudo(parseInfo)) {
|
|
452
588
|
next(parseInfo);
|
|
453
|
-
result.push(yieldResult(
|
|
454
|
-
buffer = "";
|
|
589
|
+
result.push(yieldResult(parseInfo, EnumToken.PseudoClassFunctionTokenDefType));
|
|
455
590
|
break;
|
|
456
591
|
}
|
|
457
|
-
else if (
|
|
458
|
-
const hint =
|
|
592
|
+
else if (isIdentToken(parseInfo)) {
|
|
593
|
+
const hint = startsWith(parseInfo, "--")
|
|
459
594
|
? EnumToken.CustomFunctionTokenDefType
|
|
460
|
-
: (SymbolsMapTokens[
|
|
461
|
-
|
|
595
|
+
: (SymbolsMapTokens[parseInfo.stream
|
|
596
|
+
.slice(parseInfo.position - parseInfo.offset, parseInfo.currentPosition - parseInfo.offset)
|
|
597
|
+
.toLowerCase() + "("] ?? EnumToken.FunctionTokenDefType);
|
|
598
|
+
result.push(yieldResult(parseInfo, hint));
|
|
462
599
|
next(parseInfo);
|
|
463
|
-
|
|
600
|
+
// consume '('
|
|
601
|
+
parseInfo.position = parseInfo.currentPosition;
|
|
464
602
|
if (hint === EnumToken.UrlFunctionTokenDefType) {
|
|
465
|
-
buffer = "";
|
|
466
|
-
value = peek(parseInfo);
|
|
467
603
|
// consume an <url>
|
|
468
|
-
while (isWhiteSpace((
|
|
469
|
-
|
|
470
|
-
value = peek(parseInfo);
|
|
471
|
-
charCode = value.charCodeAt(0);
|
|
472
|
-
if (value === "/" && match(parseInfo, "/*")) {
|
|
473
|
-
if (buffer.length > 0) {
|
|
474
|
-
result.push(yieldResult(buffer, parseInfo));
|
|
475
|
-
buffer = "";
|
|
476
|
-
}
|
|
477
|
-
buffer += next(parseInfo, 2);
|
|
478
|
-
while ((value = next(parseInfo))) {
|
|
479
|
-
if (value == "*") {
|
|
480
|
-
buffer += value;
|
|
481
|
-
if (match(parseInfo, "/")) {
|
|
482
|
-
result.push(yieldResult(buffer + next(parseInfo), parseInfo, EnumToken.CommentTokenType));
|
|
483
|
-
buffer = "";
|
|
484
|
-
break;
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
else {
|
|
488
|
-
buffer += value;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
if (buffer.length > 0) {
|
|
492
|
-
result.push(yieldResult(buffer, parseInfo, EnumToken.BadCommentTokenType));
|
|
493
|
-
buffer = "";
|
|
494
|
-
}
|
|
495
|
-
value = peek(parseInfo);
|
|
496
|
-
charCode = value.charCodeAt(0);
|
|
497
|
-
}
|
|
604
|
+
while (isWhiteSpace(peek(parseInfo).charCodeAt(0))) {
|
|
605
|
+
next(parseInfo);
|
|
498
606
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
607
|
+
charCode = peek(parseInfo).charCodeAt(0);
|
|
608
|
+
let values = null;
|
|
609
|
+
if (charCode == 34 /* TokenMap.DOUBLE_QUOTE */ || charCode == 39 /* TokenMap.SINGLE_QUOTE */) {
|
|
610
|
+
values = consumeString(parseInfo);
|
|
502
611
|
}
|
|
503
|
-
|
|
504
|
-
|
|
612
|
+
else {
|
|
613
|
+
do {
|
|
614
|
+
next(parseInfo);
|
|
615
|
+
// value = peek(parseInfo);
|
|
616
|
+
charCode = peek(parseInfo).charCodeAt(0);
|
|
617
|
+
} while (
|
|
618
|
+
// !(value === "/" && match(parseInfo, "/*") &&
|
|
619
|
+
charCode !== 41 /* TokenMap.RIGHT_PARENTHESIS */ &&
|
|
620
|
+
parseInfo.currentPosition < endPosition);
|
|
505
621
|
}
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
622
|
+
if (values != null) {
|
|
623
|
+
// NaN is not equal to NaN
|
|
624
|
+
if ((charCode = peek(parseInfo).charCodeAt(0)) != charCode) {
|
|
625
|
+
for (let i = 0; i < values.length; i++) {
|
|
626
|
+
values[i].token.typ = EnumToken.BadUrlTokenType;
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
result.push(...values);
|
|
630
|
+
}
|
|
631
|
+
else if (parseInfo.position < parseInfo.currentPosition) {
|
|
632
|
+
result.push(yieldResult(parseInfo,
|
|
633
|
+
// parseInfo.position < parseInfo.currentPosition
|
|
634
|
+
(charCode = peek(parseInfo).charCodeAt(0)) != charCode || !isURLToken(parseInfo)
|
|
515
635
|
? EnumToken.BadUrlTokenType
|
|
516
636
|
: EnumToken.UrlTokenTokenType));
|
|
517
|
-
buffer = "";
|
|
518
637
|
}
|
|
519
638
|
}
|
|
520
|
-
// console.debug({value: peek(parseInfo)});
|
|
521
639
|
break;
|
|
522
640
|
}
|
|
523
641
|
}
|
|
524
|
-
|
|
525
|
-
|
|
642
|
+
next(parseInfo);
|
|
643
|
+
result.push(yieldResult(parseInfo, EnumToken.StartParensTokenType));
|
|
526
644
|
break;
|
|
527
645
|
// ')'
|
|
528
646
|
case 41 /* TokenMap.RIGHT_PARENTHESIS */:
|
|
529
|
-
if (
|
|
530
|
-
result.push(yieldResult(
|
|
531
|
-
buffer = "";
|
|
647
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
648
|
+
result.push(yieldResult(parseInfo));
|
|
532
649
|
}
|
|
533
|
-
|
|
650
|
+
next(parseInfo);
|
|
651
|
+
result.push(yieldResult(parseInfo, EnumToken.EndParensTokenType));
|
|
534
652
|
break;
|
|
535
653
|
// '['
|
|
536
654
|
case 91 /* TokenMap.LEFT_BRACKETS */:
|
|
537
|
-
if (
|
|
538
|
-
result.push(yieldResult(
|
|
539
|
-
buffer = "";
|
|
655
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
656
|
+
result.push(yieldResult(parseInfo));
|
|
540
657
|
}
|
|
541
|
-
|
|
658
|
+
next(parseInfo);
|
|
659
|
+
result.push(yieldResult(parseInfo, EnumToken.AttrStartTokenType));
|
|
542
660
|
break;
|
|
543
661
|
// ']'
|
|
544
662
|
case 93 /* TokenMap.RIGHT_BRACKETS */:
|
|
545
|
-
if (
|
|
546
|
-
result.push(yieldResult(
|
|
547
|
-
buffer = "";
|
|
663
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
664
|
+
result.push(yieldResult(parseInfo));
|
|
548
665
|
}
|
|
549
|
-
|
|
666
|
+
next(parseInfo);
|
|
667
|
+
result.push(yieldResult(parseInfo, EnumToken.AttrEndTokenType));
|
|
550
668
|
break;
|
|
551
669
|
case 59 /* TokenMap.SEMICOLON */:
|
|
552
|
-
if (
|
|
553
|
-
result.push(yieldResult(
|
|
554
|
-
buffer = "";
|
|
670
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
671
|
+
result.push(yieldResult(parseInfo));
|
|
555
672
|
}
|
|
556
|
-
|
|
673
|
+
next(parseInfo);
|
|
674
|
+
result.push(yieldResult(parseInfo, EnumToken.SemiColonTokenType));
|
|
557
675
|
break;
|
|
558
676
|
case 58 /* TokenMap.COLON */:
|
|
559
|
-
if (
|
|
560
|
-
result.push(yieldResult(
|
|
561
|
-
buffer = "";
|
|
677
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
678
|
+
result.push(yieldResult(parseInfo));
|
|
562
679
|
}
|
|
563
680
|
next(parseInfo);
|
|
564
681
|
if (peek(parseInfo).charCodeAt(0) == 58 /* TokenMap.COLON */) {
|
|
565
|
-
|
|
682
|
+
next(parseInfo);
|
|
683
|
+
result.push(yieldResult(parseInfo, EnumToken.DoubleColonTokenType));
|
|
566
684
|
break;
|
|
567
685
|
}
|
|
568
|
-
result.push(yieldResult(
|
|
686
|
+
result.push(yieldResult(parseInfo, EnumToken.ColonTokenType));
|
|
569
687
|
break;
|
|
570
688
|
// \n \r \f \v \t space
|
|
571
689
|
case 0x9:
|
|
@@ -576,241 +694,229 @@ function tokenize(parseInfo, yieldEOFToken = true) {
|
|
|
576
694
|
case 0xd:
|
|
577
695
|
case 0x2028:
|
|
578
696
|
case 0x2029:
|
|
579
|
-
if (
|
|
580
|
-
result.push(yieldResult(
|
|
581
|
-
buffer = "";
|
|
697
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
698
|
+
result.push(yieldResult(parseInfo));
|
|
582
699
|
}
|
|
583
|
-
|
|
584
|
-
nextCharCode = parseInfo.stream.charAt(parseInfo.currentPosition - parseInfo.offset
|
|
700
|
+
next(parseInfo);
|
|
701
|
+
nextCharCode = parseInfo.stream.charAt(parseInfo.currentPosition - parseInfo.offset).charCodeAt(0);
|
|
585
702
|
while (nextCharCode == 0x20 ||
|
|
586
703
|
(nextCharCode >= 0x9 && nextCharCode <= 0xd) ||
|
|
587
704
|
nextCharCode == 0x2028 ||
|
|
588
705
|
nextCharCode == 0x2029) {
|
|
589
|
-
|
|
590
|
-
nextCharCode = parseInfo.stream
|
|
591
|
-
.charAt(parseInfo.currentPosition - parseInfo.offset + 1)
|
|
592
|
-
.charCodeAt(0);
|
|
706
|
+
next(parseInfo);
|
|
707
|
+
nextCharCode = parseInfo.stream.charAt(parseInfo.currentPosition - parseInfo.offset).charCodeAt(0);
|
|
593
708
|
}
|
|
594
|
-
result.push(yieldResult(
|
|
595
|
-
buffer = "";
|
|
709
|
+
result.push(yieldResult(parseInfo, EnumToken.WhitespaceTokenType));
|
|
596
710
|
break;
|
|
597
711
|
case 44 /* TokenMap.COMMA */:
|
|
598
|
-
if (
|
|
599
|
-
result.push(yieldResult(
|
|
600
|
-
buffer = "";
|
|
712
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
713
|
+
result.push(yieldResult(parseInfo));
|
|
601
714
|
}
|
|
602
|
-
|
|
715
|
+
next(parseInfo);
|
|
716
|
+
result.push(yieldResult(parseInfo, EnumToken.CommaTokenType));
|
|
603
717
|
break;
|
|
604
718
|
case 36 /* TokenMap.DOLLAR */:
|
|
605
|
-
if (
|
|
606
|
-
result.push(yieldResult(
|
|
607
|
-
buffer = "";
|
|
719
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
720
|
+
result.push(yieldResult(parseInfo));
|
|
608
721
|
}
|
|
609
722
|
if (match(parseInfo, "$=")) {
|
|
610
|
-
|
|
723
|
+
next(parseInfo, 2);
|
|
724
|
+
result.push(yieldResult(parseInfo, EnumToken.EndMatchTokenType));
|
|
611
725
|
break;
|
|
612
726
|
}
|
|
613
|
-
|
|
727
|
+
next(parseInfo);
|
|
614
728
|
break;
|
|
615
729
|
case 126 /* TokenMap.TILDA */:
|
|
616
|
-
if (
|
|
617
|
-
result.push(yieldResult(
|
|
618
|
-
buffer = "";
|
|
730
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
731
|
+
result.push(yieldResult(parseInfo));
|
|
619
732
|
}
|
|
620
733
|
if (match(parseInfo, "~=")) {
|
|
621
|
-
|
|
734
|
+
next(parseInfo, 2);
|
|
735
|
+
result.push(yieldResult(parseInfo, EnumToken.IncludeMatchTokenType));
|
|
622
736
|
break;
|
|
623
737
|
}
|
|
624
|
-
|
|
625
|
-
|
|
738
|
+
next(parseInfo);
|
|
739
|
+
result.push(yieldResult(parseInfo, EnumToken.Tilda));
|
|
626
740
|
break;
|
|
627
741
|
// case '^':
|
|
628
742
|
case 94 /* TokenMap.CARET */:
|
|
629
|
-
if (
|
|
630
|
-
result.push(yieldResult(
|
|
631
|
-
buffer = "";
|
|
743
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
744
|
+
result.push(yieldResult(parseInfo));
|
|
632
745
|
}
|
|
633
746
|
if (match(parseInfo, "^=")) {
|
|
634
|
-
|
|
747
|
+
next(parseInfo, 2);
|
|
748
|
+
result.push(yieldResult(parseInfo, EnumToken.StartMatchTokenType));
|
|
635
749
|
break;
|
|
636
750
|
}
|
|
637
|
-
|
|
751
|
+
next(parseInfo);
|
|
638
752
|
break;
|
|
639
753
|
case 42 /* TokenMap.STAR */:
|
|
640
|
-
if (
|
|
641
|
-
result.push(yieldResult(
|
|
642
|
-
buffer = "";
|
|
754
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
755
|
+
result.push(yieldResult(parseInfo));
|
|
643
756
|
}
|
|
644
757
|
if (match(parseInfo, "*=")) {
|
|
645
|
-
|
|
758
|
+
next(parseInfo, 2);
|
|
759
|
+
result.push(yieldResult(parseInfo, EnumToken.ContainMatchTokenType));
|
|
646
760
|
break;
|
|
647
761
|
}
|
|
648
|
-
|
|
649
|
-
|
|
762
|
+
next(parseInfo);
|
|
763
|
+
result.push(yieldResult(parseInfo, EnumToken.Star));
|
|
650
764
|
break;
|
|
651
765
|
case 38 /* TokenMap.AMPERSAND */:
|
|
652
|
-
if (
|
|
653
|
-
result.push(yieldResult(
|
|
654
|
-
buffer = "";
|
|
766
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
767
|
+
result.push(yieldResult(parseInfo));
|
|
655
768
|
}
|
|
656
|
-
|
|
657
|
-
|
|
769
|
+
next(parseInfo);
|
|
770
|
+
result.push(yieldResult(parseInfo, EnumToken.NestingSelectorTokenType));
|
|
658
771
|
break;
|
|
659
772
|
case 124 /* TokenMap.PIPE */:
|
|
660
|
-
if (
|
|
661
|
-
result.push(yieldResult(
|
|
662
|
-
buffer = "";
|
|
773
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
774
|
+
result.push(yieldResult(parseInfo));
|
|
663
775
|
}
|
|
664
776
|
// '||'
|
|
665
777
|
if (match(parseInfo, "||")) {
|
|
666
|
-
|
|
778
|
+
next(parseInfo, 2);
|
|
779
|
+
result.push(yieldResult(parseInfo, EnumToken.ColumnCombinatorTokenType));
|
|
667
780
|
break;
|
|
668
781
|
}
|
|
669
782
|
else if (match(parseInfo, "|=")) {
|
|
670
|
-
|
|
783
|
+
next(parseInfo, 2);
|
|
784
|
+
result.push(yieldResult(parseInfo, EnumToken.DashMatchTokenType));
|
|
671
785
|
break;
|
|
672
786
|
}
|
|
673
|
-
|
|
674
|
-
|
|
787
|
+
next(parseInfo);
|
|
788
|
+
result.push(yieldResult(parseInfo, EnumToken.Pipe));
|
|
675
789
|
break;
|
|
676
790
|
case 33 /* TokenMap.EXCLAMATION */:
|
|
677
|
-
if (
|
|
678
|
-
result.push(yieldResult(
|
|
679
|
-
buffer = "";
|
|
791
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
792
|
+
result.push(yieldResult(parseInfo));
|
|
680
793
|
}
|
|
681
794
|
if (match(parseInfo, "!important")) {
|
|
682
|
-
|
|
683
|
-
|
|
795
|
+
next(parseInfo, 10);
|
|
796
|
+
result.push(yieldResult(parseInfo, EnumToken.ImportantTokenType));
|
|
684
797
|
break;
|
|
685
798
|
}
|
|
686
|
-
|
|
799
|
+
next(parseInfo);
|
|
687
800
|
break;
|
|
688
801
|
case 47 /* TokenMap.SLASH */:
|
|
689
|
-
if (
|
|
690
|
-
result.push(yieldResult(
|
|
691
|
-
buffer = "";
|
|
802
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
803
|
+
result.push(yieldResult(parseInfo));
|
|
692
804
|
}
|
|
693
805
|
if (!match(parseInfo, "/*")) {
|
|
694
|
-
|
|
806
|
+
next(parseInfo);
|
|
807
|
+
result.push(yieldResult(parseInfo, SymbolsMapTokens[parseInfo.stream.slice(parseInfo.position, parseInfo.currentPosition)]));
|
|
695
808
|
break;
|
|
696
809
|
}
|
|
697
|
-
|
|
698
|
-
while ((
|
|
699
|
-
if (
|
|
700
|
-
buffer += value;
|
|
810
|
+
next(parseInfo, 2);
|
|
811
|
+
while ((charCode = next(parseInfo).charCodeAt(0)) == charCode) {
|
|
812
|
+
if (charCode == 42 /* TokenMap.STAR */) {
|
|
701
813
|
if (match(parseInfo, "/")) {
|
|
702
|
-
|
|
703
|
-
|
|
814
|
+
next(parseInfo);
|
|
815
|
+
result.push(yieldResult(parseInfo, EnumToken.CommentTokenType));
|
|
704
816
|
break;
|
|
705
817
|
}
|
|
706
818
|
}
|
|
707
|
-
else {
|
|
708
|
-
|
|
709
|
-
}
|
|
819
|
+
// else {
|
|
820
|
+
// buffer += value;
|
|
821
|
+
// }
|
|
710
822
|
}
|
|
711
|
-
if (
|
|
712
|
-
result.push(yieldResult(
|
|
713
|
-
buffer = "";
|
|
823
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
824
|
+
result.push(yieldResult(parseInfo, EnumToken.BadCommentTokenType));
|
|
714
825
|
}
|
|
715
826
|
break;
|
|
716
827
|
case 62 /* TokenMap.GREATERTHAN */:
|
|
717
|
-
if (
|
|
718
|
-
result.push(yieldResult(
|
|
719
|
-
buffer = "";
|
|
828
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
829
|
+
result.push(yieldResult(parseInfo));
|
|
720
830
|
}
|
|
721
831
|
if (match(parseInfo, ">=")) {
|
|
722
|
-
|
|
832
|
+
next(parseInfo, 2);
|
|
833
|
+
result.push(yieldResult(parseInfo, EnumToken.GteTokenType));
|
|
723
834
|
break;
|
|
724
835
|
}
|
|
725
|
-
|
|
726
|
-
|
|
836
|
+
next(parseInfo);
|
|
837
|
+
result.push(yieldResult(parseInfo, EnumToken.GtTokenType));
|
|
727
838
|
break;
|
|
728
839
|
case 60 /* TokenMap.LOWERTHAN */:
|
|
729
|
-
if (
|
|
730
|
-
result.push(yieldResult(
|
|
731
|
-
buffer = "";
|
|
840
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
841
|
+
result.push(yieldResult(parseInfo));
|
|
732
842
|
}
|
|
733
843
|
if (match(parseInfo, "<=")) {
|
|
734
|
-
|
|
844
|
+
next(parseInfo, 2);
|
|
845
|
+
result.push(yieldResult(parseInfo, EnumToken.LteTokenType));
|
|
735
846
|
break;
|
|
736
847
|
}
|
|
737
|
-
|
|
848
|
+
next(parseInfo);
|
|
738
849
|
if (match(parseInfo, "!--")) {
|
|
739
|
-
|
|
740
|
-
while ((
|
|
741
|
-
|
|
742
|
-
if (value == "-" && match(parseInfo, "->")) {
|
|
850
|
+
next(parseInfo, 3);
|
|
851
|
+
while ((charCode = next(parseInfo).charCodeAt(0)) == charCode) {
|
|
852
|
+
if (charCode == 45 /* TokenMap.MINUS */ && match(parseInfo, "->")) {
|
|
743
853
|
break;
|
|
744
854
|
}
|
|
745
855
|
}
|
|
746
|
-
if (
|
|
747
|
-
result.push(yieldResult(
|
|
856
|
+
if (parseInfo.currentPosition >= endPosition) {
|
|
857
|
+
result.push(yieldResult(parseInfo, EnumToken.BadCdoTokenType));
|
|
748
858
|
}
|
|
749
859
|
else {
|
|
750
|
-
|
|
860
|
+
next(parseInfo, 2);
|
|
861
|
+
result.push(yieldResult(parseInfo, EnumToken.CDOCOMMTokenType));
|
|
751
862
|
}
|
|
752
|
-
buffer = "";
|
|
753
863
|
}
|
|
754
864
|
break;
|
|
755
865
|
case 35 /* TokenMap.HASH */:
|
|
756
|
-
if (
|
|
757
|
-
result.push(yieldResult(
|
|
758
|
-
buffer = "";
|
|
866
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
867
|
+
result.push(yieldResult(parseInfo));
|
|
759
868
|
}
|
|
760
|
-
|
|
869
|
+
next(parseInfo);
|
|
761
870
|
break;
|
|
762
871
|
case 92 /* TokenMap.REVERSE_SOLIDUS */:
|
|
872
|
+
if (!yieldEOFToken && parseInfo.stream.length == parseInfo.currentPosition - parseInfo.offset + 1) {
|
|
873
|
+
break;
|
|
874
|
+
}
|
|
763
875
|
next(parseInfo);
|
|
764
876
|
// EOF
|
|
765
|
-
if (!
|
|
877
|
+
if (!peek(parseInfo)) {
|
|
878
|
+
if (!yieldEOFToken) {
|
|
879
|
+
break;
|
|
880
|
+
}
|
|
766
881
|
// end of stream ignore \\
|
|
767
|
-
if (
|
|
768
|
-
result.push(yieldResult(
|
|
769
|
-
buffer = "";
|
|
882
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
883
|
+
result.push(yieldResult(parseInfo));
|
|
770
884
|
}
|
|
771
885
|
break;
|
|
772
886
|
}
|
|
773
|
-
|
|
774
|
-
// buffer +=
|
|
775
|
-
// (parseInfo.offset == parseInfo.currentPosition
|
|
776
|
-
// ? parseInfo.buffer.slice(-1)
|
|
777
|
-
// : parseInfo.stream.charAt(parseInfo.currentPosition - parseInfo.offset - 1)) + value;
|
|
887
|
+
next(parseInfo);
|
|
778
888
|
break;
|
|
779
889
|
case 39 /* TokenMap.SINGLE_QUOTE */:
|
|
780
890
|
case 34 /* TokenMap.DOUBLE_QUOTE */:
|
|
781
|
-
if (
|
|
782
|
-
result.push(yieldResult(
|
|
783
|
-
buffer = "";
|
|
891
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
892
|
+
result.push(yieldResult(parseInfo));
|
|
784
893
|
}
|
|
785
894
|
result.push(...consumeString(parseInfo));
|
|
786
895
|
break;
|
|
787
896
|
case 46 /* TokenMap.DOT */:
|
|
788
897
|
const codepoint = parseInfo.stream
|
|
789
|
-
.charAt(parseInfo.currentPosition - parseInfo.offset +
|
|
898
|
+
.charAt(parseInfo.currentPosition - parseInfo.offset + 1)
|
|
790
899
|
.charCodeAt(0);
|
|
791
|
-
if (!isDigit(codepoint) &&
|
|
792
|
-
result.push(yieldResult(
|
|
793
|
-
|
|
900
|
+
if (!isDigit(codepoint) && parseInfo.position !== parseInfo.currentPosition) {
|
|
901
|
+
result.push(yieldResult(parseInfo));
|
|
902
|
+
next(parseInfo, 2);
|
|
794
903
|
break;
|
|
795
904
|
}
|
|
796
|
-
|
|
905
|
+
next(parseInfo);
|
|
797
906
|
break;
|
|
798
907
|
default:
|
|
799
|
-
|
|
908
|
+
next(parseInfo);
|
|
800
909
|
break;
|
|
801
910
|
}
|
|
802
|
-
if (!yieldEOFToken && endPosition <= parseInfo.
|
|
911
|
+
if (!yieldEOFToken && endPosition <= parseInfo.currentPosition - parseInfo.offset + 1) {
|
|
803
912
|
break;
|
|
804
913
|
}
|
|
805
914
|
}
|
|
806
915
|
if (yieldEOFToken) {
|
|
807
|
-
if (
|
|
808
|
-
result.push(yieldResult(
|
|
916
|
+
if (parseInfo.position < parseInfo.currentPosition) {
|
|
917
|
+
result.push(yieldResult(parseInfo));
|
|
809
918
|
}
|
|
810
|
-
result.push(yieldResult(
|
|
811
|
-
}
|
|
812
|
-
else {
|
|
813
|
-
parseInfo.buffer = buffer;
|
|
919
|
+
result.push(yieldResult(parseInfo, EnumToken.EOFTokenType));
|
|
814
920
|
}
|
|
815
921
|
parseInfo.time += performance.now() - startTime;
|
|
816
922
|
return result;
|
|
@@ -823,19 +929,17 @@ function tokenize(parseInfo, yieldEOFToken = true) {
|
|
|
823
929
|
async function* tokenizeStream(input, parseInfo) {
|
|
824
930
|
const decoder = new TextDecoder("utf-8");
|
|
825
931
|
const reader = input.getReader();
|
|
932
|
+
parseInfo.stream = "";
|
|
826
933
|
while (true) {
|
|
827
934
|
const { done, value } = await reader.read();
|
|
828
935
|
const stream = ArrayBuffer.isView(value) ? decoder.decode(value, { stream: true }) : value;
|
|
829
936
|
if (!done) {
|
|
830
937
|
parseInfo.source.append(stream);
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
stream);
|
|
837
|
-
}
|
|
838
|
-
parseInfo.offset = parseInfo.currentPosition + 1;
|
|
938
|
+
parseInfo.stream = (parseInfo.stream.slice(parseInfo.position - parseInfo.offset) + stream);
|
|
939
|
+
parseInfo.offset = parseInfo.offset = parseInfo.position;
|
|
940
|
+
}
|
|
941
|
+
else {
|
|
942
|
+
parseInfo.stream = "";
|
|
839
943
|
}
|
|
840
944
|
yield* tokenize(parseInfo, done);
|
|
841
945
|
if (done) {
|