Skip to content

Commit c16fb3e

Browse files
committed
Module declaration is not always followed by block
Fixes #484
1 parent 53821b0 commit c16fb3e

File tree

5 files changed

+118
-12
lines changed

5 files changed

+118
-12
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ repository:
259259
'1': { name: keyword.control.export.ts }
260260
'2': { name: storage.type.type.ts }
261261
'3': { name: entity.name.type.alias.ts }
262-
end: (?=[};]|\bvar\b|\blet\b|\bconst\b|\btype\b|\bfunction\b|\bclass\b|\binterface\b|\bnamespace\b|\bmodule\b|\bimport\b|\benum\b|\bdeclare\b|\bexport\b|\babstract\b|\basync\b)
262+
end: (?=[};]|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)
263263
patterns:
264264
- include: '#comment'
265265
- include: '#type-parameters'
@@ -309,7 +309,7 @@ repository:
309309
beginCaptures:
310310
'1': { name: keyword.control.export.ts }
311311
'2': { name: storage.type.namespace.ts }
312-
end: (?<=\})
312+
end: (?<=\})|(?=;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)
313313
patterns:
314314
- include: '#comment'
315315
- include: '#string'
@@ -376,14 +376,14 @@ repository:
376376
'1': { name: keyword.control.export.ts }
377377
'2': { name: keyword.operator.assignment.ts }
378378
'3': { name: keyword.control.default.ts }
379-
end: (?=;|\bexport\b|\bfunction\b|\bclass\b|\binterface\b|\blet\b|\bvar\b|\bconst\b|\bimport\b|\benum\b|\bnamespace\b|\bmodule\b|\btype\b|\babstract\b|\bdeclare\b|\basync\b|$)
379+
end: (?=;|$|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)
380380
patterns:
381381
- include: '#expression'
382382
- name: meta.export.ts
383383
begin: (?<!\.|\$)\b(export)(?!(\s*:)|(\$))\b
384384
beginCaptures:
385385
'0': { name: keyword.control.export.ts }
386-
end: (?=;|\bexport\b|\bfunction\b|\bclass\b|\binterface\b|\blet\b|\bvar\b|\bconst\b|\bimport\b|\benum\b|\bnamespace\b|\bmodule\b|\btype\b|\babstract\b|\bdeclare\b|\basync\b|$)
386+
end: (?=;|$|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)
387387
patterns:
388388
- include: '#import-export-declaration'
389389

TypeScript.tmLanguage

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@
757757
</dict>
758758
</dict>
759759
<key>end</key>
760-
<string>(?=[};]|\bvar\b|\blet\b|\bconst\b|\btype\b|\bfunction\b|\bclass\b|\binterface\b|\bnamespace\b|\bmodule\b|\bimport\b|\benum\b|\bdeclare\b|\bexport\b|\babstract\b|\basync\b)</string>
760+
<string>(?=[};]|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)</string>
761761
<key>patterns</key>
762762
<array>
763763
<dict>
@@ -928,7 +928,7 @@
928928
</dict>
929929
</dict>
930930
<key>end</key>
931-
<string>(?&lt;=\})</string>
931+
<string>(?&lt;=\})|(?=;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)</string>
932932
<key>patterns</key>
933933
<array>
934934
<dict>
@@ -1166,7 +1166,7 @@
11661166
</dict>
11671167
</dict>
11681168
<key>end</key>
1169-
<string>(?=;|\bexport\b|\bfunction\b|\bclass\b|\binterface\b|\blet\b|\bvar\b|\bconst\b|\bimport\b|\benum\b|\bnamespace\b|\bmodule\b|\btype\b|\babstract\b|\bdeclare\b|\basync\b|$)</string>
1169+
<string>(?=;|$|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)</string>
11701170
<key>patterns</key>
11711171
<array>
11721172
<dict>
@@ -1189,7 +1189,7 @@
11891189
</dict>
11901190
</dict>
11911191
<key>end</key>
1192-
<string>(?=;|\bexport\b|\bfunction\b|\bclass\b|\binterface\b|\blet\b|\bvar\b|\bconst\b|\bimport\b|\benum\b|\bnamespace\b|\bmodule\b|\btype\b|\babstract\b|\bdeclare\b|\basync\b|$)</string>
1192+
<string>(?=;|$|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)</string>
11931193
<key>patterns</key>
11941194
<array>
11951195
<dict>

