Skip to content

Commit c72f92f

Browse files
Fix Behavior Related to namedCaptureGroups
1 parent b48f0d0 commit c72f92f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/compiler/scanner.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,8 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
24902490
inCharacterClass = false;
24912491
}
24922492
else if (
2493-
ch === CharacterCodes.openParen
2493+
!inCharacterClass
2494+
&& ch === CharacterCodes.openParen
24942495
&& charCodeChecked(pos + 1) === CharacterCodes.question
24952496
&& charCodeChecked(pos + 2) === CharacterCodes.lessThan
24962497
&& charCodeChecked(pos + 3) !== CharacterCodes.equals
@@ -2877,7 +2878,7 @@ export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean
28772878
scanGroupName(/*isReference*/ true);
28782879
scanExpectedChar(CharacterCodes.greaterThan);
28792880
}
2880-
else if (namedCaptureGroups) {
2881+
else if (anyUnicodeModeOrNonAnnexB || namedCaptureGroups) {
28812882
error(Diagnostics.k_must_be_followed_by_a_capturing_group_name_enclosed_in_angle_brackets, pos - 2, 2);
28822883
}
28832884
break;

tests/baselines/reference/regularExpressionAnnexB.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ regularExpressionAnnexB.ts(3,29): error TS1125: Hexadecimal digit expected.
77
regularExpressionAnnexB.ts(7,4): error TS1535: This character cannot be escaped in a regular expression.
88
regularExpressionAnnexB.ts(7,8): error TS1125: Hexadecimal digit expected.
99
regularExpressionAnnexB.ts(7,10): error TS1512: '\c' must be followed by an ASCII letter.
10+
regularExpressionAnnexB.ts(7,12): error TS1510: '\k' must be followed by a capturing group name enclosed in angle brackets.
1011
regularExpressionAnnexB.ts(7,14): error TS1535: This character cannot be escaped in a regular expression.
1112
regularExpressionAnnexB.ts(7,18): error TS1535: This character cannot be escaped in a regular expression.
1213
regularExpressionAnnexB.ts(7,22): error TS1125: Hexadecimal digit expected.
@@ -73,7 +74,7 @@ regularExpressionAnnexB.ts(42,5): error TS1506: Numbers out of order in quantifi
7374
regularExpressionAnnexB.ts(42,10): error TS1507: There is nothing available for repetition.
7475

7576

76-
==== regularExpressionAnnexB.ts (73 errors) ====
77+
==== regularExpressionAnnexB.ts (74 errors) ====
7778
const regexes: RegExp[] = [
7879
/\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/,
7980

@@ -99,6 +100,8 @@ regularExpressionAnnexB.ts(42,10): error TS1507: There is nothing available for
99100
!!! error TS1125: Hexadecimal digit expected.
100101
~~
101102
!!! error TS1512: '\c' must be followed by an ASCII letter.
103+
~~
104+
!!! error TS1510: '\k' must be followed by a capturing group name enclosed in angle brackets.
102105
~~
103106
!!! error TS1535: This character cannot be escaped in a regular expression.
104107
~~

0 commit comments

Comments
 (0)