Skip to content

Commit 9fbaca8

Browse files
committed
Namespace declarations
1 parent 8870cb4 commit 9fbaca8

10 files changed

+195
-75
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,10 @@ repository:
118118
- include: '#class-or-interface-declaration'
119119
- include: '#type-declaration'
120120
- include: '#enum-declaration'
121+
- include: '#namespace-declaration'
121122
- include: '#import-equals-declaration'
122123
- include: '#import-declaration'
123124
- include: '#export-declaration'
124-
# TODO: change this to actual declarations of export, import, namespace
125-
- include: '#storage-keyword'
126125

127126
type-declaration:
128127
name: meta.type.declaration.ts
@@ -148,6 +147,21 @@ repository:
148147
'3': { name: storage.type.enum.ts }
149148
'4': { name: entity.name.type.enum.ts }
150149

150+
namespace-declaration:
151+
name: meta.namespace.declaration.ts
152+
begin: (?:(\bexport)\s+)?\b(?<!\.)(namespace|module)\s+
153+
beginCaptures:
154+
'1': { name: keyword.control.export.ts }
155+
'2': { name: storage.type.namespace.ts }
156+
end: (?=$|\{)
157+
patterns:
158+
- include: '#comment'
159+
- include: '#string'
160+
- name: entity.name.type.module.ts
161+
match: \b([a-zA-Z_$][\w$]*)\b
162+
- name: punctuation.accessor.ts
163+
match: \.
164+
151165
import-equals-declaration:
152166
patterns:
153167
- name: meta.import-equals.external.ts
@@ -770,10 +784,6 @@ repository:
770784
- name: keyword.operator.arithmetic.ts
771785
match: '%|\*|/|-|\+'
772786

773-
storage-keyword:
774-
name: storage.type.ts
775-
match: \b(module|namespace)\b
776-
777787
paren-expression:
778788
begin: \(
779789
beginCaptures:

TypeScript.tmLanguage

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -591,19 +591,19 @@
591591
</dict>
592592
<dict>
593593
<key>include</key>
594-
<string>#import-equals-declaration</string>
594+
<string>#namespace-declaration</string>
595595
</dict>
596596
<dict>
597597
<key>include</key>
598-
<string>#import-declaration</string>
598+
<string>#import-equals-declaration</string>
599599
</dict>
600600
<dict>
601601
<key>include</key>
602-
<string>#export-declaration</string>
602+
<string>#import-declaration</string>
603603
</dict>
604604
<dict>
605605
<key>include</key>
606-
<string>#storage-keyword</string>
606+
<string>#export-declaration</string>
607607
</dict>
608608
</array>
609609
</dict>
@@ -1672,6 +1672,51 @@
16721672
<key>name</key>
16731673
<string>meta.method.overload.declaration.ts</string>
16741674
</dict>
1675+
<key>namespace-declaration</key>
1676+
<dict>
1677+
<key>begin</key>
1678+
<string>(?:(\bexport)\s+)?\b(?&lt;!\.)(namespace|module)\s+</string>
1679+
<key>beginCaptures</key>
1680+
<dict>
1681+
<key>1</key>
1682+
<dict>
1683+
<key>name</key>
1684+
<string>keyword.control.export.ts</string>
1685+
</dict>
1686+
<key>2</key>
1687+
<dict>
1688+
<key>name</key>
1689+
<string>storage.type.namespace.ts</string>
1690+
</dict>
1691+
</dict>
1692+
<key>end</key>
1693+
<string>(?=$|\{)</string>
1694+
<key>name</key>
1695+
<string>meta.namespace.declaration.ts</string>
1696+
<key>patterns</key>
1697+
<array>
1698+
<dict>
1699+
<key>include</key>
1700+
<string>#comment</string>
1701+
</dict>
1702+
<dict>
1703+
<key>include</key>
1704+
<string>#string</string>
1705+
</dict>
1706+
<dict>
1707+
<key>match</key>
1708+
<string>\b([a-zA-Z_$][\w$]*)\b</string>
1709+
<key>name</key>
1710+
<string>entity.name.type.module.ts</string>
1711+
</dict>
1712+
<dict>
1713+
<key>match</key>
1714+
<string>\.</string>
1715+
<key>name</key>
1716+
<string>punctuation.accessor.ts</string>
1717+
</dict>
1718+
</array>
1719+
</dict>
16751720
<key>new-expr</key>
16761721
<dict>
16771722
<key>begin</key>
@@ -2424,13 +2469,6 @@
24242469
<key>name</key>
24252470
<string>storage.modifier.ts</string>
24262471
</dict>
2427-
<key>storage-keyword</key>
2428-
<dict>
2429-
<key>match</key>
2430-
<string>\b(module|namespace)\b</string>
2431-
<key>name</key>
2432-
<string>storage.type.ts</string>
2433-
</dict>
24342472
<key>string</key>
24352473
<dict>
24362474
<key>name</key>

TypeScriptReact.YAML-tmLanguage

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,10 @@ repository:
122122
- include: '#class-or-interface-declaration'
123123
- include: '#type-declaration'
124124
- include: '#enum-declaration'
125+
- include: '#namespace-declaration'
125126
- include: '#import-equals-declaration'
126127
- include: '#import-declaration'
127128
- include: '#export-declaration'
128-
# TODO: change this to actual declarations of export, import, namespace
129-
- include: '#storage-keyword'
130129

131130
type-declaration:
132131
name: meta.type.declaration.tsx
@@ -152,6 +151,21 @@ repository:
152151
'3': { name: storage.type.enum.tsx }
153152
'4': { name: entity.name.type.enum.tsx }
154153

154+
namespace-declaration:
155+
name: meta.namespace.declaration.tsx
156+
begin: (?:(\bexport)\s+)?\b(?<!\.)(namespace|module)\s+
157+
beginCaptures:
158+
'1': { name: keyword.control.export.tsx }
159+
'2': { name: storage.type.namespace.tsx }
160+
end: (?=$|\{)
161+
patterns:
162+
- include: '#comment'
163+
- include: '#string'
164+
- name: entity.name.type.module.tsx
165+
match: \b([a-zA-Z_$][\w$]*)\b
166+
- name: punctuation.accessor.tsx
167+
match: \.
168+
155169
import-equals-declaration:
156170
patterns:
157171
- name: meta.import-equals.external.tsx
@@ -760,10 +774,6 @@ repository:
760774
- name: keyword.operator.arithmetic.tsx
761775
match: '%|\*|/|-|\+'
762776

763-
storage-keyword:
764-
name: storage.type.tsx
765-
match: \b(module|namespace)\b
766-
767777
paren-expression:
768778
begin: \(
769779
beginCaptures:

TypeScriptReact.tmLanguage

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -559,19 +559,19 @@
559559
</dict>
560560
<dict>
561561
<key>include</key>
562-
<string>#import-equals-declaration</string>
562+
<string>#namespace-declaration</string>
563563
</dict>
564564
<dict>
565565
<key>include</key>
566-
<string>#import-declaration</string>
566+
<string>#import-equals-declaration</string>
567567
</dict>
568568
<dict>
569569
<key>include</key>
570-
<string>#export-declaration</string>
570+
<string>#import-declaration</string>
571571
</dict>
572572
<dict>
573573
<key>include</key>
574-
<string>#storage-keyword</string>
574+
<string>#export-declaration</string>
575575
</dict>
576576
</array>
577577
</dict>
@@ -2069,6 +2069,51 @@
20692069
<key>name</key>
20702070
<string>meta.method.overload.declaration.tsx</string>
20712071
</dict>
2072+
<key>namespace-declaration</key>
2073+
<dict>
2074+
<key>begin</key>
2075+
<string>(?:(\bexport)\s+)?\b(?&lt;!\.)(namespace|module)\s+</string>
2076+
<key>beginCaptures</key>
2077+
<dict>
2078+
<key>1</key>
2079+
<dict>
2080+
<key>name</key>
2081+
<string>keyword.control.export.tsx</string>
2082+
</dict>
2083+
<key>2</key>
2084+
<dict>
2085+
<key>name</key>
2086+
<string>storage.type.namespace.tsx</string>
2087+
</dict>
2088+
</dict>
2089+
<key>end</key>
2090+
<string>(?=$|\{)</string>
2091+
<key>name</key>
2092+
<string>meta.namespace.declaration.tsx</string>
2093+
<key>patterns</key>
2094+
<array>
2095+
<dict>
2096+
<key>include</key>
2097+
<string>#comment</string>
2098+
</dict>
2099+
<dict>
2100+
<key>include</key>
2101+
<string>#string</string>
2102+
</dict>
2103+
<dict>
2104+
<key>match</key>
2105+
<string>\b([a-zA-Z_$][\w$]*)\b</string>
2106+
<key>name</key>
2107+
<string>entity.name.type.module.tsx</string>
2108+
</dict>
2109+
<dict>
2110+
<key>match</key>
2111+
<string>\.</string>
2112+
<key>name</key>
2113+
<string>punctuation.accessor.tsx</string>
2114+
</dict>
2115+
</array>
2116+
</dict>
20722117
<key>new-expr</key>
20732118
<dict>
20742119
<key>begin</key>
@@ -2825,13 +2870,6 @@
28252870
<key>name</key>
28262871
<string>storage.modifier.tsx</string>
28272872
</dict>
2828-
<key>storage-keyword</key>
2829-
<dict>
2830-
<key>match</key>
2831-
<string>\b(module|namespace)\b</string>
2832-
<key>name</key>
2833-
<string>storage.type.tsx</string>
2834-
</dict>
28352873
<key>string</key>
28362874
<dict>
28372875
<key>name</key>

tests/baselines/Issue200.baseline.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ original file
2020
^
2121
source.ts
2222
^^^^^^
23-
source.ts storage.type.ts
23+
source.ts meta.namespace.declaration.ts storage.type.namespace.ts
2424
^
25-
source.ts
25+
source.ts meta.namespace.declaration.ts
2626
^
27-
source.ts string.quoted.single.ts punctuation.definition.string.begin.ts
27+
source.ts meta.namespace.declaration.ts string.quoted.single.ts punctuation.definition.string.begin.ts
2828
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29-
source.ts string.quoted.single.ts
29+
source.ts meta.namespace.declaration.ts string.quoted.single.ts
3030
^
31-
source.ts string.quoted.single.ts punctuation.definition.string.end.ts
31+
source.ts meta.namespace.declaration.ts string.quoted.single.ts punctuation.definition.string.end.ts
3232
^
33-
source.ts
33+
source.ts meta.namespace.declaration.ts
3434
^
3535
source.ts meta.block.ts punctuation.definition.block.ts
3636
^^

tests/baselines/Issue200.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ original file
1616
^^^^^^^
1717
[3, 1]: source.ts storage.modifier.ts
1818
^^^^^^
19-
[3, 9]: source.ts storage.type.ts
19+
[3, 9]: source.ts meta.namespace.declaration.ts storage.type.namespace.ts
2020
^
21-
[3, 16]: source.ts string.quoted.single.ts punctuation.definition.string.begin.ts
21+
[3, 16]: source.ts meta.namespace.declaration.ts string.quoted.single.ts punctuation.definition.string.begin.ts
2222
> import alias = lool.clutz.goog.i18n.NumberFormatSymbols_en_TT;
2323
^^^^^^
2424
[4, 3]: source.ts meta.block.ts meta.import-equals.internal.ts keyword.control.import.ts

tests/baselines/Issue37.baseline.txt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,13 @@ var j: I = {}
382382
source.ts
383383
>module M {
384384
^^^^^^
385-
source.ts storage.type.ts
386-
^^^
387-
source.ts
385+
source.ts meta.namespace.declaration.ts storage.type.namespace.ts
386+
^
387+
source.ts meta.namespace.declaration.ts
388+
^
389+
source.ts meta.namespace.declaration.ts entity.name.type.module.ts
390+
^
391+
source.ts meta.namespace.declaration.ts
388392
^
389393
source.ts meta.block.ts punctuation.definition.block.ts
390394
> export function myFun(x: number) {
@@ -574,9 +578,13 @@ var j: I = {}
574578
source.ts
575579
>module Body {
576580
^^^^^^
577-
source.ts storage.type.ts
578-
^^^^^^
579-
source.ts
581+
source.ts meta.namespace.declaration.ts storage.type.namespace.ts
582+
^
583+
source.ts meta.namespace.declaration.ts
584+
^^^^
585+
source.ts meta.namespace.declaration.ts entity.name.type.module.ts
586+
^
587+
source.ts meta.namespace.declaration.ts
580588
^
581589
source.ts meta.block.ts punctuation.definition.block.ts
582590
> export class Cell {

tests/baselines/Issue37.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ var j: I = {}
150150
>
151151
>module M {
152152
^^^^^^
153-
[35, 1]: source.ts storage.type.ts
153+
[35, 1]: source.ts meta.namespace.declaration.ts storage.type.namespace.ts
154154
> export function myFun(x: number) {
155155
^^^^^^
156156
[36, 5]: source.ts meta.block.ts meta.function.ts keyword.control.export.ts
@@ -176,9 +176,9 @@ var j: I = {}
176176
>
177177
>module Body {
178178
^^^^^^
179-
[51, 1]: source.ts storage.type.ts
180-
^^^^^^
181-
[51, 8]: source.ts
179+
[51, 1]: source.ts meta.namespace.declaration.ts storage.type.namespace.ts
180+
^^^^
181+
[51, 8]: source.ts meta.namespace.declaration.ts entity.name.type.module.ts
182182
> export class Cell {
183183
^^^^^^
184184
[52, 5]: source.ts meta.block.ts meta.declaration.object.ts keyword.control.export.ts

0 commit comments

Comments
 (0)