@@ -91,14 +91,13 @@ function isEmpty(ch: string) {
9191 }
9292}
9393
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 )
102101
103102/**
104103 * Splits an input string into lexical tokens, i.e. smaller strings that are
@@ -573,7 +572,7 @@ export class Lexer {
573572 while ( ( ch = this . buffer [ ++ i ] ) ) {
574573 if ( ch === ':' ) {
575574 const next = this . buffer [ i + 1 ]
576- if ( isEmpty ( next ) || ( inFlow && next === ',' ) ) break
575+ if ( isEmpty ( next ) || ( inFlow && flowIndicatorChars . has ( next ) ) ) break
577576 end = i
578577 } else if ( isEmpty ( ch ) ) {
579578 let next = this . buffer [ i + 1 ]
@@ -584,15 +583,14 @@ export class Lexer {
584583 next = this . buffer [ i + 1 ]
585584 } else end = i
586585 }
587- if ( next === '#' || ( inFlow && invalidFlowScalarChars . includes ( next ) ) )
588- break
586+ if ( next === '#' || ( inFlow && flowIndicatorChars . has ( next ) ) ) break
589587 if ( ch === '\n' ) {
590588 const cs = this . continueScalar ( i + 1 )
591589 if ( cs === - 1 ) break
592590 i = Math . max ( i , cs - 2 ) // to advance, but still account for ' #'
593591 }
594592 } else {
595- if ( inFlow && invalidFlowScalarChars . includes ( ch ) ) break
593+ if ( inFlow && flowIndicatorChars . has ( ch ) ) break
596594 end = i
597595 }
598596 }
@@ -640,7 +638,7 @@ export class Lexer {
640638 case ':' : {
641639 const inFlow = this . flowLevel > 0
642640 const ch1 = this . charAt ( 1 )
643- if ( isEmpty ( ch1 ) || ( inFlow && invalidFlowScalarChars . includes ( ch1 ) ) ) {
641+ if ( isEmpty ( ch1 ) || ( inFlow && flowIndicatorChars . has ( ch1 ) ) ) {
644642 if ( ! inFlow ) this . indentNext = this . indentValue + 1
645643 else if ( this . flowKey ) this . flowKey = false
646644 return (
@@ -664,11 +662,11 @@ export class Lexer {
664662 let i = this . pos + 1
665663 let ch = this . buffer [ i ]
666664 while ( ch ) {
667- if ( tagChars . includes ( ch ) ) ch = this . buffer [ ++ i ]
665+ if ( tagChars . has ( ch ) ) ch = this . buffer [ ++ i ]
668666 else if (
669667 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 ] )
672670 ) {
673671 ch = this . buffer [ ( i += 3 ) ]
674672 } else break
0 commit comments