@@ -2470,10 +2470,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
2470
2470
}
2471
2471
else if (
2472
2472
ch === CharacterCodes . openParen
2473
- && charCodeUnchecked ( p + 1 ) === CharacterCodes . question
2474
- && charCodeUnchecked ( p + 2 ) === CharacterCodes . lessThan
2475
- && charCodeUnchecked ( p + 3 ) !== CharacterCodes . equals
2476
- && charCodeUnchecked ( p + 3 ) !== CharacterCodes . exclamation
2473
+ && charCodeChecked ( p + 1 ) === CharacterCodes . question
2474
+ && charCodeChecked ( p + 2 ) === CharacterCodes . lessThan
2475
+ && charCodeChecked ( p + 3 ) !== CharacterCodes . equals
2476
+ && charCodeChecked ( p + 3 ) !== CharacterCodes . exclamation
2477
2477
) {
2478
2478
namedCaptureGroups = true ;
2479
2479
}
@@ -2535,7 +2535,8 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
2535
2535
/** Grammar parameter */
2536
2536
var unicodeMode = ! ! ( regExpFlags & RegularExpressionFlags . UnicodeMode ) ;
2537
2537
2538
- // Annex B treats any unicode mode as the strict syntax.
2538
+ // Regular expressions are checked more strictly when either in 'u' or 'v' mode, or
2539
+ // when not using the looser interpretation of the syntax from ECMA-262 Annex B.
2539
2540
var anyUnicodeModeOrNonAnnexB = unicodeMode || ! annexB ;
2540
2541
2541
2542
/** @see {scanClassSetExpression} */
@@ -2699,7 +2700,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
2699
2700
break ;
2700
2701
}
2701
2702
}
2702
- else if ( max && Number . parseInt ( min ) > Number . parseInt ( max ) && ( anyUnicodeModeOrNonAnnexB || text . charCodeAt ( pos ) === CharacterCodes . closeBrace ) ) {
2703
+ else if ( max && Number . parseInt ( min ) > Number . parseInt ( max ) && ( anyUnicodeModeOrNonAnnexB || charCodeChecked ( pos ) === CharacterCodes . closeBrace ) ) {
2703
2704
error ( Diagnostics . Numbers_out_of_order_in_quantifier , digitsStart , pos - digitsStart ) ;
2704
2705
}
2705
2706
}
@@ -3501,9 +3502,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
3501
3502
}
3502
3503
} ) ;
3503
3504
forEach ( decimalEscapes , escape => {
3504
- // in AnnexB, if a DecimalEscape is greater than the number of capturing groups then it is treated as
3505
- // either a LegacyOctalEscapeSequence or IdentityEscape
3506
- if ( anyUnicodeModeOrNonAnnexB && escape . value > numberOfCapturingGroups ) {
3505
+ // Although a DecimalEscape with a value greater than the number of capturing groups
3506
+ // is treated as either a LegacyOctalEscapeSequence or an IdentityEscape in Annex B,
3507
+ // an error is nevertheless reported since it's most likely a mistake.
3508
+ if ( escape . value > numberOfCapturingGroups ) {
3507
3509
if ( numberOfCapturingGroups ) {
3508
3510
error ( Diagnostics . This_backreference_refers_to_a_group_that_does_not_exist_There_are_only_0_capturing_groups_in_this_regular_expression , escape . pos , escape . end - escape . pos , numberOfCapturingGroups ) ;
3509
3511
}
0 commit comments