1; Variables
2
3(identifier) @variable
4
5(call_expression
6 function: (member_expression
7 object: (identifier) @type
8 (#any-of?
9 @type
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; Special identifiers
122;
123(class_declaration
124 (type_identifier) @type.class)
125
126(extends_clause
127 value: (identifier) @type.class)
128
129(type_identifier) @type
130(predefined_type) @type.builtin
131
132([
133 (identifier)
134 (shorthand_property_identifier)
135 (shorthand_property_identifier_pattern)
136 ] @constant
137 (#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
138
139; Literals
140
141(this) @variable.special
142(super) @variable.special
143
144[
145 (null)
146 (undefined)
147] @constant.builtin
148
149[
150 (true)
151 (false)
152] @boolean
153
154(comment) @comment
155
156(hash_bang_line) @comment
157
158[
159 (string)
160 (template_string)
161] @string
162
163(escape_sequence) @string.escape
164
165(regex) @string.regex
166(regex_flags) @keyword.operator.regex
167(number) @number
168
169; Tokens
170
171[
172 ";"
173 "?."
174 "."
175 ","
176 ":"
177] @punctuation.delimiter
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 "^"
213 "&"
214 "|"
215 "^="
216 "&="
217 "|="
218 "&&"
219 "||"
220 "??"
221 "&&="
222 "||="
223 "??="
224 "..."
225] @operator
226
227(regex "/" @string.regex)
228
229[
230 "("
231 ")"
232 "["
233 "]"
234 "{"
235 "}"
236] @punctuation.bracket
237
238(ternary_expression
239 [
240 "?"
241 ":"
242 ] @operator
243)
244
245[
246 "as"
247 "async"
248 "await"
249 "debugger"
250 "default"
251 "delete"
252 "extends"
253 "get"
254 "in"
255 "instanceof"
256 "new"
257 "of"
258 "set"
259 "static"
260 "target"
261 "typeof"
262 "using"
263 "void"
264 "with"
265] @keyword
266
267[
268 "const"
269 "let"
270 "var"
271 "function"
272 "class"
273] @keyword.declaration
274
275[
276 "export"
277 "from"
278 "import"
279] @keyword.import
280
281[
282 "break"
283 "case"
284 "catch"
285 "continue"
286 "do"
287 "else"
288 "finally"
289 "for"
290 "if"
291 "return"
292 "switch"
293 "throw"
294 "try"
295 "while"
296 "yield"
297] @keyword.control
298
299(switch_default "default" @keyword.control)
300
301(template_substitution
302 "${" @punctuation.special
303 "}" @punctuation.special) @embedded
304
305(type_arguments
306 "<" @punctuation.bracket
307 ">" @punctuation.bracket)
308
309(decorator "@" @punctuation.special)
310
311; Keywords
312
313[ "abstract"
314 "declare"
315 "enum"
316 "export"
317 "implements"
318 "interface"
319 "keyof"
320 "module"
321 "namespace"
322 "private"
323 "protected"
324 "public"
325 "type"
326 "readonly"
327 "override"
328] @keyword
329
330; JSX elements
331(jsx_opening_element
332 [
333 (identifier) @type
334 (member_expression
335 object: (identifier) @type
336 property: (property_identifier) @type
337 )
338 ]
339)
340(jsx_closing_element
341 [
342 (identifier) @type
343 (member_expression
344 object: (identifier) @type
345 property: (property_identifier) @type
346 )
347 ]
348)
349(jsx_self_closing_element
350 [
351 (identifier) @type
352 (member_expression
353 object: (identifier) @type
354 property: (property_identifier) @type
355 )
356 ]
357)
358
359(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
360(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
361(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
362(jsx_attribute (property_identifier) @attribute.jsx)
363(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx)
364(jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
365(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
366(jsx_attribute "=" @punctuation.delimiter.jsx)
367(jsx_text) @text.jsx