@@ -282,16 +282,16 @@ const textToToken = new Map(Object.entries({
282
282
"`" : SyntaxKind . BacktickToken ,
283
283
} ) ) ;
284
284
285
- const charToRegExpFlag = new Map ( Object . entries ( {
286
- d : RegularExpressionFlags . HasIndices ,
287
- g : RegularExpressionFlags . Global ,
288
- i : RegularExpressionFlags . IgnoreCase ,
289
- m : RegularExpressionFlags . Multiline ,
290
- s : RegularExpressionFlags . DotAll ,
291
- u : RegularExpressionFlags . Unicode ,
292
- v : RegularExpressionFlags . UnicodeSets ,
293
- y : RegularExpressionFlags . Sticky ,
294
- } ) ) ;
285
+ const charCodeToRegExpFlag = new Map < CharacterCodes , RegularExpressionFlags > ( [
286
+ [ CharacterCodes . d , RegularExpressionFlags . HasIndices ] ,
287
+ [ CharacterCodes . g , RegularExpressionFlags . Global ] ,
288
+ [ CharacterCodes . i , RegularExpressionFlags . IgnoreCase ] ,
289
+ [ CharacterCodes . m , RegularExpressionFlags . Multiline ] ,
290
+ [ CharacterCodes . s , RegularExpressionFlags . DotAll ] ,
291
+ [ CharacterCodes . u , RegularExpressionFlags . Unicode ] ,
292
+ [ CharacterCodes . v , RegularExpressionFlags . UnicodeSets ] ,
293
+ [ CharacterCodes . y , RegularExpressionFlags . Sticky ] ,
294
+ ] ) ;
295
295
296
296
const regExpFlagToFirstAvailableLanguageVersion = new Map < RegularExpressionFlags , LanguageFeatureMinimumTarget > ( [
297
297
[ RegularExpressionFlags . HasIndices , LanguageFeatureMinimumTarget . RegularExpressionFlagsHasIndices ] ,
@@ -394,8 +394,8 @@ function isUnicodeIdentifierPart(code: number, languageVersion: ScriptTarget | u
394
394
lookupInUnicodeMap ( code , unicodeES5IdentifierPart ) ;
395
395
}
396
396
397
- function makeReverseMap ( source : Map < string , number > ) : string [ ] {
398
- const result : string [ ] = [ ] ;
397
+ function makeReverseMap < T > ( source : Map < T , number > ) : T [ ] {
398
+ const result : T [ ] = [ ] ;
399
399
source . forEach ( ( value , name ) => {
400
400
result [ value ] = name ;
401
401
} ) ;
@@ -416,16 +416,16 @@ export function stringToToken(s: string): SyntaxKind | undefined {
416
416
return textToToken . get ( s ) ;
417
417
}
418
418
419
- const regExpFlagChars = makeReverseMap ( charToRegExpFlag ) ;
419
+ const regExpFlagCharCodes = makeReverseMap ( charCodeToRegExpFlag ) ;
420
420
421
421
/** @internal */
422
- export function regularExpressionFlagToCharacter ( f : RegularExpressionFlags ) : string | undefined {
423
- return regExpFlagChars [ f ] ;
422
+ export function regularExpressionFlagToCharacterCode ( f : RegularExpressionFlags ) : CharacterCodes | undefined {
423
+ return regExpFlagCharCodes [ f ] ;
424
424
}
425
425
426
426
/** @internal */
427
- export function characterToRegularExpressionFlag ( c : string ) : RegularExpressionFlags | undefined {
428
- return charToRegExpFlag . get ( c ) ;
427
+ export function characterCodeToRegularExpressionFlag ( ch : CharacterCodes ) : RegularExpressionFlags | undefined {
428
+ return charCodeToRegExpFlag . get ( ch ) ;
429
429
}
430
430
431
431
/** @internal */
@@ -2558,27 +2558,28 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
2558
2558
pos ++ ;
2559
2559
let regExpFlags = RegularExpressionFlags . None ;
2560
2560
while ( true ) {
2561
- const ch = charCodeChecked ( pos ) ;
2561
+ const ch = codePointChecked ( pos ) ;
2562
2562
if ( ch === CharacterCodes . EOF || ! isIdentifierPart ( ch , languageVersion ) ) {
2563
2563
break ;
2564
2564
}
2565
+ const size = charSize ( ch ) ;
2565
2566
if ( reportErrors ) {
2566
- const flag = characterToRegularExpressionFlag ( String . fromCharCode ( ch ) ) ;
2567
+ const flag = characterCodeToRegularExpressionFlag ( ch ) ;
2567
2568
if ( flag === undefined ) {
2568
- error ( Diagnostics . Unknown_regular_expression_flag , pos , 1 ) ;
2569
+ error ( Diagnostics . Unknown_regular_expression_flag , pos , size ) ;
2569
2570
}
2570
2571
else if ( regExpFlags & flag ) {
2571
- error ( Diagnostics . Duplicate_regular_expression_flag , pos , 1 ) ;
2572
+ error ( Diagnostics . Duplicate_regular_expression_flag , pos , size ) ;
2572
2573
}
2573
2574
else if ( ( ( regExpFlags | flag ) & RegularExpressionFlags . AnyUnicodeMode ) === RegularExpressionFlags . AnyUnicodeMode ) {
2574
- error ( Diagnostics . The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously , pos , 1 ) ;
2575
+ error ( Diagnostics . The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously , pos , size ) ;
2575
2576
}
2576
2577
else {
2577
2578
regExpFlags |= flag ;
2578
- checkRegularExpressionFlagAvailable ( flag , pos ) ;
2579
+ checkRegularExpressionFlagAvailability ( flag , size ) ;
2579
2580
}
2580
2581
}
2581
- pos ++ ;
2582
+ pos += size ;
2582
2583
}
2583
2584
if ( reportErrors ) {
2584
2585
scanRange ( startOfRegExpBody , endOfRegExpBody - startOfRegExpBody , ( ) => {
@@ -2843,25 +2844,26 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
2843
2844
2844
2845
function scanPatternModifiers ( currFlags : RegularExpressionFlags ) : RegularExpressionFlags {
2845
2846
while ( true ) {
2846
- const ch = charCodeChecked ( pos ) ;
2847
+ const ch = codePointChecked ( pos ) ;
2847
2848
if ( ch === CharacterCodes . EOF || ! isIdentifierPart ( ch , languageVersion ) ) {
2848
2849
break ;
2849
2850
}
2850
- const flag = characterToRegularExpressionFlag ( String . fromCharCode ( ch ) ) ;
2851
+ const size = charSize ( ch ) ;
2852
+ const flag = characterCodeToRegularExpressionFlag ( ch ) ;
2851
2853
if ( flag === undefined ) {
2852
- error ( Diagnostics . Unknown_regular_expression_flag , pos , 1 ) ;
2854
+ error ( Diagnostics . Unknown_regular_expression_flag , pos , size ) ;
2853
2855
}
2854
2856
else if ( currFlags & flag ) {
2855
- error ( Diagnostics . Duplicate_regular_expression_flag , pos , 1 ) ;
2857
+ error ( Diagnostics . Duplicate_regular_expression_flag , pos , size ) ;
2856
2858
}
2857
2859
else if ( ! ( flag & RegularExpressionFlags . Modifiers ) ) {
2858
- error ( Diagnostics . This_regular_expression_flag_cannot_be_toggled_within_a_subpattern , pos , 1 ) ;
2860
+ error ( Diagnostics . This_regular_expression_flag_cannot_be_toggled_within_a_subpattern , pos , size ) ;
2859
2861
}
2860
2862
else {
2861
2863
currFlags |= flag ;
2862
- checkRegularExpressionFlagAvailable ( flag , pos ) ;
2864
+ checkRegularExpressionFlagAvailability ( flag , size ) ;
2863
2865
}
2864
- pos ++ ;
2866
+ pos += size ;
2865
2867
}
2866
2868
return currFlags ;
2867
2869
}
@@ -3583,10 +3585,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
3583
3585
} ) ;
3584
3586
}
3585
3587
3586
- function checkRegularExpressionFlagAvailable ( flag : RegularExpressionFlags , pos : number ) {
3588
+ function checkRegularExpressionFlagAvailability ( flag : RegularExpressionFlags , size : number ) {
3587
3589
const availableFrom = regExpFlagToFirstAvailableLanguageVersion . get ( flag ) as ScriptTarget | undefined ;
3588
3590
if ( availableFrom && languageVersion < availableFrom ) {
3589
- error ( Diagnostics . This_regular_expression_flag_is_only_available_when_targeting_0_or_later , pos , 1 , getNameOfScriptTarget ( availableFrom ) ) ;
3591
+ error ( Diagnostics . This_regular_expression_flag_is_only_available_when_targeting_0_or_later , pos , size , getNameOfScriptTarget ( availableFrom ) ) ;
3590
3592
}
3591
3593
}
3592
3594
0 commit comments