@@ -91,14 +91,13 @@ function isEmpty(ch: string) {
91
91
}
92
92
}
93
93
94
- const hexDigits = '0123456789ABCDEFabcdef' . split ( '' )
95
- const tagChars =
96
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()" . split (
97
- ''
98
- )
99
- const invalidFlowScalarChars = ',[]{}' . split ( '' )
100
- const invalidAnchorChars = ' ,[]{}\n\r\t' . split ( '' )
101
- const isNotAnchorChar = ( ch : string ) => ! ch || invalidAnchorChars . includes ( ch )
94
+ const hexDigits = new Set ( '0123456789ABCDEFabcdef' )
95
+ const tagChars = new Set (
96
+ "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()"
97
+ )
98
+ const flowIndicatorChars = new Set ( ',[]{}' )
99
+ const invalidAnchorChars = new Set ( ' ,[]{}\n\r\t' )
100
+ const isNotAnchorChar = ( ch : string ) => ! ch || invalidAnchorChars . has ( ch )
102
101
103
102
/**
104
103
* Splits an input string into lexical tokens, i.e. smaller strings that are
@@ -573,7 +572,7 @@ export class Lexer {
573
572
while ( ( ch = this . buffer [ ++ i ] ) ) {
574
573
if ( ch === ':' ) {
575
574
const next = this . buffer [ i + 1 ]
576
- if ( isEmpty ( next ) || ( inFlow && next === ',' ) ) break
575
+ if ( isEmpty ( next ) || ( inFlow && flowIndicatorChars . has ( next ) ) ) break
577
576
end = i
578
577
} else if ( isEmpty ( ch ) ) {
579
578
let next = this . buffer [ i + 1 ]
@@ -584,15 +583,14 @@ export class Lexer {
584
583
next = this . buffer [ i + 1 ]
585
584
} else end = i
586
585
}
587
- if ( next === '#' || ( inFlow && invalidFlowScalarChars . includes ( next ) ) )
588
- break
586
+ if ( next === '#' || ( inFlow && flowIndicatorChars . has ( next ) ) ) break
589
587
if ( ch === '\n' ) {
590
588
const cs = this . continueScalar ( i + 1 )
591
589
if ( cs === - 1 ) break
592
590
i = Math . max ( i , cs - 2 ) // to advance, but still account for ' #'
593
591
}
594
592
} else {
595
- if ( inFlow && invalidFlowScalarChars . includes ( ch ) ) break
593
+ if ( inFlow && flowIndicatorChars . has ( ch ) ) break
596
594
end = i
597
595
}
598
596
}
@@ -640,7 +638,7 @@ export class Lexer {
640
638
case ':' : {
641
639
const inFlow = this . flowLevel > 0
642
640
const ch1 = this . charAt ( 1 )
643
- if ( isEmpty ( ch1 ) || ( inFlow && invalidFlowScalarChars . includes ( ch1 ) ) ) {
641
+ if ( isEmpty ( ch1 ) || ( inFlow && flowIndicatorChars . has ( ch1 ) ) ) {
644
642
if ( ! inFlow ) this . indentNext = this . indentValue + 1
645
643
else if ( this . flowKey ) this . flowKey = false
646
644
return (
@@ -664,11 +662,11 @@ export class Lexer {
664
662
let i = this . pos + 1
665
663
let ch = this . buffer [ i ]
666
664
while ( ch ) {
667
- if ( tagChars . includes ( ch ) ) ch = this . buffer [ ++ i ]
665
+ if ( tagChars . has ( ch ) ) ch = this . buffer [ ++ i ]
668
666
else if (
669
667
ch === '%' &&
670
- hexDigits . includes ( this . buffer [ i + 1 ] ) &&
671
- hexDigits . includes ( this . buffer [ i + 2 ] )
668
+ hexDigits . has ( this . buffer [ i + 1 ] ) &&
669
+ hexDigits . has ( this . buffer [ i + 2 ] )
672
670
) {
673
671
ch = this . buffer [ ( i += 3 ) ]
674
672
} else break
0 commit comments