1; Variables
2
3(identifier) @variable
4
5; Special identifiers
6
7((identifier) @type
8 (#match? @type "^[A-Z]"))
9(type_identifier) @type
10(predefined_type) @type.builtin
11
12;; Highlights object literals by hijacking the statement_block pattern, but only if
13;; the statement block follows an object literal pattern
14((statement_block
15 (labeled_statement
16 ;; highlight the label like a property name
17 label: (statement_identifier) @property.name
18 body: [
19 ;; match a terminating expression statement
20 (expression_statement
21 ;; single identifier - treat as a type name
22 [(identifier) @type.name
23 ;; object - treat as a property - type pair
24 (object
25 (pair
26 key: (_) @property.name
27 value: (_) @type.name))
28 ;; subscript_expression - treat as an array declaration
29 (subscript_expression
30 object: (_) @type.name
31 index: (_)
32 )
33 ;; templated string - treat each identifier contained as a type name
34 (template_string
35 (template_substitution
36 (identifier) @type.name))
37 ])
38 ;; match a nested statement block
39 (statement_block) @nested
40 ])))
41
42(import_specifier
43 "type"
44 name: (identifier) @type
45 alias: (identifier) @type
46)
47
48(import_statement
49 "type"
50 (import_clause
51 (named_imports
52 (import_specifier
53 name: (identifier) @type
54 alias: (identifier) @type
55 )
56 )
57 )
58)
59
60([
61 (identifier)
62 (shorthand_property_identifier)
63 (shorthand_property_identifier_pattern)
64 ] @constant
65 (#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
66
67; Properties
68
69(property_identifier) @property
70(shorthand_property_identifier) @property
71(shorthand_property_identifier_pattern) @property
72(private_property_identifier) @property
73
74; Function and method calls
75
76(call_expression
77 function: (identifier) @function)
78
79(call_expression
80 function: (member_expression
81 property: [(property_identifier) (private_property_identifier)] @function.method))
82
83; Function and method definitions
84
85(function_expression
86 name: (identifier) @function)
87(function_declaration
88 name: (identifier) @function)
89(method_definition
90 name: [(property_identifier) (private_property_identifier)] @function.method)
91(method_definition
92 name: (property_identifier) @constructor
93 (#eq? @constructor "constructor"))
94
95(pair
96 key: [(property_identifier) (private_property_identifier)] @function.method
97 value: [(function_expression) (arrow_function)])
98
99(assignment_expression
100 left: (member_expression
101 property: [(property_identifier) (private_property_identifier)] @function.method)
102 right: [(function_expression) (arrow_function)])
103
104(variable_declarator
105 name: (identifier) @function
106 value: [(function_expression) (arrow_function)])
107
108(assignment_expression
109 left: (identifier) @function
110 right: [(function_expression) (arrow_function)])
111
112(arrow_function) @function
113
114; Literals
115
116(this) @variable.special
117(super) @variable.special
118
119[
120 (null)
121 (undefined)
122] @constant.builtin
123
124[
125 (true)
126 (false)
127] @boolean
128
129(literal_type
130 [
131 (null)
132 (undefined)
133 (true)
134 (false)
135 ] @type.builtin
136)
137
138(comment) @comment
139
140(hash_bang_line) @comment
141
142[
143 (string)
144 (template_string)
145 (template_literal_type)
146] @string
147
148(escape_sequence) @string.escape
149
150(regex) @string.regex
151(regex_flags) @keyword.operator.regex
152(number) @number
153
154; Tokens
155
156[
157 ";"
158 "?."
159 "."
160 ","
161 ":"
162 "?"
163] @punctuation.delimiter
164
165[
166 "..."
167 "-"
168 "--"
169 "-="
170 "+"
171 "++"
172 "+="
173 "*"
174 "*="
175 "**"
176 "**="
177 "/"
178 "/="
179 "%"
180 "%="
181 "<"
182 "<="
183 "<<"
184 "<<="
185 "="
186 "=="
187 "==="
188 "!"
189 "!="
190 "!=="
191 "=>"
192 ">"
193 ">="
194 ">>"
195 ">>="
196 ">>>"
197 ">>>="
198 "~"
199 "^"
200 "&"
201 "|"
202 "^="
203 "&="
204 "|="
205 "&&"
206 "||"
207 "??"
208 "&&="
209 "||="
210 "??="
211 "..."
212] @operator
213
214(regex "/" @string.regex)
215
216(ternary_expression
217 [
218 "?"
219 ":"
220 ] @operator
221)
222
223[
224 "("
225 ")"
226 "["
227 "]"
228 "{"
229 "}"
230] @punctuation.bracket
231
232(template_substitution
233 "${" @punctuation.special
234 "}" @punctuation.special) @embedded
235
236(template_type
237 "${" @punctuation.special
238 "}" @punctuation.special) @embedded
239
240(type_arguments
241 "<" @punctuation.bracket
242 ">" @punctuation.bracket)
243
244(decorator "@" @punctuation.special)
245
246; Keywords
247
248[
249 "abstract"
250 "as"
251 "async"
252 "await"
253 "class"
254 "const"
255 "debugger"
256 "declare"
257 "default"
258 "delete"
259 "enum"
260 "export"
261 "extends"
262 "from"
263 "function"
264 "get"
265 "implements"
266 "import"
267 "in"
268 "infer"
269 "instanceof"
270 "interface"
271 "is"
272 "keyof"
273 "let"
274 "module"
275 "namespace"
276 "new"
277 "of"
278 "override"
279 "private"
280 "protected"
281 "public"
282 "readonly"
283 "satisfies"
284 "set"
285 "static"
286 "target"
287 "type"
288 "typeof"
289 "using"
290 "var"
291 "void"
292 "with"
293] @keyword
294
295[
296 "break"
297 "case"
298 "catch"
299 "continue"
300 "do"
301 "else"
302 "finally"
303 "for"
304 "if"
305 "return"
306 "switch"
307 "throw"
308 "try"
309 "while"
310 "yield"
311] @keyword.control
312
313(switch_default "default" @keyword.control)