Skip to content

Commit 26bc1de

Browse files
committed
Removed duplicated definitions and fixed issues with constructor type annotation
1 parent e5a583f commit 26bc1de

File tree

2 files changed

+44
-132
lines changed

2 files changed

+44
-132
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 27 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ repository:
137137
patterns:
138138
- include: '#comment'
139139
- include: '#type-parameters'
140-
- include: '#function-parameters'
140+
- include: '#function-type-parameters'
141141
- include: '#type-annotation'
142142
- include: '#decl-block'
143143

@@ -172,7 +172,7 @@ repository:
172172
- include: '#function-overload-declaration'
173173
- include: '#comment'
174174
- include: '#type-parameters'
175-
- include: '#function-parameters'
175+
- include: '#function-type-parameters'
176176
- include: '#return-type'
177177
- include: '#decl-block'
178178

@@ -206,34 +206,6 @@ repository:
206206
patterns:
207207
- include: '#expression'
208208

209-
function-parameters:
210-
name: meta.function-parameters.ts
211-
begin: \(
212-
beginCaptures:
213-
'0': { name: meta.brace.round.ts }
214-
end: \)
215-
endCaptures:
216-
'0': { name: meta.brace.round.ts }
217-
patterns:
218-
- include: '#comment'
219-
- include: '#parameter-name'
220-
- include: '#type-annotation'
221-
- include: '#variable-initializer'
222-
223-
function-type-parameters:
224-
name: meta.function.type.ts
225-
begin: (\()
226-
beginCaptures:
227-
'1': { name: meta.brace.round.ts }
228-
end: (\))
229-
endCaptures:
230-
'1': { name: meta.brace.round.ts }
231-
patterns:
232-
- include: '#comment'
233-
- include: '#parameter-name'
234-
- include: '#type-annotation'
235-
- include: '#variable-initializer'
236-
237209
parameter-name:
238210
name: parameter.name.ts
239211
match: '(?:\s*\b(public|private)\b\s+)?(\.\.\.)?\s*([a-zA-Z_$][\w$]*)\s*(\??)'
@@ -245,7 +217,7 @@ repository:
245217

