Skip to content

Commit c4036f9

Browse files
committed
Fix the arrow parameter detection
Fixes #536
1 parent 3e5fcfa commit c4036f9

File tree

5 files changed

+56
-13
lines changed

5 files changed

+56
-13
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ variables:
2929
# arrow function possible to detect only with => on same line
3030
(
3131
{{typeParameters}}? # typeparameters
32-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
32+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
3333
(\s*:\s*([^<>\(\)]|\<[^<>]+\>|\([^\(\)]+\))+)? # return type
3434
\s*=> # arrow operator
3535
)

TypeScript.tmLanguage

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@
408408
# arrow function possible to detect only with =&gt; on same line
409409
(
410410
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
411-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
411+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
412412
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
413413
\s*=&gt; # arrow operator
414414
)
@@ -796,7 +796,7 @@
796796
# arrow function possible to detect only with =&gt; on same line
797797
(
798798
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
799-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
799+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
800800
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
801801
\s*=&gt; # arrow operator
802802
)
@@ -1182,7 +1182,7 @@
11821182
# arrow function possible to detect only with =&gt; on same line
11831183
(
11841184
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
1185-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
1185+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
11861186
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
11871187
\s*=&gt; # arrow operator
11881188
)
@@ -1623,7 +1623,7 @@
16231623
# arrow function possible to detect only with =&gt; on same line
16241624
(
16251625
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
1626-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
1626+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
16271627
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
16281628
\s*=&gt; # arrow operator
16291629
)
@@ -3098,7 +3098,7 @@
30983098
# arrow function possible to detect only with =&gt; on same line
30993099
(
31003100
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
3101-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
3101+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
31023102
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
31033103
\s*=&gt; # arrow operator
31043104
)
@@ -4335,7 +4335,7 @@
43354335
# arrow function possible to detect only with =&gt; on same line
43364336
(
43374337
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
4338-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
4338+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
43394339
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
43404340
\s*=&gt; # arrow operator
43414341
)

TypeScriptReact.tmLanguage

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@
412412
# arrow function possible to detect only with =&gt; on same line
413413
(
414414
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
415-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
415+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
416416
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
417417
\s*=&gt; # arrow operator
418418
)
@@ -800,7 +800,7 @@
800800
# arrow function possible to detect only with =&gt; on same line
801801
(
802802
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
803-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
803+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
804804
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
805805
\s*=&gt; # arrow operator
806806
)
@@ -1186,7 +1186,7 @@
11861186
# arrow function possible to detect only with =&gt; on same line
11871187
(
11881188
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
1189-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
1189+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
11901190
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
11911191
\s*=&gt; # arrow operator
11921192
)
@@ -1627,7 +1627,7 @@
16271627
# arrow function possible to detect only with =&gt; on same line
16281628
(
16291629
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
1630-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
1630+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
16311631
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
16321632
\s*=&gt; # arrow operator
16331633
)
@@ -3102,7 +3102,7 @@
31023102
# arrow function possible to detect only with =&gt; on same line
31033103
(
31043104
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
3105-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
3105+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
31063106
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
31073107
\s*=&gt; # arrow operator
31083108
)
@@ -4281,7 +4281,7 @@
42814281
# arrow function possible to detect only with =&gt; on same line
42824282
(
42834283
(&lt;\s*[_$[:alpha:]\{\(\[]([^&lt;&gt;=]|=[^&lt;]|\&lt;\s*[_$[:alpha:]\{\(\[]([^=&lt;&gt;]|=[^&lt;])+\&gt;)+&gt;\s*)? # typeparameters
4284-
\((\s*[_$[:alpha:]\{\(]([^()]|\((\s*[_$[:alpha:]\{\(]\{\(][^()]*)?\))*)?\) # parameteres
4284+
\(\s*([_$[:alpha:]\{\[]([^()]|\((\s*[_$[:alpha:]\{\[][^()]*)?\))*)?\) # parameteres
42854285
(\s*:\s*([^&lt;&gt;\(\)]|\&lt;[^&lt;&gt;]+\&gt;|\([^\(\)]+\))+)? # return type
42864286
\s*=&gt; # arrow operator
42874287
)

tests/baselines/Issue536.baseline.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
original file
2+
-----------------------------------
3+
const z = (() => {})()
4+
-----------------------------------
5+
6+
Grammar: TypeScript.tmLanguage
7+
-----------------------------------
8+
>const z = (() => {})()
9+
^^^^^
10+
source.ts meta.var.expr.ts storage.type.ts
11+
^
12+
source.ts meta.var.expr.ts
13+
^
14+
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts meta.definition.variable.ts variable.other.readwrite.ts
15+
^
16+
source.ts meta.var.expr.ts meta.var-single-variable.expr.ts
17+
^
18+
source.ts meta.var.expr.ts keyword.operator.assignment.ts
19+
^
20+
source.ts meta.var.expr.ts
21+
^
22+
source.ts meta.var.expr.ts meta.brace.round.ts
23+
^
24+
source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.begin.ts
25+
^
26+
source.ts meta.var.expr.ts meta.arrow.ts meta.parameters.ts punctuation.definition.parameters.end.ts
27+
^
28+
source.ts meta.var.expr.ts meta.arrow.ts
29+
^^
30+
source.ts meta.var.expr.ts meta.arrow.ts storage.type.function.arrow.ts
31+
^
32+
source.ts meta.var.expr.ts meta.arrow.ts
33+
^
34+
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
35+
^
36+
source.ts meta.var.expr.ts meta.arrow.ts meta.block.ts punctuation.definition.block.ts
37+
^
38+
source.ts meta.var.expr.ts meta.brace.round.ts
39+
^
40+
source.ts meta.var.expr.ts meta.brace.round.ts
41+
^
42+
source.ts meta.var.expr.ts meta.brace.round.ts

tests/cases/Issue536.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
const z = (() => {})()

0 commit comments

Comments
 (0)