Skip to content

Commit 1d2625a

Browse files
committed
Fix the handling of extends/implements clause
Fixes #551
1 parent 0683194 commit 1d2625a

File tree

8 files changed

+164
-43
lines changed

8 files changed

+164
-43
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@ repository:
125125
match: (?<!\.|\$)\b(declare)\b(?!\$|\.)
126126

127127
expression:
128+
patterns:
129+
- include: '#expressionWithoutIdentifiers'
130+
- include: '#identifiers'
131+
- include: '#expressionPunctuations'
132+
133+
expressionWithoutIdentifiers:
128134
patterns:
129135
- include: '#string'
130136
- include: '#regex'
@@ -141,8 +147,10 @@ repository:
141147
- include: '#function-call'
142148
- include: '#literal'
143149
- include: '#support-objects'
144-
- include: '#identifiers'
145150
- include: '#paren-expression'
151+
152+
expressionPunctuations:
153+
patterns:
146154
- include: '#punctuation-comma'
147155
- include: '#punctuation-accessor'
148156

@@ -658,20 +666,22 @@ repository:
658666
beginCaptures:
659667
'1': { name: storage.modifier.ts }
660668
end: (?=\{)
661-
endCaptures:
662-
'1': { name: punctuation.definition.block.ts }
663669
patterns:
664670
- include: '#comment'
665671
- include: '#class-or-interface-heritage'
666672
- include: '#type-parameters'
667-
- match: ({{identifier}})\s*(\.)(?=\s*{{identifier}}(\s*\.\s*{{identifier}})*\s*([,<{]|extends|implements|//|/\*))
673+
# match expressions before matching identifiers
674+
- include: '#expressionWithoutIdentifiers'
675+
# identifiers are treated as inherited class
676+
- match: ({{identifier}})\s*(\.)(?=\s*{{identifier}}(\s*\.\s*{{identifier}})*\s*)
668677
captures:
669678
'1': { name: entity.name.type.module.ts }
670679
'2': { name: punctuation.accessor.ts }
671-
- match: ({{identifier}})(?=\s*([,<{]|extends|implements|//|/\*))
680+
- match: ({{identifier}})
672681
captures:
673682
'1': { name: entity.other.inherited-class.ts }
674-
- include: '#expression'
683+
# match punctuations of the expression
684+
- include: '#expressionPunctuations'
675685

676686
class-or-interface-body:
677687
begin: \{

TypeScript.tmLanguage

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@
194194
</array>
195195
</dict>
196196
<key>expression</key>
197+
<dict>
198+
<key>patterns</key>
199+
<array>
200+
<dict>
201+
<key>include</key>
202+
<string>#expressionWithoutIdentifiers</string>
203+
</dict>
204+
<dict>
205+
<key>include</key>
206+
<string>#identifiers</string>
207+
</dict>
208+
<dict>
209+
<key>include</key>
210+
<string>#expressionPunctuations</string>
211+
</dict>
212+
</array>
213+
</dict>
214+
<key>expressionWithoutIdentifiers</key>
197215
<dict>
198216
<key>patterns</key>
199217
<array>
@@ -257,14 +275,16 @@
257275
<key>include</key>
258276
<string>#support-objects</string>
259277
</dict>
260-
<dict>
261-
<key>include</key>
262-
<string>#identifiers</string>
263-
</dict>
264278
<dict>
265279
<key>include</key>
266280
<string>#paren-expression</string>
267281
</dict>
282+
</array>
283+
</dict>
284+
<key>expressionPunctuations</key>
285+
<dict>
286+
<key>patterns</key>
287+
<array>
268288
<dict>
269289
<key>include</key>
270290
<string>#punctuation-comma</string>
@@ -2009,14 +2029,6 @@
20092029
</dict>
20102030
<key>end</key>
20112031
<string>(?=\{)</string>
2012-
<key>endCaptures</key>
2013-
<dict>
2014-
<key>1</key>
2015-
<dict>
2016-
<key>name</key>
2017-
<string>punctuation.definition.block.ts</string>
2018-
</dict>
2019-
</dict>
20202032
<key>patterns</key>
20212033
<array>
20222034
<dict>
@@ -2031,9 +2043,13 @@
20312043
<key>include</key>
20322044
<string>#type-parameters</string>
20332045
</dict>
2046+
<dict>
2047+
<key>include</key>
2048+
<string>#expressionWithoutIdentifiers</string>
2049+
</dict>
20342050
<dict>
20352051
<key>match</key>
2036-
<string>([_$[:alpha:]][_$[:alnum:]]*)\s*(\.)(?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s*\.\s*[_$[:alpha:]][_$[:alnum:]]*)*\s*([,&lt;{]|extends|implements|//|/\*))</string>
2052+
<string>([_$[:alpha:]][_$[:alnum:]]*)\s*(\.)(?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s*\.\s*[_$[:alpha:]][_$[:alnum:]]*)*\s*)</string>
20372053
<key>captures</key>
20382054
<dict>
20392055
<key>1</key>
@@ -2050,7 +2066,7 @@
20502066
</dict>
20512067
<dict>
20522068
<key>match</key>
2053-
<string>([_$[:alpha:]][_$[:alnum:]]*)(?=\s*([,&lt;{]|extends|implements|//|/\*))</string>
2069+
<string>([_$[:alpha:]][_$[:alnum:]]*)</string>
20542070
<key>captures</key>
20552071
<dict>
20562072
<key>1</key>
@@ -2062,7 +2078,7 @@
20622078
</dict>
20632079
<dict>
20642080
<key>include</key>
2065-
<string>#expression</string>
2081+
<string>#expressionPunctuations</string>
20662082
</dict>
20672083
</array>
20682084
</dict>

TypeScriptReact.YAML-tmLanguage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ uuid: 805375ec-d614-41f5-8993-5843fe63ea82
1111
repository:
1212
# Additions:
1313
# expression repository need to include jsx first followed by whaterver ts grammar says
14-
expression:
14+
expressionWithoutIdentifiers:
1515
patterns:
1616
- include: '#jsx'
1717

TypeScriptReact.tmLanguage

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,24 @@
194194
</array>
195195
</dict>
196196
<key>expression</key>
197+
<dict>
198+
<key>patterns</key>
199+
<array>
200+
<dict>
201+
<key>include</key>
202+
<string>#expressionWithoutIdentifiers</string>
203+
</dict>
204+
<dict>
205+
<key>include</key>
206+
<string>#identifiers</string>
207+
</dict>
208+
<dict>
209+
<key>include</key>
210+
<string>#expressionPunctuations</string>
211+
</dict>
212+
</array>
213+
</dict>
214+
<key>expressionWithoutIdentifiers</key>
197215
<dict>
198216
<key>patterns</key>
199217
<array>
@@ -261,14 +279,16 @@
261279
<key>include</key>
262280
<string>#support-objects</string>
263281
</dict>
264-
<dict>
265-
<key>include</key>
266-
<string>#identifiers</string>
267-
</dict>
268282
<dict>
269283
<key>include</key>
270284
<string>#paren-expression</string>
271285
</dict>
286+
</array>
287+
</dict>
288+
<key>expressionPunctuations</key>
289+
<dict>
290+
<key>patterns</key>
291+
<array>
272292
<dict>
273293
<key>include</key>
274294
<string>#punctuation-comma</string>
@@ -2013,14 +2033,6 @@
20132033
</dict>
20142034
<key>end</key>
20152035
<string>(?=\{)</string>
2016-
<key>endCaptures</key>
2017-
<dict>
2018-
<key>1</key>
2019-
<dict>
2020-
<key>name</key>
2021-
<string>punctuation.definition.block.tsx</string>
2022-
</dict>
2023-
</dict>
20242036
<key>patterns</key>
20252037
<array>
20262038
<dict>
@@ -2035,9 +2047,13 @@
20352047
<key>include</key>
20362048
<string>#type-parameters</string>
20372049
</dict>
2050+
<dict>
2051+
<key>include</key>
2052+
<string>#expressionWithoutIdentifiers</string>
2053+
</dict>
20382054
<dict>
20392055
<key>match</key>
2040-
<string>([_$[:alpha:]][_$[:alnum:]]*)\s*(\.)(?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s*\.\s*[_$[:alpha:]][_$[:alnum:]]*)*\s*([,&lt;{]|extends|implements|//|/\*))</string>
2056+
<string>([_$[:alpha:]][_$[:alnum:]]*)\s*(\.)(?=\s*[_$[:alpha:]][_$[:alnum:]]*(\s*\.\s*[_$[:alpha:]][_$[:alnum:]]*)*\s*)</string>
20412057
<key>captures</key>
20422058
<dict>
20432059
<key>1</key>
@@ -2054,7 +2070,7 @@
20542070
</dict>
20552071
<dict>
20562072
<key>match</key>
2057-
<string>([_$[:alpha:]][_$[:alnum:]]*)(?=\s*([,&lt;{]|extends|implements|//|/\*))</string>
2073+
<string>([_$[:alpha:]][_$[:alnum:]]*)</string>
20582074
<key>captures</key>
20592075
<dict>
20602076
<key>1</key>
@@ -2066,7 +2082,7 @@
20662082
</dict>
20672083
<dict>
20682084
<key>include</key>
2069-
<string>#expression</string>
2085+
<string>#expressionPunctuations</string>
20702086
</dict>
20712087
</array>
20722088
</dict>

build/build.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function changeTsToTsxGrammar(grammar: any) {
5757
const updatesRepository = tsxUpdates.repository;
5858
for (let key in updatesRepository) {
5959
switch(key) {
60-
case "expression":
60+
case "expressionWithoutIdentifiers":
6161
// Update expression
6262
repository[key].patterns.unshift(updatesRepository[key].patterns[0]);
6363
break;

tests/baselines/Comments.baseline.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ Grammar: TypeScript.tmLanguage
14791479
^
14801480
source.ts meta.interface.ts
14811481
^^^^^
1482-
source.ts meta.interface.ts entity.other.inherited-class.ts
1482+
source.ts meta.interface.ts support.class.builtin.ts
14831483
^
14841484
source.ts meta.interface.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
14851485
^
@@ -1554,7 +1554,7 @@ Grammar: TypeScript.tmLanguage
15541554
^
15551555
source.ts meta.interface.ts
15561556
^^^^^
1557-
source.ts meta.interface.ts entity.other.inherited-class.ts
1557+
source.ts meta.interface.ts support.class.builtin.ts
15581558
^
15591559
source.ts meta.interface.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
15601560
^
@@ -1629,7 +1629,7 @@ Grammar: TypeScript.tmLanguage
16291629
^^
16301630
source.ts meta.interface.ts comment.block.ts punctuation.definition.comment.ts
16311631
^^^^^
1632-
source.ts meta.interface.ts entity.other.inherited-class.ts
1632+
source.ts meta.interface.ts support.class.builtin.ts
16331633
^
16341634
source.ts meta.interface.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
16351635
^
@@ -1702,7 +1702,7 @@ Grammar: TypeScript.tmLanguage
17021702
^
17031703
source.ts meta.interface.ts
17041704
^^^^^
1705-
source.ts meta.interface.ts entity.other.inherited-class.ts
1705+
source.ts meta.interface.ts support.class.builtin.ts
17061706
^^
17071707
source.ts meta.interface.ts comment.block.ts punctuation.definition.comment.ts
17081708
^^
@@ -1779,7 +1779,7 @@ Grammar: TypeScript.tmLanguage
17791779
^
17801780
source.ts meta.interface.ts
17811781
^^^^^
1782-
source.ts meta.interface.ts entity.other.inherited-class.ts
1782+
source.ts meta.interface.ts support.class.builtin.ts
17831783
^
17841784
source.ts meta.interface.ts meta.type.parameters.ts punctuation.definition.typeparameters.begin.ts
17851785
^

tests/baselines/Issue551.baseline.txt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
original file
2+
-----------------------------------
3+
class a extends b, c {
4+
}
5+
class a2 extends b, c
6+
{
7+
}
8+
-----------------------------------
9+
10+
Grammar: TypeScript.tmLanguage
11+
-----------------------------------
12+
>class a extends b, c {
13+
^^^^^
14+
source.ts meta.class.ts storage.type.class.ts
15+
^
16+
source.ts meta.class.ts
17+
^
18+
source.ts meta.class.ts entity.name.type.class.ts
19+
^
20+
source.ts meta.class.ts
21+
^^^^^^^
22+
source.ts meta.class.ts storage.modifier.ts
23+
^
24+
source.ts meta.class.ts
25+
^
26+
source.ts meta.class.ts entity.other.inherited-class.ts
27+
^
28+
source.ts meta.class.ts punctuation.separator.comma.ts
29+
^
30+
source.ts meta.class.ts
31+
^
32+
source.ts meta.class.ts entity.other.inherited-class.ts
33+
^
34+
source.ts meta.class.ts
35+
^
36+
source.ts meta.class.ts punctuation.definition.block.ts
37+
^^^
38+
source.ts meta.class.ts
39+
>}
40+
^
41+
source.ts meta.class.ts punctuation.definition.block.ts
42+
^^
43+
source.ts
44+
>class a2 extends b, c
45+
^^^^^
46+
source.ts meta.class.ts storage.type.class.ts
47+
^
48+
source.ts meta.class.ts
49+
^^
50+
source.ts meta.class.ts entity.name.type.class.ts
51+
^
52+
source.ts meta.class.ts
53+
^^^^^^^
54+
source.ts meta.class.ts storage.modifier.ts
55+
^
56+
source.ts meta.class.ts
57+
^
58+
source.ts meta.class.ts entity.other.inherited-class.ts
59+
^
60+
source.ts meta.class.ts punctuation.separator.comma.ts
61+
^
62+
source.ts meta.class.ts
63+
^
64+
source.ts meta.class.ts entity.other.inherited-class.ts
65+
^^
66+
source.ts meta.class.ts
67+
>{
68+
^
69+
source.ts meta.class.ts punctuation.definition.block.ts
70+
^^^
71+
source.ts meta.class.ts
72+
>}
73+
^
74+
source.ts meta.class.ts punctuation.definition.block.ts

tests/cases/Issue551.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class a extends b, c {
2+
}
3+
class a2 extends b, c
4+
{
5+
}

0 commit comments

Comments
 (0)