TypeScriptReact.tmLanguage

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@
761761
</dict>
762762
</dict>
763763
<key>end</key>
764-
<string>(?=[};]|\bvar\b|\blet\b|\bconst\b|\btype\b|\bfunction\b|\bclass\b|\binterface\b|\bnamespace\b|\bmodule\b|\bimport\b|\benum\b|\bdeclare\b|\bexport\b|\babstract\b|\basync\b)</string>
764+
<string>(?=[};]|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)</string>
765765
<key>patterns</key>
766766
<array>
767767
<dict>
@@ -932,7 +932,7 @@
932932
</dict>
933933
</dict>
934934
<key>end</key>
935-
<string>(?&lt;=\})</string>
935+
<string>(?&lt;=\})|(?=;|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)</string>
936936
<key>patterns</key>
937937
<array>
938938
<dict>
@@ -1170,7 +1170,7 @@
11701170
</dict>
11711171
</dict>
11721172
<key>end</key>
1173-
<string>(?=;|\bexport\b|\bfunction\b|\bclass\b|\binterface\b|\blet\b|\bvar\b|\bconst\b|\bimport\b|\benum\b|\bnamespace\b|\bmodule\b|\btype\b|\babstract\b|\bdeclare\b|\basync\b|$)</string>
1173+
<string>(?=;|$|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)</string>
11741174
<key>patterns</key>
11751175
<array>
11761176
<dict>
@@ -1193,7 +1193,7 @@
11931193
</dict>
11941194
</dict>
11951195
<key>end</key>
1196-
<string>(?=;|\bexport\b|\bfunction\b|\bclass\b|\binterface\b|\blet\b|\bvar\b|\bconst\b|\bimport\b|\benum\b|\bnamespace\b|\bmodule\b|\btype\b|\babstract\b|\bdeclare\b|\basync\b|$)</string>
1196+
<string>(?=;|$|\babstract\b|\basync\b|\bclass\b|\bconst\b|\bdeclare\b|\benum\b|\bexport\b|\bfunction\b|\bimport\b|\binterface\b|\blet\b|\bmodule\b|\bnamespace\b|\btype\b|\bvar\b)</string>
11971197
<key>patterns</key>
11981198
<array>
11991199
<dict>

tests/baselines/Issue484.baseline.txt

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
original file
2+
-----------------------------------
3+
declare module 'foo';
4+
declare module 'bar';
5+
declare module 'baz';
6+
interface Foo {
7+
bar: string;
8+
}
9+
-----------------------------------
10+
11+
Grammar: TypeScript.tmLanguage
12+
-----------------------------------
13+
>declare module 'foo';
14+
^^^^^^^
15+
source.ts storage.modifier.ts
16+
^
17+
source.ts
18+
^^^^^^
19+
source.ts meta.namespace.declaration.ts storage.type.namespace.ts
20+
^
21+
source.ts meta.namespace.declaration.ts
22+
^
23+
source.ts meta.namespace.declaration.ts string.quoted.single.ts punctuation.definition.string.begin.ts
24+
^^^
25+
source.ts meta.namespace.declaration.ts string.quoted.single.ts
26+
^
27+
source.ts meta.namespace.declaration.ts string.quoted.single.ts punctuation.definition.string.end.ts
28+
^
29+
source.ts punctuation.terminator.statement.ts
30+
^^
31+
source.ts
32+
>declare module 'bar';
33+
^^^^^^^
34+
source.ts storage.modifier.ts
35+
^
36+
source.ts
37+
^^^^^^
38+
source.ts meta.namespace.declaration.ts storage.type.namespace.ts
39+
^
40+
source.ts meta.namespace.declaration.ts
41+
^
42+
source.ts meta.namespace.declaration.ts string.quoted.single.ts punctuation.definition.string.begin.ts
43+
^^^
44+
source.ts meta.namespace.declaration.ts string.quoted.single.ts
45+
^
46+
source.ts meta.namespace.declaration.ts string.quoted.single.ts punctuation.definition.string.end.ts
47+
^
48+
source.ts punctuation.terminator.statement.ts
49+
^^
50+
source.ts
51+
>declare module 'baz';
52+
^^^^^^^
53+
source.ts storage.modifier.ts
54+
^
55+
source.ts
56+
^^^^^^
57+
source.ts meta.namespace.declaration.ts storage.type.namespace.ts
58+
^
59+
source.ts meta.namespace.declaration.ts
60+
^
61+
source.ts meta.namespace.declaration.ts string.quoted.single.ts punctuation.definition.string.begin.ts
62+
^^^
63+
source.ts meta.namespace.declaration.ts string.quoted.single.ts
64+
^
65+
source.ts meta.namespace.declaration.ts string.quoted.single.ts punctuation.definition.string.end.ts
66+
^
67+
source.ts punctuation.terminator.statement.ts
68+
^^
69+
source.ts
70+
>interface Foo {
71+
^^^^^^^^^
72+
source.ts meta.interface.ts storage.type.interface.ts
73+
^
74+
source.ts meta.interface.ts
75+
^^^
76+
source.ts meta.interface.ts entity.name.type.interface.ts
77+
^
78+
source.ts meta.interface.ts
79+
^
80+
source.ts meta.interface.ts punctuation.definition.block.ts
81+
^^
82+
source.ts meta.interface.ts
83+
> bar: string;
84+
^^^^
85+
source.ts meta.interface.ts
86+
^^^
87+
source.ts meta.interface.ts meta.field.declaration.ts meta.definition.property.ts variable.object.property.ts
88+
^
89+
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts keyword.operator.type.annotation.ts
90+
^
91+
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts
92+
^^^^^^
93+
source.ts meta.interface.ts meta.field.declaration.ts meta.type.annotation.ts support.type.primitive.ts
94+
^
95+
source.ts meta.interface.ts punctuation.terminator.statement.ts
96+
^^
97+
source.ts meta.interface.ts
98+
>}
99+
^
100+
source.ts meta.interface.ts punctuation.definition.block.ts

tests/cases/Issue484.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
declare module 'foo';
2+
declare module 'bar';
3+
declare module 'baz';
4+
interface Foo {
5+
bar: string;
6+
}

0 commit comments

Comments
 (0)