Skip to content

Commit 4774bec

Browse files
committed
Support Import equals and import declarations
1 parent c817285 commit 4774bec

13 files changed

+870
-79
lines changed

TypeScript.YAML-tmLanguage

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ repository:
117117
- include: '#class-or-interface-declaration'
118118
- include: '#type-declaration'
119119
- include: '#enum-declaration'
120-
# Todo: to change this to import declaration
121-
- include: '#import-operator'
120+
- include: '#import-equals-declaration'
121+
- include: '#import-declaration'
122122
# TODO: change this to actual declarations of export, import, namespace
123123
- include: '#storage-keyword'
124124

@@ -146,6 +146,88 @@ repository:
146146
'3': { name: storage.type.enum.ts }
147147
'4': { name: entity.name.type.enum.ts }
148148

149+
import-equals-declaration:
150+
patterns:
151+
- name: meta.import-equals.external.ts
152+
begin: (?:(\bexport)\s+)?\b(?<!\.)(import)\s+([a-zA-Z_$][\w$]*)\s*(=)\s*(require)\s*(\()
153+
beginCaptures:
154+
'1': { name: keyword.control.export.ts }
155+
'2': { name: keyword.control.import.ts }
156+
'3': { name: variable.other.readwrite.alias.ts }
157+
'4': { name: keyword.operator.assignment.ts }
158+
'5': { name: keyword.control.require.ts }
159+
'6': { name: meta.brace.round.ts }
160+
end: \)
161+
endCaptures:
162+
'0': { name: meta.brace.round.ts }
163+
patterns:
164+
- include: '#comment'
165+
- include: '#string'
166+
- name: meta.import-equals.internal.ts
167+
begin: (?:(\bexport)\s+)?\b(?<!\.)(import)\s+([a-zA-Z_$][\w$]*)\s*(=)\s*(?!require\b)
168+
beginCaptures:
169+
'1': { name: keyword.control.export.ts }
170+
'2': { name: keyword.control.import.ts }
171+
'3': { name: variable.other.readwrite.alias.ts }
172+
'4': { name: keyword.operator.assignment.ts }
173+
end: (?=;|$)
174+
patterns:
175+
- include: '#comment'
176+
- match: \b([a-zA-Z_$][\w$]*)\s*(\.)
177+
captures:
178+
'1': { name: entity.name.module.ts }
179+
'2': { name: punctuation.accessor.ts }
180+
- name: variable.other.readwrite.ts
181+
match: \b([a-zA-Z_$][\w$]*)\b
182+
183+
import-declaration:
184+
name: meta.import.ts
185+
begin: (?:(\bexport)\s+)?(?<!\.)\b(import)(?!\s*:)\b
186+
beginCaptures:
187+
'1': { name: keyword.control.export.ts }
188+
'2': { name: keyword.control.import.ts }
189+
end: (?=;|$)
190+
patterns:
191+
- include: '#comment'
192+
- include: '#string'
193+
- include: '#import-block'
194+
- name: keyword.control.from.ts
195+
match: \bfrom\b
196+
- include: '#import-clause'
197+
198+
import-block:
199+
name: meta.block.ts
200+
begin: \{
201+
beginCaptures:
202+
'0': { name: punctuation.definition.block.ts }
203+
end: \}
204+
endCaptures:
205+
'0': { name: punctuation.definition.block.ts }
206+
patterns:
207+
- include: '#import-clause'
208+
209+
import-clause:
210+
patterns:
211+
- include: '#comment'
212+
- comment: (default|*|name) as alias
213+
match: '(?x) (?: \b(default)\b | (\*) | \b([a-zA-Z_$][a-zA-Z_$0-9]*)\b) \s* (\b
214+
as \b) \s* (?: (\b default \b | \*) | \b([a-zA-Z_$][a-zA-Z_$0-9]*)\b)'
215+
captures:
216+
'1': { name: keyword.control.default.ts }
217+
'2': { name: constant.language.import-all.ts }
218+
'3': { name: variable.other.readwrite.ts }
219+
'4': { name: keyword.control.as.ts }
220+
'5': { name: invalid.illegal.ts }
221+
'6': { name: variable.other.readwrite.alias.ts }
222+
- name: meta.delimiter.object.comma.ts
223+
match: ','
224+
- name: constant.language.import-all.ts
225+
match: \*
226+
- name: keyword.control.default.ts
227+
match: \b(default)\b
228+
- name: variable.other.readwrite.alias.ts
229+
match: \b([a-zA-Z_$][a-zA-Z_$0-9]*)\b
230+
149231
class-or-interface-declaration:
150232
name: meta.declaration.object.ts
151233
begin: '\b(?:(export)\s+)?\b(?:(abstract)\s+)?\b(?<!\.)(?:(class)|(interface))\b'
@@ -634,13 +716,6 @@ repository:
634716
name: storage.type.function.arrow.ts
635717
match: =>
636718

637-
import-operator:
638-
patterns:
639-
- name: keyword.control.import.ts
640-
match: \bimport\b
641-
- name: keyword.control.from.ts
642-
match: \bfrom\b
643-
644719
operators:
645720
patterns:
646721
- name: keyword.operator.assignment.compound.ts

0 commit comments

Comments
 (0)