@@ -76,23 +76,23 @@ class Tokenizer {
76
76
*
77
77
* https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#next-input-code-point
78
78
*/
79
- private get nextInputCodePoint ( ) : string | EOF {
79
+ private nextInputCodePoint ( ) : string | EOF {
80
80
return this . css [ this . pos ] ;
81
81
}
82
82
83
- private get nextTwoInputCodePoints ( ) : [ string | EOF , string | EOF ] {
83
+ private nextTwoInputCodePoints ( ) : [ string | EOF , string | EOF ] {
84
84
return [ this . css [ this . pos ] , this . css [ this . pos + 1 ] ] ;
85
85
}
86
86
87
- private get nextThreeInputCodePoints ( ) : [
87
+ private nextThreeInputCodePoints ( ) : [
88
88
string | EOF ,
89
89
string | EOF ,
90
90
string | EOF ,
91
91
] {
92
92
return [ this . css [ this . pos ] , this . css [ this . pos + 1 ] , this . css [ this . pos + 2 ] ] ;
93
93
}
94
94
95
- private get currentInputCodePoint ( ) : string | EOF {
95
+ private currentInputCodePoint ( ) : string | EOF {
96
96
return this . css [ this . pos - 1 ] ;
97
97
}
98
98
@@ -136,7 +136,7 @@ class Tokenizer {
136
136
// ":ho st", which is safe.
137
137
return { tokenKind : CssTokenKind . WHITESPACE } ;
138
138
}
139
- const codePoint = this . nextInputCodePoint ;
139
+ const codePoint = this . nextInputCodePoint ( ) ;
140
140
this . consumeTheNextInputCodePoint ( ) ;
141
141
if ( codePoint === EOF ) {
142
142
return { tokenKind : CssTokenKind . EOF } ;
@@ -147,8 +147,8 @@ class Tokenizer {
147
147
return this . consumeString ( codePoint ) ;
148
148
} else if ( codePoint === '#' ) {
149
149
if (
150
- this . isIdentCodePoint ( this . nextInputCodePoint ) ||
151
- this . twoCodePointsAreValidEscape ( ...this . nextTwoInputCodePoints )
150
+ this . isIdentCodePoint ( this . nextInputCodePoint ( ) ) ||
151
+ this . twoCodePointsAreValidEscape ( ...this . nextTwoInputCodePoints ( ) )
152
152
) {
153
153
// In spec there's also a step to check if the next three code points
154
154
// would start an ident sequence. However, the only reason to do so
@@ -208,7 +208,7 @@ class Tokenizer {
208
208
} else if ( codePoint === '@' ) {
209
209
if (
210
210
this . threeCodePointsWouldStartAnIdentSequence (
211
- ...this . nextThreeInputCodePoints ,
211
+ ...this . nextThreeInputCodePoints ( ) ,
212
212
)
213
213
) {
214
214
const ident = this . consumeIdentSequence ( ) ;
@@ -271,7 +271,7 @@ class Tokenizer {
271
271
value : '' ,
272
272
} ;
273
273
while ( true ) {
274
- const codePoint = this . nextInputCodePoint ;
274
+ const codePoint = this . nextInputCodePoint ( ) ;
275
275
this . consumeTheNextInputCodePoint ( ) ;
276
276
if ( codePoint === EOF || codePoint === quote ) {
277
277
return stringToken ;
@@ -283,10 +283,10 @@ class Tokenizer {
283
283
stringToken . value = '' ;
284
284
return stringToken ;
285
285
} else if ( codePoint === '\\' ) {
286
- if ( this . nextInputCodePoint === EOF ) {
286
+ if ( this . nextInputCodePoint ( ) === EOF ) {
287
287
// > If the next input code point is EOF, do nothing.
288
288
continue ;
289
- } else if ( this . isNewline ( this . nextInputCodePoint ) ) {
289
+ } else if ( this . isNewline ( this . nextInputCodePoint ( ) ) ) {
290
290
this . consumeTheNextInputCodePoint ( ) ;
291
291
} else {
292
292
const escapedCodePoint = this . consumeEscapedCodePoint ( ) ;
@@ -300,7 +300,7 @@ class Tokenizer {
300
300
301
301
/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-an-escaped-code-point */
302
302
private consumeEscapedCodePoint ( ) : string {
303
- const codePoint = this . nextInputCodePoint ;
303
+ const codePoint = this . nextInputCodePoint ( ) ;
304
304
this . consumeTheNextInputCodePoint ( ) ;
305
305
if ( codePoint === EOF ) {
306
306
return '\ufffd' ;
@@ -311,12 +311,15 @@ class Tokenizer {
311
311
// The spec assumes here that the first hex digit has already been
312
312
// consumed. So in fact, the maximum number of hex digits that can be
313
313
// consumed is 6.
314
- while ( this . isHexDigit ( this . nextInputCodePoint ) && hexDigits . length < 6 ) {
315
- hexDigits += this . nextInputCodePoint ;
314
+ while (
315
+ this . isHexDigit ( this . nextInputCodePoint ( ) ) &&
316
+ hexDigits . length < 6
317
+ ) {
318
+ hexDigits += this . nextInputCodePoint ( ) ;
316
319
this . consumeTheNextInputCodePoint ( ) ;
317
320
}
318
321
// Whitespace directly following an escape sequence is ignored.
319
- if ( this . isWhitespace ( this . nextInputCodePoint ) ) {
322
+ if ( this . isWhitespace ( this . nextInputCodePoint ( ) ) ) {
320
323
this . consumeTheNextInputCodePoint ( ) ;
321
324
}
322
325
// Needed to parse hexadecimal.
@@ -329,7 +332,7 @@ class Tokenizer {
329
332
}
330
333
331
334
private consumeAsMuchWhitespaceAsPossible ( ) {
332
- while ( this . isWhitespace ( this . nextInputCodePoint ) ) {
335
+ while ( this . isWhitespace ( this . nextInputCodePoint ( ) ) ) {
333
336
this . consumeTheNextInputCodePoint ( ) ;
334
337
}
335
338
}
@@ -338,9 +341,9 @@ class Tokenizer {
338
341
private consumeIdentSequence ( ) : string {
339
342
let result = '' ;
340
343
while ( true ) {
341
- const codePoint = this . nextInputCodePoint ;
344
+ const codePoint = this . nextInputCodePoint ( ) ;
342
345
this . consumeTheNextInputCodePoint ( ) ;
343
- const codePoint2 = this . nextInputCodePoint ;
346
+ const codePoint2 = this . nextInputCodePoint ( ) ;
344
347
if ( this . isIdentCodePoint ( codePoint ) ) {
345
348
result += codePoint ;
346
349
} else if ( this . twoCodePointsAreValidEscape ( codePoint , codePoint2 ) ) {
@@ -355,15 +358,15 @@ class Tokenizer {
355
358
/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-an-ident-like-token */
356
359
private consumeIdentLikeToken ( ) : CssToken | CssToken [ ] {
357
360
const ident = this . consumeIdentSequence ( ) ;
358
- if ( / ^ u r l $ / i. test ( ident ) && this . nextInputCodePoint === '(' ) {
361
+ if ( / ^ u r l $ / i. test ( ident ) && this . nextInputCodePoint ( ) === '(' ) {
359
362
// TODO(securitymb): This algorithm may look a little weird but we're
360
363
// following the spec here exactly. We will see later on if this can be
361
364
// optimized.
362
365
this . consumeTheNextInputCodePoint ( ) ;
363
366
while ( this . nextTwoInputsPointsAreWhitespace ( ) ) {
364
367
this . consumeTheNextInputCodePoint ( ) ;
365
368
}
366
- const nextTwo = this . nextTwoInputCodePoints ;
369
+ const nextTwo = this . nextTwoInputCodePoints ( ) ;
367
370
if (
368
371
( this . isWhitespace ( nextTwo [ 0 ] ) &&
369
372
( nextTwo [ 1 ] === '"' || nextTwo [ 1 ] === "'" ) ) ||
@@ -376,7 +379,7 @@ class Tokenizer {
376
379
} else {
377
380
return this . consumeUrlToken ( ) ;
378
381
}
379
- } else if ( this . nextInputCodePoint === '(' ) {
382
+ } else if ( this . nextInputCodePoint ( ) === '(' ) {
380
383
this . consumeTheNextInputCodePoint ( ) ;
381
384
// We lowercase the function name because function names are
382
385
// case-insensitive in CSS.
@@ -413,15 +416,15 @@ class Tokenizer {
413
416
let url = '' ;
414
417
this . consumeAsMuchWhitespaceAsPossible ( ) ;
415
418
while ( true ) {
416
- const codePoint = this . nextInputCodePoint ;
419
+ const codePoint = this . nextInputCodePoint ( ) ;
417
420
this . consumeTheNextInputCodePoint ( ) ;
418
421
if ( codePoint === ')' || codePoint === EOF ) {
419
422
return this . createFunctionUrlToken ( url ) ;
420
423
} else if ( this . isWhitespace ( codePoint ) ) {
421
424
this . consumeAsMuchWhitespaceAsPossible ( ) ;
422
425
if (
423
- this . nextInputCodePoint === ')' ||
424
- this . nextInputCodePoint === EOF
426
+ this . nextInputCodePoint ( ) === ')' ||
427
+ this . nextInputCodePoint ( ) === EOF
425
428
) {
426
429
this . consumeTheNextInputCodePoint ( ) ;
427
430
return this . createFunctionUrlToken ( url ) ;
@@ -462,7 +465,7 @@ class Tokenizer {
462
465
/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#consume-the-remnants-of-a-bad-url */
463
466
private consumeRemnantsOfBadUrl ( ) {
464
467
while ( true ) {
465
- const codePoint = this . nextInputCodePoint ;
468
+ const codePoint = this . nextInputCodePoint ( ) ;
466
469
this . consumeTheNextInputCodePoint ( ) ;
467
470
if ( codePoint === EOF || codePoint === ')' ) {
468
471
return ;
@@ -484,23 +487,23 @@ class Tokenizer {
484
487
private consumeNumber ( ) : string {
485
488
let repr = '' ;
486
489
{
487
- const next = this . nextInputCodePoint ;
490
+ const next = this . nextInputCodePoint ( ) ;
488
491
if ( next === '+' || next === '-' ) {
489
492
this . consumeTheNextInputCodePoint ( ) ;
490
493
repr += next ;
491
494
}
492
495
}
493
496
repr += this . consumeDigits ( ) ;
494
497
{
495
- const next = this . nextInputCodePoint ;
498
+ const next = this . nextInputCodePoint ( ) ;
496
499
const next2 = this . css [ this . pos + 1 ] ;
497
500
if ( next === '.' && this . isDigit ( next2 ) ) {
498
501
this . consumeTheNextInputCodePoint ( ) ;
499
502
repr += '.' + this . consumeDigits ( ) ;
500
503
}
501
504
}
502
505
{
503
- const next = this . nextInputCodePoint ;
506
+ const next = this . nextInputCodePoint ( ) ;
504
507
const next2 = this . css [ this . pos + 1 ] ;
505
508
const next3 = this . css [ this . pos + 2 ] ;
506
509
if ( next === 'e' || next === 'E' ) {
@@ -518,8 +521,8 @@ class Tokenizer {
518
521
519
522
private consumeDigits ( ) : string {
520
523
let repr = '' ;
521
- while ( this . isDigit ( this . nextInputCodePoint ) ) {
522
- repr += this . nextInputCodePoint ;
524
+ while ( this . isDigit ( this . nextInputCodePoint ( ) ) ) {
525
+ repr += this . nextInputCodePoint ( ) ;
523
526
this . consumeTheNextInputCodePoint ( ) ;
524
527
}
525
528
return repr ;
@@ -533,7 +536,7 @@ class Tokenizer {
533
536
const repr = this . consumeNumber ( ) ;
534
537
if (
535
538
this . threeCodePointsWouldStartAnIdentSequence (
536
- ...this . nextThreeInputCodePoints ,
539
+ ...this . nextThreeInputCodePoints ( ) ,
537
540
)
538
541
) {
539
542
return {
@@ -542,15 +545,15 @@ class Tokenizer {
542
545
dimension : this . consumeIdentSequence ( ) ,
543
546
} ;
544
547
}
545
- if ( this . nextInputCodePoint === '%' ) {
548
+ if ( this . nextInputCodePoint ( ) === '%' ) {
546
549
this . consumeTheNextInputCodePoint ( ) ;
547
550
return { tokenKind : CssTokenKind . PERCENTAGE , repr} ;
548
551
}
549
552
return { tokenKind : CssTokenKind . NUMBER , repr} ;
550
553
}
551
554
552
555
private nextTwoInputsPointsAreWhitespace ( ) {
553
- return this . nextTwoInputCodePoints . every ( ( c ) => this . isWhitespace ( c ) ) ;
556
+ return this . nextTwoInputCodePoints ( ) . every ( ( c ) => this . isWhitespace ( c ) ) ;
554
557
}
555
558
556
559
/** https://www.w3.org/TR/2021/CRD-css-syntax-3-20211224/#check-if-two-code-points-are-a-valid-escape */
@@ -563,8 +566,8 @@ class Tokenizer {
563
566
564
567
private streamStartsWithValidEscape ( ) {
565
568
return this . twoCodePointsAreValidEscape (
566
- this . currentInputCodePoint ,
567
- this . nextInputCodePoint ,
569
+ this . currentInputCodePoint ( ) ,
570
+ this . nextInputCodePoint ( ) ,
568
571
) ;
569
572
}
570
573
@@ -588,8 +591,8 @@ class Tokenizer {
588
591
589
592
private streamStartsWithANumber ( ) {
590
593
return this . threeCodePointsWouldStartANumber (
591
- this . currentInputCodePoint ,
592
- ...this . nextTwoInputCodePoints ,
594
+ this . currentInputCodePoint ( ) ,
595
+ ...this . nextTwoInputCodePoints ( ) ,
593
596
) ;
594
597
}
595
598
@@ -618,8 +621,8 @@ class Tokenizer {
618
621
619
622
private streamStartsWithAnIdentSequence ( ) {
620
623
return this . threeCodePointsWouldStartAnIdentSequence (
621
- this . currentInputCodePoint ,
622
- ...this . nextTwoInputCodePoints ,
624
+ this . currentInputCodePoint ( ) ,
625
+ ...this . nextTwoInputCodePoints ( ) ,
623
626
) ;
624
627
}
625
628
0 commit comments