246218
return-type:
247219
name: meta.return.type.ts
248-
begin: '(?<=\)):'
220+
begin: '(?<=\))\s*:'
249221
end: (?=$)|(?=\{|;|//)
250222
patterns:
251223
- include: '#type'
@@ -262,37 +234,47 @@ repository:
262234
name: meta.type.ts
263235
patterns:
264236
- include: '#type-primitive'
265-
- include: '#type-name'
266237
- include: '#type-parameters'
267238
- include: '#type-tuple'
268239
- include: '#object-type'
269240
- include: '#type-operator'
270241
- include: '#paren-type-or-function-type-parameters'
271-
- include: '#function-type-parameters'
272242
- include: '#function-type-return-type'
243+
- include: '#type-name'
244+
245+
function-type-parameters:
246+
name: meta.function.type.parameter.ts
247+
begin: \(
248+
beginCaptures:
249+
'0': { name: meta.brace.round.ts }
250+
end: \)
251+
endCaptures:
252+
'0': { name: meta.brace.round.ts }
253+
patterns:
254+
- include: '#comment'
255+
- include: '#parameter-name'
256+
- include: '#type-annotation'
257+
- include: '#variable-initializer'
273258

274259
type-primitive:
275260
name: storage.type.ts
276261
match: '\b(string|number|boolean|symbol|any|void)\b'
277262

263+
# Parenthesis can contain either types and function parameters
264+
# (number | string) or (param: number, param2: string)
265+
# and it can be nested, for example
266+
# (number | (param: number, param2: string) => void)
278267
paren-type-or-function-type-parameters:
279268
name: meta.type.paren.cover.ts
280-
begin: '\('
269+
begin: '(?:\b(new)\b)?\s*\('
270+
beginCaptures:
271+
'1': { name: keyword.operator.ts }
281272
end: '\)'
282273
patterns:
283274
- include: '#comment'
284275
- include: '#type'
285-
- include: '#type-or-function-type-parameter'
286-
287-
type-or-function-type-parameter:
288-
name: meta.type.paren.cover.ts
289-
match: '(\.\.\.)?\s*([a-zA-Z_$][\w$]*)\s*(\?)?\s*(:)?\s*(?=,|\)\s*=>)'
290-
captures:
291-
'1': { name: keyword.operator.ts }
292-
'2': { name: meta.function-parameters.ts }
293-
'3': { name: keyword.operator.ts }
294-
'4': { name: keyword.operator.ts }
295-
276+
- include: '#function-type-parameters'
277+
296278
type-operator:
297279
name: keyword.operator.type.ts
298280
match: '[.|]'

TypeScript.tmLanguage

Lines changed: 17 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@
459459
</dict>
460460
<dict>
461461
<key>include</key>
462-
<string>#function-parameters</string>
462+
<string>#function-type-parameters</string>
463463
</dict>
464464
<dict>
465465
<key>include</key>
@@ -491,7 +491,7 @@
491491
<key>name</key>
492492
<string>meta.function.overload.ts</string>
493493
</dict>
494-
<key>function-parameters</key>
494+
<key>function-type-parameters</key>
495495
<dict>
496496
<key>begin</key>
497497
<string>\(</string>
@@ -514,51 +514,7 @@
514514
</dict>
515515
</dict>
516516
<key>name</key>
517-
<string>meta.function-parameters.ts</string>
518-
<key>patterns</key>
519-
<array>
520-
<dict>
521-
<key>include</key>
522-
<string>#comment</string>
523-
</dict>
524-
<dict>
525-
<key>include</key>
526-
<string>#parameter-name</string>
527-
</dict>
528-
<dict>
529-
<key>include</key>
530-
<string>#type-annotation</string>
531-
</dict>
532-
<dict>
533-
<key>include</key>
534-
<string>#variable-initializer</string>
535-
</dict>
536-
</array>
537-
</dict>
538-
<key>function-type-parameters</key>
539-
<dict>
540-
<key>begin</key>
541-
<string>(\()</string>
542-
<key>beginCaptures</key>
543-
<dict>
544-
<key>1</key>
545-
<dict>
546-
<key>name</key>
547-
<string>meta.brace.round.ts</string>
548-
</dict>
549-
</dict>
550-
<key>end</key>
551-
<string>(\))</string>
552-
<key>endCaptures</key>
553-
<dict>
554-
<key>1</key>
555-
<dict>
556-
<key>name</key>
557-
<string>meta.brace.round.ts</string>
558-
</dict>
559-
</dict>
560-
<key>name</key>
561-
<string>meta.function.type.ts</string>
517+
<string>meta.function.type.parameter.ts</string>
562518
<key>patterns</key>
563519
<array>
564520
<dict>
@@ -745,7 +701,7 @@
745701
</dict>
746702
<dict>
747703
<key>include</key>
748-
<string>#function-parameters</string>
704+
<string>#function-type-parameters</string>
749705
</dict>
750706
<dict>
751707
<key>include</key>
@@ -1060,7 +1016,15 @@
10601016
<key>paren-type-or-function-type-parameters</key>
10611017
<dict>
10621018
<key>begin</key>
1063-
<string>\(</string>
1019+
<string>(?:\b(new)\b)?\s*\(</string>
1020+
<key>beginCaptures</key>
1021+
<dict>
1022+
<key>1</key>
1023+
<dict>
1024+
<key>name</key>
1025+
<string>keyword.operator.ts</string>
1026+
</dict>
1027+
</dict>
10641028
<key>end</key>
10651029
<string>\)</string>
10661030
<key>name</key>
@@ -1077,7 +1041,7 @@
10771041
</dict>
10781042
<dict>
10791043
<key>include</key>
1080-
<string>#type-or-function-type-parameter</string>
1044+
<string>#function-type-parameters</string>
10811045
</dict>
10821046
</array>
10831047
</dict>
@@ -1154,7 +1118,7 @@
11541118
<key>return-type</key>
11551119
<dict>
11561120
<key>begin</key>
1157-
<string>(?&lt;=\)):</string>
1121+
<string>(?&lt;=\))\s*:</string>
11581122
<key>end</key>
11591123
<string>(?=$)|(?=\{|;|//)</string>
11601124
<key>name</key>
@@ -1329,10 +1293,6 @@
13291293
<key>include</key>
13301294
<string>#type-primitive</string>
13311295
</dict>
1332-
<dict>
1333-
<key>include</key>
1334-
<string>#type-name</string>
1335-
</dict>
13361296
<dict>
13371297
<key>include</key>
13381298
<string>#type-parameters</string>
@@ -1355,11 +1315,11 @@
13551315
</dict>
13561316
<dict>
13571317
<key>include</key>
1358-
<string>#function-type-parameters</string>
1318+
<string>#function-type-return-type</string>
13591319
</dict>
13601320
<dict>
13611321
<key>include</key>
1362-
<string>#function-type-return-type</string>
1322+
<string>#type-name</string>
13631323
</dict>
13641324
</array>
13651325
</dict>
@@ -1426,36 +1386,6 @@
14261386
<key>name</key>
14271387
<string>keyword.operator.type.ts</string>
14281388
</dict>
1429-
<key>type-or-function-type-parameter</key>
1430-
<dict>
1431-
<key>captures</key>
1432-
<dict>
1433-
<key>1</key>
1434-
<dict>
1435-
<key>name</key>
1436-
<string>keyword.operator.ts</string>
1437-
</dict>
1438-
<key>2</key>
1439-
<dict>
1440-
<key>name</key>
1441-
<string>meta.function-parameters.ts</string>
1442-
</dict>
1443-
<key>3</key>
1444-
<dict>
1445-
<key>name</key>
1446-
<string>keyword.operator.ts</string>
1447-
</dict>
1448-
<key>4</key>
1449-
<dict>
1450-
<key>name</key>
1451-
<string>keyword.operator.ts</string>
1452-
</dict>
1453-
</dict>
1454-
<key>match</key>
1455-
<string>(\.\.\.)?\s*([a-zA-Z_$][\w$]*)\s*(\?)?\s*(:)?\s*(?=,|\)\s*=&gt;)</string>
1456-
<key>name</key>
1457-
<string>meta.type.paren.cover.ts</string>
1458-
</dict>
14591389
<key>type-parameters</key>
14601390
<dict>
14611391
<key>begin</key>

0 commit comments

Comments
 (0)