1; Variables
2
3(identifier) @variable
4
5(call_expression
6 function: (member_expression
7 object: (identifier) @type.builtin
8 (#any-of?
9 @type.builtin
10 "Promise"
11 "Array"
12 "Object"
13 "Map"
14 "Set"
15 "WeakMap"
16 "WeakSet"
17 "Date"
18 "Error"
19 "TypeError"
20 "RangeError"
21 "SyntaxError"
22 "ReferenceError"
23 "EvalError"
24 "URIError"
25 "RegExp"
26 "Function"
27 "Number"
28 "String"
29 "Boolean"
30 "Symbol"
31 "BigInt"
32 "Proxy"
33 "ArrayBuffer"
34 "DataView"
35 )
36 )
37)
38
39; Properties
40
41(property_identifier) @property
42(shorthand_property_identifier) @property
43(shorthand_property_identifier_pattern) @property
44(private_property_identifier) @property
45
46; Function and method calls
47
48(call_expression
49 function: (identifier) @function)
50
51(call_expression
52 function: (member_expression
53 property: [(property_identifier) (private_property_identifier)] @function.method))
54
55(new_expression
56 constructor: (identifier) @type)
57
58(nested_type_identifier
59 module: (identifier) @type)
60
61; Function and method definitions
62
63(function_expression
64 name: (identifier) @function)
65(function_declaration
66 name: (identifier) @function)
67(method_definition
68 name: [(property_identifier) (private_property_identifier)] @function.method)
69(method_definition
70 name: (property_identifier) @constructor
71 (#eq? @constructor "constructor"))
72
73(pair
74 key: [(property_identifier) (private_property_identifier)] @function.method
75 value: [(function_expression) (arrow_function)])
76
77(assignment_expression
78 left: (member_expression
79 property: [(property_identifier) (private_property_identifier)] @function.method)
80 right: [(function_expression) (arrow_function)])
81
82(variable_declarator
83 name: (identifier) @function
84 value: [(function_expression) (arrow_function)])
85
86(assignment_expression
87 left: (identifier) @function
88 right: [(function_expression) (arrow_function)])
89
90; Parameters
91
92(required_parameter
93 (identifier) @variable.parameter)
94
95(required_parameter
96 (_
97 ([
98 (identifier)
99 (shorthand_property_identifier_pattern)
100 ]) @variable.parameter))
101
102(optional_parameter
103 (identifier) @variable.parameter)
104
105(optional_parameter
106 (_
107 ([
108 (identifier)
109 (shorthand_property_identifier_pattern)
110 ]) @variable.parameter))
111
112(catch_clause
113 parameter: (identifier) @variable.parameter)
114
115(index_signature
116 name: (identifier) @variable.parameter)
117
118(arrow_function
119 parameter: (identifier) @variable.parameter)
120
121(type_predicate
122 name: (identifier) @variable.parameter)
123
124; Special identifiers
125
126(type_annotation) @type
127(type_identifier) @type
128(predefined_type) @type.builtin
129
130(type_alias_declaration
131 (type_identifier) @type)
132
133(type_alias_declaration
134 value: (_
135 (type_identifier) @type))
136
137(interface_declaration
138 (type_identifier) @type)
139
140(class_declaration
141 (type_identifier) @type.class)
142
143(extends_clause
144 value: (identifier) @type.class)
145
146(extends_type_clause
147 type: (type_identifier) @type)
148
149(implements_clause
150 (type_identifier) @type)
151
152([
153 (identifier)
154 (shorthand_property_identifier)
155 (shorthand_property_identifier_pattern)
156 ] @constant
157 (#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
158
159; Literals
160
161(this) @variable.special
162(super) @variable.special
163
164[
165 (null)
166 (undefined)
167] @constant.builtin
168
169[
170 (true)
171 (false)
172] @boolean
173
174(comment) @comment
175
176[
177 (string)
178 (template_string)
179 (template_literal_type)
180] @string
181
182(escape_sequence) @string.escape
183
184(regex) @string.regex
185(regex_flags) @keyword.operator.regex
186(number) @number
187
188; Tokens
189
190[
191 ";"
192 "?."
193 "."
194 ","
195 ":"
196 "?"
197] @punctuation.delimiter
198
199[
200 "-"
201 "--"
202 "-="
203 "+"
204 "++"
205 "+="
206 "*"
207 "*="
208 "**"
209 "**="
210 "/"
211 "/="
212 "%"
213 "%="
214 "<"
215 "<="
216 "<<"
217 "<<="
218 "="
219 "=="
220 "==="
221 "!"
222 "!="
223 "!=="
224 "=>"
225 ">"
226 ">="
227 ">>"
228 ">>="
229 ">>>"
230 ">>>="
231 "~"
232 "^"
233 "&"
234 "|"
235 "^="
236 "&="
237 "|="
238 "&&"
239 "||"
240 "??"
241 "&&="
242 "||="
243 "??="
244 "..."
245] @operator
246
247(regex "/" @string.regex)
248
249[
250 "("
251 ")"
252 "["
253 "]"
254 "{"
255 "}"
256] @punctuation.bracket
257
258(ternary_expression
259 [
260 "?"
261 ":"
262 ] @operator
263)
264
265[
266 "as"
267 "async"
268 "await"
269 "class"
270 "const"
271 "debugger"
272 "default"
273 "delete"
274 "export"
275 "extends"
276 "from"
277 "function"
278 "get"
279 "import"
280 "in"
281 "instanceof"
282 "is"
283 "let"
284 "new"
285 "of"
286 "satisfies"
287 "set"
288 "static"
289 "target"
290 "typeof"
291 "using"
292 "var"
293 "void"
294 "with"
295] @keyword
296
297[
298 "break"
299 "case"
300 "catch"
301 "continue"
302 "do"
303 "else"
304 "finally"
305 "for"
306 "if"
307 "return"
308 "switch"
309 "throw"
310 "try"
311 "while"
312 "yield"
313] @keyword.control
314
315(switch_default "default" @keyword.control)
316
317(template_substitution
318 "${" @punctuation.special
319 "}" @punctuation.special) @embedded
320
321(template_type
322 "${" @punctuation.special
323 "}" @punctuation.special) @embedded
324
325(type_arguments
326 "<" @punctuation.bracket
327 ">" @punctuation.bracket)
328
329(type_parameters
330 "<" @punctuation.bracket
331 ">" @punctuation.bracket)
332
333(decorator "@" @punctuation.special)
334
335(union_type
336 ("|") @punctuation.special)
337
338(intersection_type
339 ("&") @punctuation.special)
340
341(type_annotation
342 (":") @punctuation.special)
343
344(index_signature
345 (":") @punctuation.special)
346
347(type_predicate_annotation
348 (":") @punctuation.special)
349
350(public_field_definition
351 ("?") @punctuation.special)
352
353(property_signature
354 ("?") @punctuation.special)
355
356(method_signature
357 ("?") @punctuation.special)
358
359(optional_parameter
360 ([
361 "?"
362 ":"
363 ]) @punctuation.special)
364
365; Keywords
366
367[ "abstract"
368 "declare"
369 "enum"
370 "export"
371 "implements"
372 "interface"
373 "keyof"
374 "module"
375 "namespace"
376 "private"
377 "protected"
378 "public"
379 "type"
380 "readonly"
381 "override"
382] @keyword
383
384; JSX elements
385(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
386(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
387(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
388
389(jsx_opening_element
390 [
391 (identifier) @type
392 (member_expression
393 object: (identifier) @type
394 property: (property_identifier) @type
395 )
396 ]
397)
398(jsx_closing_element
399 [
400 (identifier) @type
401 (member_expression
402 object: (identifier) @type
403 property: (property_identifier) @type
404 )
405 ]
406)
407(jsx_self_closing_element
408 [
409 (identifier) @type
410 (member_expression
411 object: (identifier) @type
412 property: (property_identifier) @type
413 )
414 ]
415)
416
417(jsx_attribute (property_identifier) @attribute.jsx)
418(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx)
419(jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
420(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
421(jsx_attribute "=" @punctuation.delimiter.jsx)
422(jsx_text) @text.jsx