Skip to content

Commit 0cc62c3

Browse files
Correct Regular Expressions Behavior Related to Annex B (#58320)
Co-authored-by: Ron Buckton <[email protected]>
1 parent fa58c61 commit 0cc62c3

20 files changed

+955
-131
lines changed

src/compiler/diagnosticMessages.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1789,14 +1789,22 @@
17891789
"category": "Error",
17901790
"code": 1533
17911791
},
1792-
"This backreference is invalid because the containing regular expression contains no capturing groups.": {
1792+
"This backreference refers to a group that does not exist. There are no capturing groups in this regular expression.": {
17931793
"category": "Error",
17941794
"code": 1534
17951795
},
17961796
"This character cannot be escaped in a regular expression.": {
17971797
"category": "Error",
17981798
"code": 1535
17991799
},
1800+
"Octal escape sequences and backreferences are not allowed in a character class. If this was intended as an escape sequence, use the syntax '{0}' instead.": {
1801+
"category": "Error",
1802+
"code": 1536
1803+
},
1804+
"Decimal escape sequences and backreferences are not allowed in a character class.": {
1805+
"category": "Error",
1806+
"code": 1537
1807+
},
18001808

18011809
"The types of '{0}' are incompatible between these types.": {
18021810
"category": "Error",

src/compiler/scanner.ts

Lines changed: 98 additions & 39 deletions
Large diffs are not rendered by default.
Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
regularExpressionAnnexB.ts(2,8): error TS1125: Hexadecimal digit expected.
2+
regularExpressionAnnexB.ts(2,22): error TS1125: Hexadecimal digit expected.
3+
regularExpressionAnnexB.ts(2,28): error TS1125: Hexadecimal digit expected.
4+
regularExpressionAnnexB.ts(3,9): error TS1125: Hexadecimal digit expected.
5+
regularExpressionAnnexB.ts(3,23): error TS1125: Hexadecimal digit expected.
6+
regularExpressionAnnexB.ts(3,29): error TS1125: Hexadecimal digit expected.
7+
regularExpressionAnnexB.ts(7,4): error TS1535: This character cannot be escaped in a regular expression.
8+
regularExpressionAnnexB.ts(7,8): error TS1125: Hexadecimal digit expected.
9+
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.
11+
regularExpressionAnnexB.ts(7,14): error TS1535: This character cannot be escaped in a regular expression.
12+
regularExpressionAnnexB.ts(7,18): error TS1535: This character cannot be escaped in a regular expression.
13+
regularExpressionAnnexB.ts(7,22): error TS1125: Hexadecimal digit expected.
14+
regularExpressionAnnexB.ts(7,24): error TS1535: This character cannot be escaped in a regular expression.
15+
regularExpressionAnnexB.ts(7,28): error TS1125: Hexadecimal digit expected.
16+
regularExpressionAnnexB.ts(7,30): error TS1531: '\p' must be followed by a Unicode property value expression enclosed in braces.
17+
regularExpressionAnnexB.ts(8,5): error TS1535: This character cannot be escaped in a regular expression.
18+
regularExpressionAnnexB.ts(8,9): error TS1125: Hexadecimal digit expected.
19+
regularExpressionAnnexB.ts(8,11): error TS1512: '\c' must be followed by an ASCII letter.
20+
regularExpressionAnnexB.ts(8,13): error TS1535: This character cannot be escaped in a regular expression.
21+
regularExpressionAnnexB.ts(8,15): error TS1535: This character cannot be escaped in a regular expression.
22+
regularExpressionAnnexB.ts(8,19): error TS1535: This character cannot be escaped in a regular expression.
23+
regularExpressionAnnexB.ts(8,23): error TS1125: Hexadecimal digit expected.
24+
regularExpressionAnnexB.ts(8,25): error TS1535: This character cannot be escaped in a regular expression.
25+
regularExpressionAnnexB.ts(8,29): error TS1125: Hexadecimal digit expected.
26+
regularExpressionAnnexB.ts(8,31): error TS1531: '\p' must be followed by a Unicode property value expression enclosed in braces.
27+
regularExpressionAnnexB.ts(9,4): error TS1531: '\P' must be followed by a Unicode property value expression enclosed in braces.
28+
regularExpressionAnnexB.ts(9,7): error TS1531: '\P' must be followed by a Unicode property value expression enclosed in braces.
29+
regularExpressionAnnexB.ts(9,9): error TS1516: A character class range must not be bounded by another character class.
30+
regularExpressionAnnexB.ts(23,4): error TS1507: There is nothing available for repetition.
31+
regularExpressionAnnexB.ts(23,8): error TS1507: There is nothing available for repetition.
32+
regularExpressionAnnexB.ts(24,4): error TS1507: There is nothing available for repetition.
33+
regularExpressionAnnexB.ts(24,9): error TS1507: There is nothing available for repetition.
34+
regularExpressionAnnexB.ts(25,4): error TS1507: There is nothing available for repetition.
35+
regularExpressionAnnexB.ts(25,10): error TS1507: There is nothing available for repetition.
36+
regularExpressionAnnexB.ts(26,4): error TS1507: There is nothing available for repetition.
37+
regularExpressionAnnexB.ts(26,5): error TS1506: Numbers out of order in quantifier.
38+
regularExpressionAnnexB.ts(26,10): error TS1507: There is nothing available for repetition.
39+
regularExpressionAnnexB.ts(29,4): error TS1508: Unexpected '{'. Did you mean to escape it with backslash?
40+
regularExpressionAnnexB.ts(30,4): error TS1508: Unexpected '{'. Did you mean to escape it with backslash?
41+
regularExpressionAnnexB.ts(31,4): error TS1507: There is nothing available for repetition.
42+
regularExpressionAnnexB.ts(31,5): error TS1505: Incomplete quantifier. Digit expected.
43+
regularExpressionAnnexB.ts(31,7): error TS1005: '}' expected.
44+
regularExpressionAnnexB.ts(31,8): error TS1507: There is nothing available for repetition.
45+
regularExpressionAnnexB.ts(32,4): error TS1507: There is nothing available for repetition.
46+
regularExpressionAnnexB.ts(32,6): error TS1005: '}' expected.
47+
regularExpressionAnnexB.ts(32,7): error TS1507: There is nothing available for repetition.
48+
regularExpressionAnnexB.ts(33,4): error TS1507: There is nothing available for repetition.
49+
regularExpressionAnnexB.ts(33,7): error TS1005: '}' expected.
50+
regularExpressionAnnexB.ts(33,8): error TS1507: There is nothing available for repetition.
51+
regularExpressionAnnexB.ts(34,4): error TS1507: There is nothing available for repetition.
52+
regularExpressionAnnexB.ts(34,8): error TS1005: '}' expected.
53+
regularExpressionAnnexB.ts(34,9): error TS1507: There is nothing available for repetition.
54+
regularExpressionAnnexB.ts(35,4): error TS1507: There is nothing available for repetition.
55+
regularExpressionAnnexB.ts(35,5): error TS1506: Numbers out of order in quantifier.
56+
regularExpressionAnnexB.ts(35,8): error TS1005: '}' expected.
57+
regularExpressionAnnexB.ts(35,9): error TS1507: There is nothing available for repetition.
58+
regularExpressionAnnexB.ts(36,4): error TS1508: Unexpected '{'. Did you mean to escape it with backslash?
59+
regularExpressionAnnexB.ts(36,5): error TS1508: Unexpected '}'. Did you mean to escape it with backslash?
60+
regularExpressionAnnexB.ts(37,4): error TS1507: There is nothing available for repetition.
61+
regularExpressionAnnexB.ts(37,5): error TS1505: Incomplete quantifier. Digit expected.
62+
regularExpressionAnnexB.ts(37,8): error TS1507: There is nothing available for repetition.
63+
regularExpressionAnnexB.ts(38,4): error TS1507: There is nothing available for repetition.
64+
regularExpressionAnnexB.ts(38,5): error TS1505: Incomplete quantifier. Digit expected.
65+
regularExpressionAnnexB.ts(38,9): error TS1507: There is nothing available for repetition.
66+
regularExpressionAnnexB.ts(39,4): error TS1507: There is nothing available for repetition.
67+
regularExpressionAnnexB.ts(39,8): error TS1507: There is nothing available for repetition.
68+
regularExpressionAnnexB.ts(40,4): error TS1507: There is nothing available for repetition.
69+
regularExpressionAnnexB.ts(40,9): error TS1507: There is nothing available for repetition.
70+
regularExpressionAnnexB.ts(41,4): error TS1507: There is nothing available for repetition.
71+
regularExpressionAnnexB.ts(41,10): error TS1507: There is nothing available for repetition.
72+
regularExpressionAnnexB.ts(42,4): error TS1507: There is nothing available for repetition.
73+
regularExpressionAnnexB.ts(42,5): error TS1506: Numbers out of order in quantifier.
74+
regularExpressionAnnexB.ts(42,10): error TS1507: There is nothing available for repetition.
75+
76+
77+
==== regularExpressionAnnexB.ts (74 errors) ====
78+
const regexes: RegExp[] = [
79+
/\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/,
80+
81+
!!! error TS1125: Hexadecimal digit expected.
82+
83+
!!! error TS1125: Hexadecimal digit expected.
84+
85+
!!! error TS1125: Hexadecimal digit expected.
86+
/[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/,
87+
88+
!!! error TS1125: Hexadecimal digit expected.
89+
90+
!!! error TS1125: Hexadecimal digit expected.
91+
92+
!!! error TS1125: Hexadecimal digit expected.
93+
/\P[\P\w-_]/,
94+
95+
// Compare to
96+
/\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/u,
97+
~~
98+
!!! error TS1535: This character cannot be escaped in a regular expression.
99+
100+
!!! error TS1125: Hexadecimal digit expected.
101+
~~
102+
!!! 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.
105+
~~
106+
!!! error TS1535: This character cannot be escaped in a regular expression.
107+
~~
108+
!!! error TS1535: This character cannot be escaped in a regular expression.
109+
110+
!!! error TS1125: Hexadecimal digit expected.
111+
~~
112+
!!! error TS1535: This character cannot be escaped in a regular expression.
113+
114+
!!! error TS1125: Hexadecimal digit expected.
115+
~~
116+
!!! error TS1531: '\p' must be followed by a Unicode property value expression enclosed in braces.
117+
/[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/u,
118+
~~
119+
!!! error TS1535: This character cannot be escaped in a regular expression.
120+
121+
!!! error TS1125: Hexadecimal digit expected.
122+
~~
123+
!!! error TS1512: '\c' must be followed by an ASCII letter.
124+
~~
125+
!!! error TS1535: This character cannot be escaped in a regular expression.
126+
~~
127+
!!! error TS1535: This character cannot be escaped in a regular expression.
128+
~~
129+
!!! error TS1535: This character cannot be escaped in a regular expression.
130+
131+
!!! error TS1125: Hexadecimal digit expected.
132+
~~
133+
!!! error TS1535: This character cannot be escaped in a regular expression.
134+
135+
!!! error TS1125: Hexadecimal digit expected.
136+
~~
137+
!!! error TS1531: '\p' must be followed by a Unicode property value expression enclosed in braces.
138+
/\P[\P\w-_]/u,
139+
~~
140+
!!! error TS1531: '\P' must be followed by a Unicode property value expression enclosed in braces.
141+
~~
142+
!!! error TS1531: '\P' must be followed by a Unicode property value expression enclosed in braces.
143+
~~
144+
!!! error TS1516: A character class range must not be bounded by another character class.
145+
];
146+
147+
const regexesWithBraces: RegExp[] = [
148+
/{??/,
149+
/{,??/,
150+
/{,1??/,
151+
/{1??/,
152+
/{1,??/,
153+
/{1,2??/,
154+
/{2,1??/,
155+
/{}??/,
156+
/{,}??/,
157+
/{,1}??/,
158+
/{1}??/,
159+
~~~~
160+
!!! error TS1507: There is nothing available for repetition.
161+
~
162+
!!! error TS1507: There is nothing available for repetition.
163+
/{1,}??/,
164+
~~~~~
165+
!!! error TS1507: There is nothing available for repetition.
166+
~
167+
!!! error TS1507: There is nothing available for repetition.
168+
/{1,2}??/,
169+
~~~~~~
170+
!!! error TS1507: There is nothing available for repetition.
171+
~
172+
!!! error TS1507: There is nothing available for repetition.
173+
/{2,1}??/,
174+
~~~~~~
175+
!!! error TS1507: There is nothing available for repetition.
176+
~~~
177+
!!! error TS1506: Numbers out of order in quantifier.
178+
~
179+
!!! error TS1507: There is nothing available for repetition.
180+
181+
// Compare to
182+
/{??/u,
183+
~
184+
!!! error TS1508: Unexpected '{'. Did you mean to escape it with backslash?
185+
/{,??/u,
186+
~
187+
!!! error TS1508: Unexpected '{'. Did you mean to escape it with backslash?
188+
/{,1??/u,
189+
~~~~
190+
!!! error TS1507: There is nothing available for repetition.
191+
192+
!!! error TS1505: Incomplete quantifier. Digit expected.
193+
194+
!!! error TS1005: '}' expected.
195+
~
196+
!!! error TS1507: There is nothing available for repetition.
197+
/{1??/u,
198+
~~~
199+
!!! error TS1507: There is nothing available for repetition.
200+
201+
!!! error TS1005: '}' expected.
202+
~
203+
!!! error TS1507: There is nothing available for repetition.
204+
/{1,??/u,
205+
~~~~
206+
!!! error TS1507: There is nothing available for repetition.
207+
208+
!!! error TS1005: '}' expected.
209+
~
210+
!!! error TS1507: There is nothing available for repetition.
211+
/{1,2??/u,
212+
~~~~~
213+
!!! error TS1507: There is nothing available for repetition.
214+
215+
!!! error TS1005: '}' expected.
216+
~
217+
!!! error TS1507: There is nothing available for repetition.
218+
/{2,1??/u,
219+
~~~~~
220+
!!! error TS1507: There is nothing available for repetition.
221+
~~~
222+
!!! error TS1506: Numbers out of order in quantifier.
223+
224+
!!! error TS1005: '}' expected.
225+
~
226+
!!! error TS1507: There is nothing available for repetition.
227+
/{}??/u,
228+
~
229+
!!! error TS1508: Unexpected '{'. Did you mean to escape it with backslash?
230+
~
231+
!!! error TS1508: Unexpected '}'. Did you mean to escape it with backslash?
232+
/{,}??/u,
233+
~~~~
234+
!!! error TS1507: There is nothing available for repetition.
235+
236+
!!! error TS1505: Incomplete quantifier. Digit expected.
237+
~
238+
!!! error TS1507: There is nothing available for repetition.
239+
/{,1}??/u,
240+
~~~~~
241+
!!! error TS1507: There is nothing available for repetition.
242+
243+
!!! error TS1505: Incomplete quantifier. Digit expected.
244+
~
245+
!!! error TS1507: There is nothing available for repetition.
246+
/{1}??/u,
247+
~~~~
248+
!!! error TS1507: There is nothing available for repetition.
249+
~
250+
!!! error TS1507: There is nothing available for repetition.
251+
/{1,}??/u,
252+
~~~~~
253+
!!! error TS1507: There is nothing available for repetition.
254+
~
255+
!!! error TS1507: There is nothing available for repetition.
256+
/{1,2}??/u,
257+
~~~~~~
258+
!!! error TS1507: There is nothing available for repetition.
259+
~
260+
!!! error TS1507: There is nothing available for repetition.
261+
/{2,1}??/u,
262+
~~~~~~
263+
!!! error TS1507: There is nothing available for repetition.
264+
~~~
265+
!!! error TS1506: Numbers out of order in quantifier.
266+
~
267+
!!! error TS1507: There is nothing available for repetition.
268+
];
269+
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
//// [tests/cases/compiler/regularExpressionAnnexB.ts] ////
2+
3+
//// [regularExpressionAnnexB.ts]
4+
const regexes: RegExp[] = [
5+
/\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/,
6+
/[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/,
7+
/\P[\P\w-_]/,
8+
9+
// Compare to
10+
/\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/u,
11+
/[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/u,
12+
/\P[\P\w-_]/u,
13+
];
14+
15+
const regexesWithBraces: RegExp[] = [
16+
/{??/,
17+
/{,??/,
18+
/{,1??/,
19+
/{1??/,
20+
/{1,??/,
21+
/{1,2??/,
22+
/{2,1??/,
23+
/{}??/,
24+
/{,}??/,
25+
/{,1}??/,
26+
/{1}??/,
27+
/{1,}??/,
28+
/{1,2}??/,
29+
/{2,1}??/,
30+
31+
// Compare to
32+
/{??/u,
33+
/{,??/u,
34+
/{,1??/u,
35+
/{1??/u,
36+
/{1,??/u,
37+
/{1,2??/u,
38+
/{2,1??/u,
39+
/{}??/u,
40+
/{,}??/u,
41+
/{,1}??/u,
42+
/{1}??/u,
43+
/{1,}??/u,
44+
/{1,2}??/u,
45+
/{2,1}??/u,
46+
];
47+
48+
49+
//// [regularExpressionAnnexB.js]
50+
const regexes = [
51+
/\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/,
52+
/[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/,
53+
/\P[\P\w-_]/,
54+
// Compare to
55+
/\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s/u,
56+
/[\q\u\i\c\k\_\f\o\x\-\j\u\m\p\s]/u,
57+
/\P[\P\w-_]/u,
58+
];
59+
const regexesWithBraces = [
60+
/{??/,
61+
/{,??/,
62+
/{,1??/,
63+
/{1??/,
64+
/{1,??/,
65+
/{1,2??/,
66+
/{2,1??/,
67+
/{}??/,
68+
/{,}??/,
69+
/{,1}??/,
70+
/{1}??/,
71+
/{1,}??/,
72+
/{1,2}??/,
73+
/{2,1}??/,
74+
// Compare to
75+
/{??/u,
76+
/{,??/u,
77+
/{,1??/u,
78+
/{1??/u,
79+
/{1,??/u,
80+
/{1,2??/u,
81+
/{2,1??/u,
82+
/{}??/u,
83+
/{,}??/u,
84+
/{,1}??/u,
85+
/{1}??/u,
86+
/{1,}??/u,
87+
/{1,2}??/u,
88+
/{2,1}??/u,
89+
];

0 commit comments

Comments
 (0)