Skip to content

Commit 06d49b5

Browse files
committed
Fix incorrect regexp matching when followed by comment
Fixes #717
1 parent e632043 commit 06d49b5

File tree

6 files changed

+296
-7
lines changed

6 files changed

+296
-7
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,7 +2519,7 @@ repository:
25192519
regex:
25202520
patterns:
25212521
- name: string.regexp.ts
2522-
begin: (?<!\+\+|--|})(?<=[=(:,\[?+!]|{{lookBehindReturn}}|{{lookBehindCase}}|=>|&&|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))
2522+
begin: (?<!\+\+|--|})(?<=[=(:,\[?+!]|{{lookBehindReturn}}|{{lookBehindCase}}|=>|&&|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[\()]|\\.|\[([^\]\\]|\\.)+\]|\(([^\)\\]|\\.)+\))+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))
25232523
beginCaptures:
25242524
'1': { name: punctuation.definition.string.begin.ts }
25252525
end: (/)([gimsuy]*)
@@ -2530,7 +2530,7 @@ repository:
25302530
- include: '#regexp'
25312531
# Check if complete regexp syntax
25322532
- name: string.regexp.ts
2533-
begin: (?<![_$[:alnum:])\]]|\+\+|--|})\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))
2533+
begin: (?<![_$[:alnum:])\]]|\+\+|--|}|\*\/)\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))
25342534
beginCaptures:
25352535
'0': { name: punctuation.definition.string.begin.ts }
25362536
end: (/)([gimsuy]*)

TypeScript.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7600,7 +7600,7 @@
76007600
<key>name</key>
76017601
<string>string.regexp.ts</string>
76027602
<key>begin</key>
7603-
<string>(?&lt;!\+\+|--|})(?&lt;=[=(:,\[?+!]|^return|[^\._$[:alnum:]]return|^case|[^\._$[:alnum:]]case|=&gt;|&amp;&amp;|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))</string>
7603+
<string>(?&lt;!\+\+|--|})(?&lt;=[=(:,\[?+!]|^return|[^\._$[:alnum:]]return|^case|[^\._$[:alnum:]]case|=&gt;|&amp;&amp;|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[\()]|\\.|\[([^\]\\]|\\.)+\]|\(([^\)\\]|\\.)+\))+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))</string>
76047604
<key>beginCaptures</key>
76057605
<dict>
76067606
<key>1</key>
@@ -7636,7 +7636,7 @@
76367636
<key>name</key>
76377637
<string>string.regexp.ts</string>
76387638
<key>begin</key>
7639-
<string>(?&lt;![_$[:alnum:])\]]|\+\+|--|})\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))</string>
7639+
<string>(?&lt;![_$[:alnum:])\]]|\+\+|--|}|\*\/)\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))</string>
76407640
<key>beginCaptures</key>
76417641
<dict>
76427642
<key>0</key>

