|
1 | 1 | //// [tests/cases/compiler/regularExpressionTypeCheckingMatchExec.ts] ////
|
2 | 2 |
|
3 | 3 | //// [regularExpressionTypeCheckingMatchExec.ts]
|
4 |
| -const dateTimeString = "2048-10-24 12:34:56"; |
5 |
| - |
6 | 4 | // a very loose Temporal (Zoned)DateTime format regex, identical to the one in `tests/cases/conformance/types/literal/regularExpressionLiteralTypes.ts`
|
7 |
| -{ |
8 |
| - const dateTimeRegex = /^(?<date>(?<year>\d{4}|(?!-000000)[+-]\d{6})(?<dateSeparator>-)?(?!(?:0[2469]|11)\k<dateSeparator>31|02\k<dateSeparator>30)(?<month>0[1-9]|1[0-2])\k<dateSeparator>(?<day>0[1-9]|[12]\d|3[01]))(?:[ T](?<time>(?<hour>[01]\d|2[0-3])(?:(?<timeSeparator>:)?(?<minute>[0-5]\d)(?:\k<timeSeparator>(?<second>(?:[0-5]\d|60)(?:[.,]\d{1,9})?))?)?)(?<timeZone>Z|(?<timeZoneSign>[+-])(?:(?<timeZoneHour>[01]\d|2[0-3])(?:(?<timeZoneTimeSeparator>:)?(?<timeZoneMinute>[0-5]\d)(?:\k<timeZoneTimeSeparator>(?<timeZoneSecond>[0-5]\d(?:[.,]\d{1,9})?))?)?))?)?$/i; |
9 |
| - |
10 |
| - let match = dateTimeString.match(dateTimeRegex)!; // RegExpExecArray |
11 |
| - match.index; // number |
12 |
| - match.input; // string |
13 |
| - match.length; // 17 |
14 |
| - match[0].length; // number |
15 |
| - match[1].length; // number |
16 |
| - match[2].length; // number |
17 |
| - match[3]?.length; // number | undefined |
18 |
| - match[4].length; // number |
19 |
| - match[5].length; // number |
20 |
| - match[6]?.length; // number | undefined |
21 |
| - match[16]?.length; // number | undefined |
22 |
| - match[17]; // should error, but see #45560#issuecomment-1111121849 |
23 |
| - match.groups.date.length; // number |
24 |
| - match.groups.year.length; // number |
25 |
| - match.groups.month.length; // number |
26 |
| - match.groups.day.length; // number |
27 |
| - match.groups.time?.length; // number | undefined |
28 |
| - match.groups.hour?.length; // number | undefined |
29 |
| - match.groups.minute?.length; // number | undefined |
30 |
| - match.groups.second?.length; // number | undefined |
31 |
| - match.groups.timeZone?.length; // number | undefined |
32 |
| - match.groups.timeZoneSecond?.length; // number | undefined |
33 |
| - match.groups.foo; // error |
34 |
| - match.indices; // error |
35 |
| - |
36 |
| - let execResult = dateTimeRegex.exec(dateTimeString)!; |
37 |
| - match = execResult; // should not error |
38 |
| - execResult = match; // should not error |
39 |
| -} |
40 |
| - |
41 |
| -{ |
42 |
| - const globalDateTimeRegex = /(?<date>(?<year>\d{4}|(?!-000000)[+-]\d{6})(?<dateSeparator>-)?(?!(?:0[2469]|11)\k<dateSeparator>31|02\k<dateSeparator>30)(?<month>0[1-9]|1[0-2])\k<dateSeparator>(?<day>0[1-9]|[12]\d|3[01]))(?:[ T](?<time>(?<hour>[01]\d|2[0-3])(?:(?<timeSeparator>:)?(?<minute>[0-5]\d)(?:\k<timeSeparator>(?<second>(?:[0-5]\d|60)(?:[.,]\d{1,9})?))?)?)(?<timeZone>Z|(?<timeZoneSign>[+-])(?:(?<timeZoneHour>[01]\d|2[0-3])(?:(?<timeZoneTimeSeparator>:)?(?<timeZoneMinute>[0-5]\d)(?:\k<timeZoneTimeSeparator>(?<timeZoneSecond>[0-5]\d(?:[.,]\d{1,9})?))?)?))?)?/ig; |
43 |
| - |
44 |
| - let match = dateTimeString.match(globalDateTimeRegex)!; // RegExpMatchArray |
45 |
| - match.index; // error |
46 |
| - match.input; // error |
47 |
| - match.length; // number |
48 |
| - match[0].length; // number |
49 |
| - match[1]?.length; // number | undefined |
50 |
| - match[99]?.length; // number | undefined |
51 |
| - match.groups; // error |
52 |
| - match.indices; // error |
53 |
| - |
54 |
| - let execResult = globalDateTimeRegex.exec(dateTimeString)!; |
55 |
| - match = execResult; // should error |
56 |
| - execResult = match; // should error |
57 |
| -} |
58 |
| - |
59 |
| -{ |
60 |
| - const dateTimeRegexWithIndices = /(?<date>(?<year>\d{4}|(?!-000000)[+-]\d{6})(?<dateSeparator>-)?(?!(?:0[2469]|11)\k<dateSeparator>31|02\k<dateSeparator>30)(?<month>0[1-9]|1[0-2])\k<dateSeparator>(?<day>0[1-9]|[12]\d|3[01]))(?:[ T](?<time>(?<hour>[01]\d|2[0-3])(?:(?<timeSeparator>:)?(?<minute>[0-5]\d)(?:\k<timeSeparator>(?<second>(?:[0-5]\d|60)(?:[.,]\d{1,9})?))?)?)(?<timeZone>Z|(?<timeZoneSign>[+-])(?:(?<timeZoneHour>[01]\d|2[0-3])(?:(?<timeZoneTimeSeparator>:)?(?<timeZoneMinute>[0-5]\d)(?:\k<timeZoneTimeSeparator>(?<timeZoneSecond>[0-5]\d(?:[.,]\d{1,9})?))?)?))?)?/id; |
61 |
| - |
62 |
| - let match = dateTimeString.match(dateTimeRegexWithIndices)!; // RegExpExecArray |
63 |
| - match.index; // number |
64 |
| - match.input; // string |
65 |
| - match.length; // 17 |
66 |
| - match[0].length; // number |
67 |
| - match[1].length; // number |
68 |
| - match[16]?.length; // number | undefined |
69 |
| - match[17]; // should error, but see #45560#issuecomment-1111121849 |
70 |
| - match.groups.date.length; // number |
71 |
| - match.groups.timeZoneSecond?.length; // number | undefined |
72 |
| - match.groups.foo; // error |
| 5 | +const dateTimeRegex = /^(?<date>(?<year>\d{4}|(?!-000000)[+-]\d{6})(?<dateSeparator>-)?(?!(?:0[2469]|11)\k<dateSeparator>31|02\k<dateSeparator>30)(?<month>0[1-9]|1[0-2])\k<dateSeparator>(?<day>0[1-9]|[12]\d|3[01]))(?:[ T](?<time>(?<hour>[01]\d|2[0-3])(?:(?<timeSeparator>:)?(?<minute>[0-5]\d)(?:\k<timeSeparator>(?<second>(?:[0-5]\d|60)(?:[.,]\d{1,9})?))?)?)(?<timeZone>Z|(?<timeZoneSign>[+-])(?:(?<timeZoneHour>[01]\d|2[0-3])(?:(?<timeZoneTimeSeparator>:)?(?<timeZoneMinute>[0-5]\d)(?:\k<timeZoneTimeSeparator>(?<timeZoneSecond>[0-5]\d(?:[.,]\d{1,9})?))?)?))?)?$/i; |
| 6 | +const dateTimeString = "2048-10-24 12:34:56"; |
73 | 7 |
|
74 |
| - // Each element is of type [startIndex: number, endIndex: number] |
75 |
| - match.indices.length; // 17 |
76 |
| - match.indices[0].length; // 2 |
77 |
| - match.indices[1].length; // 2 |
78 |
| - match.indices[2].length; // 2 |
79 |
| - match.indices[3]?.length; // 2 | undefined |
80 |
| - match.indices[4].length; // 2 |
81 |
| - match.indices[5].length; // 2 |
82 |
| - match.indices[6]?.length; // 2 | undefined |
83 |
| - match.indices[16]?.length; // 2 | undefined |
84 |
| - match.indices[17]; // should error, but see #45560#issuecomment-1111121849 |
85 |
| - match.indices.groups.date.length; // 2 |
86 |
| - match.indices.groups.year.length; // 2 |
87 |
| - match.indices.groups.month.length; // 2 |
88 |
| - match.indices.groups.day.length; // 2 |
89 |
| - match.indices.groups.time?.length; // 2 | undefined |
90 |
| - match.indices.groups.hour?.length; // 2 | undefined |
91 |
| - match.indices.groups.minute?.length; // 2 | undefined |
92 |
| - match.indices.groups.second?.length; // 2 | undefined |
93 |
| - match.indices.groups.timeZone?.length; // 2 | undefined |
94 |
| - match.indices.groups.timeZoneSecond?.length; // 2 | undefined |
95 |
| - match.indices.groups.foo; // error |
| 8 | +let match = dateTimeString.match(dateTimeRegex)!; // RegExpExecArray |
| 9 | +match.index; // number |
| 10 | +match.input; // string |
| 11 | +match.length; // 17 |
| 12 | +match[0].length; // number |
| 13 | +match[1].length; // number |
| 14 | +match[2].length; // number |
| 15 | +match[3]?.length; // number | undefined |
| 16 | +match[4].length; // number |
| 17 | +match[5].length; // number |
| 18 | +match[6]?.length; // number | undefined |
| 19 | +match[16]?.length; // number | undefined |
| 20 | +match[17]; // should error, but see #45560#issuecomment-1111121849 |
| 21 | +match.groups.date.length; // number |
| 22 | +match.groups.year.length; // number |
| 23 | +match.groups.month.length; // number |
| 24 | +match.groups.day.length; // number |
| 25 | +match.groups.time?.length; // number | undefined |
| 26 | +match.groups.hour?.length; // number | undefined |
| 27 | +match.groups.minute?.length; // number | undefined |
| 28 | +match.groups.second?.length; // number | undefined |
| 29 | +match.groups.timeZone?.length; // number | undefined |
| 30 | +match.groups.timeZoneSecond?.length; // number | undefined |
| 31 | +match.groups.foo; // error |
| 32 | +match.indices; // error |
96 | 33 |
|
97 |
| - let execResult = dateTimeRegexWithIndices.exec(dateTimeString)!; |
98 |
| - match = execResult; // should not error |
99 |
| - execResult = match; // should not error |
100 |
| -} |
| 34 | +let execResult = dateTimeRegex.exec(dateTimeString)!; |
| 35 | +match = execResult; // should not error |
| 36 | +execResult = match; // should not error |
101 | 37 |
|
102 | 38 |
|
103 | 39 | //// [regularExpressionTypeCheckingMatchExec.js]
|
104 | 40 | "use strict";
|
105 |
| -const dateTimeString = "2048-10-24 12:34:56"; |
106 | 41 | // a very loose Temporal (Zoned)DateTime format regex, identical to the one in `tests/cases/conformance/types/literal/regularExpressionLiteralTypes.ts`
|
107 |
| -{ |
108 |
| - const dateTimeRegex = /^(?<date>(?<year>\d{4}|(?!-000000)[+-]\d{6})(?<dateSeparator>-)?(?!(?:0[2469]|11)\k<dateSeparator>31|02\k<dateSeparator>30)(?<month>0[1-9]|1[0-2])\k<dateSeparator>(?<day>0[1-9]|[12]\d|3[01]))(?:[ T](?<time>(?<hour>[01]\d|2[0-3])(?:(?<timeSeparator>:)?(?<minute>[0-5]\d)(?:\k<timeSeparator>(?<second>(?:[0-5]\d|60)(?:[.,]\d{1,9})?))?)?)(?<timeZone>Z|(?<timeZoneSign>[+-])(?:(?<timeZoneHour>[01]\d|2[0-3])(?:(?<timeZoneTimeSeparator>:)?(?<timeZoneMinute>[0-5]\d)(?:\k<timeZoneTimeSeparator>(?<timeZoneSecond>[0-5]\d(?:[.,]\d{1,9})?))?)?))?)?$/i; |
109 |
| - let match = dateTimeString.match(dateTimeRegex); // RegExpExecArray |
110 |
| - match.index; // number |
111 |
| - match.input; // string |
112 |
| - match.length; // 17 |
113 |
| - match[0].length; // number |
114 |
| - match[1].length; // number |
115 |
| - match[2].length; // number |
116 |
| - match[3]?.length; // number | undefined |
117 |
| - match[4].length; // number |
118 |
| - match[5].length; // number |
119 |
| - match[6]?.length; // number | undefined |
120 |
| - match[16]?.length; // number | undefined |
121 |
| - match[17]; // should error, but see #45560#issuecomment-1111121849 |
122 |
| - match.groups.date.length; // number |
123 |
| - match.groups.year.length; // number |
124 |
| - match.groups.month.length; // number |
125 |
| - match.groups.day.length; // number |
126 |
| - match.groups.time?.length; // number | undefined |
127 |
| - match.groups.hour?.length; // number | undefined |
128 |
| - match.groups.minute?.length; // number | undefined |
129 |
| - match.groups.second?.length; // number | undefined |
130 |
| - match.groups.timeZone?.length; // number | undefined |
131 |
| - match.groups.timeZoneSecond?.length; // number | undefined |
132 |
| - match.groups.foo; // error |
133 |
| - match.indices; // error |
134 |
| - let execResult = dateTimeRegex.exec(dateTimeString); |
135 |
| - match = execResult; // should not error |
136 |
| - execResult = match; // should not error |
137 |
| -} |
138 |
| -{ |
139 |
| - const globalDateTimeRegex = /(?<date>(?<year>\d{4}|(?!-000000)[+-]\d{6})(?<dateSeparator>-)?(?!(?:0[2469]|11)\k<dateSeparator>31|02\k<dateSeparator>30)(?<month>0[1-9]|1[0-2])\k<dateSeparator>(?<day>0[1-9]|[12]\d|3[01]))(?:[ T](?<time>(?<hour>[01]\d|2[0-3])(?:(?<timeSeparator>:)?(?<minute>[0-5]\d)(?:\k<timeSeparator>(?<second>(?:[0-5]\d|60)(?:[.,]\d{1,9})?))?)?)(?<timeZone>Z|(?<timeZoneSign>[+-])(?:(?<timeZoneHour>[01]\d|2[0-3])(?:(?<timeZoneTimeSeparator>:)?(?<timeZoneMinute>[0-5]\d)(?:\k<timeZoneTimeSeparator>(?<timeZoneSecond>[0-5]\d(?:[.,]\d{1,9})?))?)?))?)?/ig; |
140 |
| - let match = dateTimeString.match(globalDateTimeRegex); // RegExpMatchArray |
141 |
| - match.index; // error |
142 |
| - match.input; // error |
143 |
| - match.length; // number |
144 |
| - match[0].length; // number |
145 |
| - match[1]?.length; // number | undefined |
146 |
| - match[99]?.length; // number | undefined |
147 |
| - match.groups; // error |
148 |
| - match.indices; // error |
149 |
| - let execResult = globalDateTimeRegex.exec(dateTimeString); |
150 |
| - match = execResult; // should error |
151 |
| - execResult = match; // should error |
152 |
| -} |
153 |
| -{ |
154 |
| - const dateTimeRegexWithIndices = /(?<date>(?<year>\d{4}|(?!-000000)[+-]\d{6})(?<dateSeparator>-)?(?!(?:0[2469]|11)\k<dateSeparator>31|02\k<dateSeparator>30)(?<month>0[1-9]|1[0-2])\k<dateSeparator>(?<day>0[1-9]|[12]\d|3[01]))(?:[ T](?<time>(?<hour>[01]\d|2[0-3])(?:(?<timeSeparator>:)?(?<minute>[0-5]\d)(?:\k<timeSeparator>(?<second>(?:[0-5]\d|60)(?:[.,]\d{1,9})?))?)?)(?<timeZone>Z|(?<timeZoneSign>[+-])(?:(?<timeZoneHour>[01]\d|2[0-3])(?:(?<timeZoneTimeSeparator>:)?(?<timeZoneMinute>[0-5]\d)(?:\k<timeZoneTimeSeparator>(?<timeZoneSecond>[0-5]\d(?:[.,]\d{1,9})?))?)?))?)?/id; |
155 |
| - let match = dateTimeString.match(dateTimeRegexWithIndices); // RegExpExecArray |
156 |
| - match.index; // number |
157 |
| - match.input; // string |
158 |
| - match.length; // 17 |
159 |
| - match[0].length; // number |
160 |
| - match[1].length; // number |
161 |
| - match[16]?.length; // number | undefined |
162 |
| - match[17]; // should error, but see #45560#issuecomment-1111121849 |
163 |
| - match.groups.date.length; // number |
164 |
| - match.groups.timeZoneSecond?.length; // number | undefined |
165 |
| - match.groups.foo; // error |
166 |
| - // Each element is of type [startIndex: number, endIndex: number] |
167 |
| - match.indices.length; // 17 |
168 |
| - match.indices[0].length; // 2 |
169 |
| - match.indices[1].length; // 2 |
170 |
| - match.indices[2].length; // 2 |
171 |
| - match.indices[3]?.length; // 2 | undefined |
172 |
| - match.indices[4].length; // 2 |
173 |
| - match.indices[5].length; // 2 |
174 |
| - match.indices[6]?.length; // 2 | undefined |
175 |
| - match.indices[16]?.length; // 2 | undefined |
176 |
| - match.indices[17]; // should error, but see #45560#issuecomment-1111121849 |
177 |
| - match.indices.groups.date.length; // 2 |
178 |
| - match.indices.groups.year.length; // 2 |
179 |
| - match.indices.groups.month.length; // 2 |
180 |
| - match.indices.groups.day.length; // 2 |
181 |
| - match.indices.groups.time?.length; // 2 | undefined |
182 |
| - match.indices.groups.hour?.length; // 2 | undefined |
183 |
| - match.indices.groups.minute?.length; // 2 | undefined |
184 |
| - match.indices.groups.second?.length; // 2 | undefined |
185 |
| - match.indices.groups.timeZone?.length; // 2 | undefined |
186 |
| - match.indices.groups.timeZoneSecond?.length; // 2 | undefined |
187 |
| - match.indices.groups.foo; // error |
188 |
| - let execResult = dateTimeRegexWithIndices.exec(dateTimeString); |
189 |
| - match = execResult; // should not error |
190 |
| - execResult = match; // should not error |
191 |
| -} |
| 42 | +const dateTimeRegex = /^(?<date>(?<year>\d{4}|(?!-000000)[+-]\d{6})(?<dateSeparator>-)?(?!(?:0[2469]|11)\k<dateSeparator>31|02\k<dateSeparator>30)(?<month>0[1-9]|1[0-2])\k<dateSeparator>(?<day>0[1-9]|[12]\d|3[01]))(?:[ T](?<time>(?<hour>[01]\d|2[0-3])(?:(?<timeSeparator>:)?(?<minute>[0-5]\d)(?:\k<timeSeparator>(?<second>(?:[0-5]\d|60)(?:[.,]\d{1,9})?))?)?)(?<timeZone>Z|(?<timeZoneSign>[+-])(?:(?<timeZoneHour>[01]\d|2[0-3])(?:(?<timeZoneTimeSeparator>:)?(?<timeZoneMinute>[0-5]\d)(?:\k<timeZoneTimeSeparator>(?<timeZoneSecond>[0-5]\d(?:[.,]\d{1,9})?))?)?))?)?$/i; |
| 43 | +const dateTimeString = "2048-10-24 12:34:56"; |
| 44 | +let match = dateTimeString.match(dateTimeRegex); // RegExpExecArray |
| 45 | +match.index; // number |
| 46 | +match.input; // string |
| 47 | +match.length; // 17 |
| 48 | +match[0].length; // number |
| 49 | +match[1].length; // number |
| 50 | +match[2].length; // number |
| 51 | +match[3]?.length; // number | undefined |
| 52 | +match[4].length; // number |
| 53 | +match[5].length; // number |
| 54 | +match[6]?.length; // number | undefined |
| 55 | +match[16]?.length; // number | undefined |
| 56 | +match[17]; // should error, but see #45560#issuecomment-1111121849 |
| 57 | +match.groups.date.length; // number |
| 58 | +match.groups.year.length; // number |
| 59 | +match.groups.month.length; // number |
| 60 | +match.groups.day.length; // number |
| 61 | +match.groups.time?.length; // number | undefined |
| 62 | +match.groups.hour?.length; // number | undefined |
| 63 | +match.groups.minute?.length; // number | undefined |
| 64 | +match.groups.second?.length; // number | undefined |
| 65 | +match.groups.timeZone?.length; // number | undefined |
| 66 | +match.groups.timeZoneSecond?.length; // number | undefined |
| 67 | +match.groups.foo; // error |
| 68 | +match.indices; // error |
| 69 | +let execResult = dateTimeRegex.exec(dateTimeString); |
| 70 | +match = execResult; // should not error |
| 71 | +execResult = match; // should not error |
0 commit comments