@@ -2474,28 +2474,29 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
2474
2474
const isUnterminated = ! ! ( tokenFlags & TokenFlags . Unterminated ) ;
2475
2475
const endOfBody = p - ( isUnterminated ? 0 : 1 ) ;
2476
2476
let regExpFlags = RegularExpressionFlags . None ;
2477
- while ( p < end ) {
2478
- const ch = charCodeUnchecked ( p ) ;
2479
- if ( ! isIdentifierPart ( ch , languageVersion ) ) {
2477
+ while ( true ) {
2478
+ const ch = codePointChecked ( p ) ;
2479
+ if ( ch === CharacterCodes . EOF || ! isIdentifierPart ( ch , languageVersion ) ) {
2480
2480
break ;
2481
2481
}
2482
+ const size = charSize ( ch ) ;
2482
2483
if ( reportErrors ) {
2483
- const flag = characterToRegularExpressionFlag ( String . fromCharCode ( ch ) ) ;
2484
+ const flag = characterToRegularExpressionFlag ( utf16EncodeAsString ( ch ) ) ;
2484
2485
if ( flag === undefined ) {
2485
- error ( Diagnostics . Unknown_regular_expression_flag , p , 1 ) ;
2486
+ error ( Diagnostics . Unknown_regular_expression_flag , p , size ) ;
2486
2487
}
2487
2488
else if ( regExpFlags & flag ) {
2488
- error ( Diagnostics . Duplicate_regular_expression_flag , p , 1 ) ;
2489
+ error ( Diagnostics . Duplicate_regular_expression_flag , p , size ) ;
2489
2490
}
2490
2491
else if ( ( ( regExpFlags | flag ) & RegularExpressionFlags . UnicodeMode ) === RegularExpressionFlags . UnicodeMode ) {
2491
- error ( Diagnostics . The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously , p , 1 ) ;
2492
+ error ( Diagnostics . The_Unicode_u_flag_and_the_Unicode_Sets_v_flag_cannot_be_set_simultaneously , p , size ) ;
2492
2493
}
2493
2494
else {
2494
2495
regExpFlags |= flag ;
2495
- checkRegularExpressionFlagAvailable ( flag , p ) ;
2496
+ checkRegularExpressionFlagAvailability ( flag , p , size ) ;
2496
2497
}
2497
2498
}
2498
- p ++ ;
2499
+ p += size ;
2499
2500
}
2500
2501
pos = p ;
2501
2502
if ( reportErrors ) {
@@ -2763,23 +2764,24 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
2763
2764
2764
2765
function scanPatternModifiers ( currFlags : RegularExpressionFlags ) : RegularExpressionFlags {
2765
2766
while ( true ) {
2766
- const ch = charCodeChecked ( pos ) ;
2767
+ const ch = codePointChecked ( pos ) ;
2767
2768
if ( ch === CharacterCodes . EOF || ! isIdentifierPart ( ch , languageVersion ) ) {
2768
2769
break ;
2769
2770
}
2771
+ const size = charSize ( ch ) ;
2770
2772
const flag = characterToRegularExpressionFlag ( String . fromCharCode ( ch ) ) ;
2771
2773
if ( flag === undefined ) {
2772
- error ( Diagnostics . Unknown_regular_expression_flag , pos , 1 ) ;
2774
+ error ( Diagnostics . Unknown_regular_expression_flag , pos , size ) ;
2773
2775
}
2774
2776
else if ( currFlags & flag ) {
2775
- error ( Diagnostics . Duplicate_regular_expression_flag , pos , 1 ) ;
2777
+ error ( Diagnostics . Duplicate_regular_expression_flag , pos , size ) ;
2776
2778
}
2777
2779
else if ( ! ( flag & RegularExpressionFlags . Modifiers ) ) {
2778
- error ( Diagnostics . This_regular_expression_flag_cannot_be_toggled_within_a_subpattern , pos , 1 ) ;
2780
+ error ( Diagnostics . This_regular_expression_flag_cannot_be_toggled_within_a_subpattern , pos , size ) ;
2779
2781
}
2780
2782
else {
2781
2783
currFlags |= flag ;
2782
- checkRegularExpressionFlagAvailable ( flag , pos ) ;
2784
+ checkRegularExpressionFlagAvailability ( flag , pos , size ) ;
2783
2785
}
2784
2786
pos ++ ;
2785
2787
}
@@ -3494,10 +3496,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
3494
3496
} ) ;
3495
3497
}
3496
3498
3497
- function checkRegularExpressionFlagAvailable ( flag : RegularExpressionFlags , pos : number ) {
3499
+ function checkRegularExpressionFlagAvailability ( flag : RegularExpressionFlags , pos : number , size : number ) {
3498
3500
const availableFrom = regExpFlagToFirstAvailableLanguageVersion . get ( flag ) as ScriptTarget | undefined ;
3499
3501
if ( availableFrom && languageVersion < availableFrom ) {
3500
- error ( Diagnostics . This_regular_expression_flag_is_only_available_when_targeting_0_or_later , pos , 1 , getNameOfScriptTarget ( availableFrom ) ) ;
3502
+ error ( Diagnostics . This_regular_expression_flag_is_only_available_when_targeting_0_or_later , pos , size , getNameOfScriptTarget ( availableFrom ) ) ;
3501
3503
}
3502
3504
}
3503
3505
0 commit comments