TypeScriptReact.tmLanguage

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7522,7 +7522,7 @@
75227522
<key>name</key>
75237523
<string>string.regexp.tsx</string>
75247524
<key>begin</key>
7525-
<string>(?&lt;!\+\+|--|})(?&lt;=[=(:,\[?+!]|^return|[^\._$[:alnum:]]return|^case|[^\._$[:alnum:]]case|=&gt;|&amp;&amp;|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))</string>
7525+
<string>(?&lt;!\+\+|--|})(?&lt;=[=(:,\[?+!]|^return|[^\._$[:alnum:]]return|^case|[^\._$[:alnum:]]case|=&gt;|&amp;&amp;|\|\||\*\/)\s*(\/)(?![\/*])(?=(?:[^\/\\\[\()]|\\.|\[([^\]\\]|\\.)+\]|\(([^\)\\]|\\.)+\))+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))</string>
75267526
<key>beginCaptures</key>
75277527
<dict>
75287528
<key>1</key>
@@ -7558,7 +7558,7 @@
75587558
<key>name</key>
75597559
<string>string.regexp.tsx</string>
75607560
<key>begin</key>
7561-
<string>(?&lt;![_$[:alnum:])\]]|\+\+|--|})\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))</string>
7561+
<string>(?&lt;![_$[:alnum:])\]]|\+\+|--|}|\*\/)\/(?![\/*])(?=(?:[^\/\\\[]|\\.|\[([^\]\\]|\\.)+\])+\/[gimsuy]*(?!\s*[a-zA-Z0-9_$]))</string>
75627562
<key>beginCaptures</key>
75637563
<dict>
75647564
<key>0</key>

tests/baselines/Issue717.baseline.txt

Lines changed: 268 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,268 @@
1+
original file
2+
-----------------------------------
3+
/* regex? */
4+
function test() {
5+
return /"/.test('xxx"xxx');
6+
}
7+
8+
console.log(test());
9+
a = 3 /*test*/ / parseInt(/.+/.exec('3f23fg')[0]);
10+
console.log(a);
11+
12+
b = 1
13+
a = () => b
14+
2 + (b=2), 3
15+
b = 6
16+
console.log(a(),b);
17+
(b)
18+
19+
if (a === 1) {
20+
b = 2
21+
} else if (a === 2) b = 3
22+
else b = 4
23+
c = 1
24+
-----------------------------------
25+
26+
Grammar: TypeScript.tmLanguage
27+
-----------------------------------
28+
>/* regex? */
29+
^^
30+
source.ts comment.block.ts punctuation.definition.comment.ts
31+
^^^^^^^^
32+
source.ts comment.block.ts
33+
^^
34+
source.ts comment.block.ts punctuation.definition.comment.ts
35+
>function test() {
36+
^^^^^^^^
37+
source.ts meta.function.ts storage.type.function.ts
38+
^
39+
source.ts meta.function.ts
40+
^^^^
41+
source.ts meta.function.ts meta.definition.function.ts entity.name.function.ts
42+
^
43+
source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
44+
^
45+
source.ts meta.function.ts meta.parameters.ts punctuation.definition.parameters.end.ts
46+
^
47+
source.ts meta.function.ts
48+
^
49+
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts
50+
> return /"/.test('xxx"xxx');
51+
^^^
52+
source.ts meta.function.ts meta.block.ts
53+
^^^^^^
54+
source.ts meta.function.ts meta.block.ts keyword.control.flow.ts
55+
^
56+
source.ts meta.function.ts meta.block.ts string.regexp.ts
57+
^
58+
source.ts meta.function.ts meta.block.ts string.regexp.ts punctuation.definition.string.begin.ts
59+
^
60+
source.ts meta.function.ts meta.block.ts string.regexp.ts
61+
^
62+
source.ts meta.function.ts meta.block.ts string.regexp.ts punctuation.definition.string.end.ts
63+
^
64+
source.ts meta.function.ts meta.block.ts meta.function-call.ts punctuation.accessor.ts
65+
^^^^
66+
source.ts meta.function.ts meta.block.ts meta.function-call.ts support.function.ts
67+
^
68+
source.ts meta.function.ts meta.block.ts meta.brace.round.ts
69+
^
70+
source.ts meta.function.ts meta.block.ts string.quoted.single.ts punctuation.definition.string.begin.ts
71+
^^^^^^^
72+
source.ts meta.function.ts meta.block.ts string.quoted.single.ts
73+
^
74+
source.ts meta.function.ts meta.block.ts string.quoted.single.ts punctuation.definition.string.end.ts
75+
^
76+
source.ts meta.function.ts meta.block.ts meta.brace.round.ts
77+
^
78+
source.ts meta.function.ts meta.block.ts punctuation.terminator.statement.ts
79+
>}
80+
^
81+
source.ts meta.function.ts meta.block.ts punctuation.definition.block.ts
82+
>
83+
^
84+
source.ts
85+
>console.log(test());
86+
^^^^^^^
87+
source.ts meta.function-call.ts support.class.console.ts
88+
^
89+
source.ts meta.function-call.ts punctuation.accessor.ts
90+
^^^
91+
source.ts meta.function-call.ts support.function.console.ts
92+
^
93+
source.ts meta.brace.round.ts
94+
^^^^
95+
source.ts meta.function-call.ts entity.name.function.ts
96+
^
97+
source.ts meta.brace.round.ts
98+
^
99+
source.ts meta.brace.round.ts
100+
^
101+
source.ts meta.brace.round.ts
102+
^
103+
source.ts punctuation.terminator.statement.ts
104+
>a = 3 /*test*/ / parseInt(/.+/.exec('3f23fg')[0]);
105+
^
106+
source.ts variable.other.readwrite.ts
107+
^
108+
source.ts
109+
^
110+
source.ts keyword.operator.assignment.ts
111+
^
112+
source.ts
113+
^
114+
source.ts constant.numeric.decimal.ts
115+
^
116+
source.ts
117+
^^
118+
source.ts comment.block.ts punctuation.definition.comment.ts
119+
^^^^
120+
source.ts comment.block.ts
121+
^^
122+
source.ts comment.block.ts punctuation.definition.comment.ts
123+
^
124+
source.ts
125+
^
126+
source.ts string.regexp.ts punctuation.definition.string.begin.ts
127+
^^^^^^^^^
128+
source.ts string.regexp.ts
129+
^
130+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
131+
^
132+
source.ts string.regexp.ts meta.group.regexp
133+
^
134+
source.ts string.regexp.ts meta.group.regexp constant.other.character-class.regexp
135+
^
136+
source.ts string.regexp.ts meta.group.regexp keyword.operator.quantifier.regexp
137+
^
138+
source.ts string.regexp.ts meta.group.regexp
139+
^
140+
source.ts string.regexp.ts meta.group.regexp constant.other.character-class.regexp
141+
^^^^
142+
source.ts string.regexp.ts meta.group.regexp
143+
^
144+
source.ts string.regexp.ts meta.group.regexp meta.group.regexp punctuation.definition.group.regexp
145+
^^^^^^^^
146+
source.ts string.regexp.ts meta.group.regexp meta.group.regexp
147+
^
148+
source.ts string.regexp.ts meta.group.regexp meta.group.regexp punctuation.definition.group.regexp
149+
^
150+
source.ts string.regexp.ts meta.group.regexp constant.other.character-class.set.regexp punctuation.definition.character-class.regexp
151+
^
152+
source.ts string.regexp.ts meta.group.regexp constant.other.character-class.set.regexp
153+
^
154+
source.ts string.regexp.ts meta.group.regexp constant.other.character-class.set.regexp punctuation.definition.character-class.regexp
155+
^
156+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
157+
^^
158+
source.ts string.regexp.ts
159+
>console.log(a);
160+
^^^^^^^
161+
source.ts string.regexp.ts
162+
^
163+
source.ts string.regexp.ts constant.other.character-class.regexp
164+
^^^
165+
source.ts string.regexp.ts
166+
^
167+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
168+
^
169+
source.ts string.regexp.ts meta.group.regexp
170+
^
171+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
172+
^^
173+
source.ts string.regexp.ts
174+
>
175+
^
176+
source.ts string.regexp.ts
177+
>b = 1
178+
^^^^^^
179+
source.ts string.regexp.ts
180+
>a = () => b
181+
^^^^
182+
source.ts string.regexp.ts
183+
^
184+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
185+
^
186+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
187+
^^^^^^
188+
source.ts string.regexp.ts
189+
>2 + (b=2), 3
190+
^^
191+
source.ts string.regexp.ts
192+
^
193+
source.ts string.regexp.ts keyword.operator.quantifier.regexp
194+
^
195+
source.ts string.regexp.ts
196+
^
197+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
198+
^^^
199+
source.ts string.regexp.ts meta.group.regexp
200+
^
201+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
202+
^^^^
203+
source.ts string.regexp.ts
204+
>b = 6
205+
^^^^^^
206+
source.ts string.regexp.ts
207+
>console.log(a(),b);
208+
^^^^^^^
209+
source.ts string.regexp.ts
210+
^
211+
source.ts string.regexp.ts constant.other.character-class.regexp
212+
^^^
213+
source.ts string.regexp.ts
214+
^
215+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
216+
^
217+
source.ts string.regexp.ts meta.group.regexp
218+
^
219+
source.ts string.regexp.ts meta.group.regexp meta.group.regexp punctuation.definition.group.regexp
220+
^
221+
source.ts string.regexp.ts meta.group.regexp meta.group.regexp punctuation.definition.group.regexp
222+
^^
223+
source.ts string.regexp.ts meta.group.regexp
224+
^
225+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
226+
^^
227+
source.ts string.regexp.ts
228+
>(b)
229+
^
230+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
231+
^
232+
source.ts string.regexp.ts meta.group.regexp
233+
^
234+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
235+
>
236+
^
237+
source.ts string.regexp.ts
238+
>if (a === 1) {
239+
^^^
240+
source.ts string.regexp.ts
241+
^
242+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
243+
^^^^^^^
244+
source.ts string.regexp.ts meta.group.regexp
245+
^
246+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
247+
^^^
248+
source.ts string.regexp.ts
249+
> b = 2
250+
^^^^^^^^^
251+
source.ts string.regexp.ts
252+
>} else if (a === 2) b = 3
253+
^^^^^^^^^^
254+
source.ts string.regexp.ts
255+
^
256+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
257+
^^^^^^^
258+
source.ts string.regexp.ts meta.group.regexp
259+
^
260+
source.ts string.regexp.ts meta.group.regexp punctuation.definition.group.regexp
261+
^^^^^^^
262+
source.ts string.regexp.ts
263+
>else b = 4
264+
^^^^^^^^^^^
265+
source.ts string.regexp.ts
266+
>c = 1
267+
^^^^^^
268+
source.ts string.regexp.ts

tests/baselines/regexp.baseline.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Grammar: TypeScript.tmLanguage
1818
^
1919
source.ts meta.var.expr.ts keyword.operator.assignment.ts
2020
^
21-
source.ts meta.var.expr.ts string.regexp.ts
21+
source.ts meta.var.expr.ts
2222
^
2323
source.ts meta.var.expr.ts string.regexp.ts punctuation.definition.string.begin.ts
2424
^

tests/cases/Issue717.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/* regex? */
2+
function test() {
3+
return /"/.test('xxx"xxx');
4+
}
5+
6+
console.log(test());
7+
a = 3 /*test*/ / parseInt(/.+/.exec('3f23fg')[0]);
8+
console.log(a);
9+
10+
b = 1
11+
a = () => b
12+
2 + (b=2), 3
13+
b = 6
14+
console.log(a(),b);
15+
(b)
16+
17+
if (a === 1) {
18+
b = 2
19+
} else if (a === 2) b = 3
20+
else b = 4
21+
c = 1

0 commit comments

Comments
 (0)