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; 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 "class"
250 "const"
251 "debugger"
252 "default"
253 "delete"
254 "export"
255 "extends"
256 "from"
257 "function"
258 "get"
259 "import"
260 "in"
261 "instanceof"
262 "let"
263 "new"
264 "of"
265 "set"
266 "static"
267 "target"
268 "typeof"
269 "using"
270 "var"
271 "void"
272 "with"
273] @keyword
274
275[
276 "break"
277 "case"
278 "catch"
279 "continue"
280 "do"
281 "else"
282 "finally"
283 "for"
284 "if"
285 "return"
286 "switch"
287 "throw"
288 "try"
289 "while"
290 "yield"
291] @keyword.control
292
293(switch_default "default" @keyword.control)
294
295(template_substitution
296 "${" @punctuation.special
297 "}" @punctuation.special) @embedded
298
299(type_arguments
300 "<" @punctuation.bracket
301 ">" @punctuation.bracket)
302
303(decorator "@" @punctuation.special)
304
305; Keywords
306
307[ "abstract"
308 "declare"
309 "enum"
310 "export"
311 "implements"
312 "interface"
313 "keyof"
314 "module"
315 "namespace"
316 "private"
317 "protected"
318 "public"
319 "type"
320 "readonly"
321 "override"
322] @keyword
323
324; JSX elements
325(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
326(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
327(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
328
329(jsx_opening_element
330 [
331 (identifier) @type
332 (member_expression
333 object: (identifier) @type
334 property: (property_identifier) @type
335 )
336 ]
337)
338(jsx_closing_element
339 [
340 (identifier) @type
341 (member_expression
342 object: (identifier) @type
343 property: (property_identifier) @type
344 )
345 ]
346)
347(jsx_self_closing_element
348 [
349 (identifier) @type
350 (member_expression
351 object: (identifier) @type
352 property: (property_identifier) @type
353 )
354 ]
355)
356
357(jsx_attribute (property_identifier) @attribute.jsx)
358(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx)
359(jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
360(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
361(jsx_attribute "=" @punctuation.delimiter.jsx)
362(jsx_text) @text.jsx