@@ -26,9 +26,6 @@ const enum CharCodes {
26
26
Eq = 0x3d , // "="
27
27
Gt = 0x3e , // ">"
28
28
Questionmark = 0x3f , // "?"
29
- LowerC = 0x63 , // "c"
30
- LowerS = 0x73 , // "s"
31
- LowerT = 0x74 , // "t"
32
29
UpperA = 0x41 , // "A"
33
30
LowerA = 0x61 , // "a"
34
31
UpperF = 0x46 , // "F"
@@ -37,7 +34,6 @@ const enum CharCodes {
37
34
LowerZ = 0x7a , // "z"
38
35
LowerX = 0x78 , // "x"
39
36
OpeningSquareBracket = 0x5b , // "["
40
- ClosingSquareBracket = 0x5d , // "]"
41
37
}
42
38
43
39
/** All the states the tokenizer can be in. */
@@ -402,38 +398,39 @@ export default class Tokenizer {
402
398
* We allow anything that wouldn't end the tag.
403
399
*/
404
400
private isTagStartChar ( c : number ) {
405
- return isASCIIAlpha ( c ) || ( this . xmlMode && ! isEndOfTagSection ( c ) ) ;
401
+ return this . xmlMode ? ! isEndOfTagSection ( c ) : isASCIIAlpha ( c ) ;
406
402
}
403
+
404
+ private startSpecial ( sequence : Uint16Array , offset : number ) {
405
+ this . isSpecial = true ;
406
+ this . currentSequence = sequence ;
407
+ this . sequenceIndex = offset ;
408
+ this . _state = State . SpecialStartSequence ;
409
+ }
410
+
407
411
private stateBeforeTagName ( c : number ) {
408
- if ( c === CharCodes . Slash ) {
409
- this . _state = State . BeforeClosingTagName ;
410
- } else if ( c === CharCodes . Lt ) {
411
- this . cbs . ontext ( this . getSection ( ) ) ;
412
- this . sectionStart = this . _index ;
413
- } else if ( c === CharCodes . Gt || isWhitespace ( c ) ) {
414
- this . _state = State . Text ;
415
- } else if ( c === CharCodes . ExclamationMark ) {
412
+ if ( c === CharCodes . ExclamationMark ) {
416
413
this . _state = State . BeforeDeclaration ;
417
414
this . sectionStart = this . _index + 1 ;
418
415
} else if ( c === CharCodes . Questionmark ) {
419
416
this . _state = State . InProcessingInstruction ;
420
417
this . sectionStart = this . _index + 1 ;
421
- } else if ( ! this . isTagStartChar ( c ) ) {
422
- this . _state = State . Text ;
423
- } else {
418
+ } else if ( this . isTagStartChar ( c ) ) {
424
419
const lower = c | 0x20 ;
425
420
this . sectionStart = this . _index ;
426
- if ( ! this . xmlMode && lower === CharCodes . LowerT ) {
427
- this . isSpecial = true ;
428
- this . currentSequence = Sequences . TitleEnd ;
429
- this . sequenceIndex = 3 ;
430
- this . _state = State . SpecialStartSequence ;
421
+ if ( ! this . xmlMode && lower === Sequences . TitleEnd [ 2 ] ) {
422
+ this . startSpecial ( Sequences . TitleEnd , 3 ) ;
431
423
} else {
432
424
this . _state =
433
- ! this . xmlMode && lower === CharCodes . LowerS
425
+ ! this . xmlMode && lower === Sequences . ScriptEnd [ 2 ]
434
426
? State . BeforeSpecialS
435
427
: State . InTagName ;
436
428
}
429
+ } else if ( c === CharCodes . Slash ) {
430
+ this . _state = State . BeforeClosingTagName ;
431
+ } else {
432
+ this . _state = State . Text ;
433
+ this . stateText ( c ) ;
437
434
}
438
435
}
439
436
private stateInTagName ( c : number ) {
@@ -449,11 +446,10 @@ export default class Tokenizer {
449
446
// Ignore
450
447
} else if ( c === CharCodes . Gt ) {
451
448
this . _state = State . Text ;
452
- } else if ( ! this . isTagStartChar ( c ) ) {
453
- this . _state = State . InSpecialComment ;
454
- this . sectionStart = this . _index ;
455
449
} else {
456
- this . _state = State . InClosingTagName ;
450
+ this . _state = this . isTagStartChar ( c )
451
+ ? State . InClosingTagName
452
+ : State . InSpecialComment ;
457
453
this . sectionStart = this . _index ;
458
454
}
459
455
}
@@ -617,16 +613,10 @@ export default class Tokenizer {
617
613
}
618
614
private stateBeforeSpecialS ( c : number ) {
619
615
const lower = c | 0x20 ;
620
- if ( lower === CharCodes . LowerC ) {
621
- this . isSpecial = true ;
622
- this . currentSequence = Sequences . ScriptEnd ;
623
- this . sequenceIndex = 4 ;
624
- this . _state = State . SpecialStartSequence ;
625
- } else if ( lower === CharCodes . LowerT ) {
626
- this . isSpecial = true ;
627
- this . currentSequence = Sequences . StyleEnd ;
628
- this . sequenceIndex = 4 ;
629
- this . _state = State . SpecialStartSequence ;
616
+ if ( lower === Sequences . ScriptEnd [ 3 ] ) {
617
+ this . startSpecial ( Sequences . ScriptEnd , 4 ) ;
618
+ } else if ( lower === Sequences . StyleEnd [ 3 ] ) {
619
+ this . startSpecial ( Sequences . StyleEnd , 4 ) ;
630
620
} else {
631
621
this . _state = State . InTagName ;
632
622
this . stateInTagName ( c ) ; // Consume the token again
0 commit comments