Skip to content

Commit 04cc2c5

Browse files
Apply Suggested Changes
1 parent 2e62d25 commit 04cc2c5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/compiler/scanner.ts

+11-9
Original file line numberDiff line numberDiff line change
@@ -2470,10 +2470,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
24702470
}
24712471
else if (
24722472
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
24772477
) {
24782478
namedCaptureGroups = true;
24792479
}
@@ -2535,7 +2535,8 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
25352535
/** Grammar parameter */
25362536
var unicodeMode = !!(regExpFlags & RegularExpressionFlags.UnicodeMode);
25372537

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.
25392540
var anyUnicodeModeOrNonAnnexB = unicodeMode || !annexB;
25402541

25412542
/** @see {scanClassSetExpression} */
@@ -2699,7 +2700,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
26992700
break;
27002701
}
27012702
}
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)) {
27032704
error(Diagnostics.Numbers_out_of_order_in_quantifier, digitsStart, pos - digitsStart);
27042705
}
27052706
}
@@ -3501,9 +3502,10 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
35013502
}
35023503
});
35033504
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) {
35073509
if (numberOfCapturingGroups) {
35083510
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);
35093511
}

0 commit comments

Comments
 (0)