highlights.scm

  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(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  "abstract"
267  "as"
268  "async"
269  "await"
270  "debugger"
271  "declare"
272  "default"
273  "delete"
274  "extends"
275  "get"
276  "implements"
277  "in"
278  "infer"
279  "instanceof"
280  "is"
281  "keyof"
282  "module"
283  "namespace"
284  "new"
285  "of"
286  "override"
287  "private"
288  "protected"
289  "public"
290  "readonly"
291  "satisfies"
292  "set"
293  "static"
294  "target"
295  "typeof"
296  "using"
297  "void"
298  "with"
299] @keyword
300
301[
302  "const"
303  "let"
304  "var"
305  "function"
306  "class"
307  "enum"
308  "interface"
309  "type"
310] @keyword.declaration
311
312[
313  "export"
314  "from"
315  "import"
316] @keyword.import
317
318[
319  "break"
320  "case"
321  "catch"
322  "continue"
323  "do"
324  "else"
325  "finally"
326  "for"
327  "if"
328  "return"
329  "switch"
330  "throw"
331  "try"
332  "while"
333  "yield"
334] @keyword.control
335
336(switch_default "default" @keyword.control)
337
338(template_substitution
339  "${" @punctuation.special
340  "}" @punctuation.special) @embedded
341
342(template_type
343  "${" @punctuation.special
344  "}" @punctuation.special) @embedded
345
346(type_arguments
347  "<" @punctuation.bracket
348  ">" @punctuation.bracket)
349
350(type_parameters
351  "<" @punctuation.bracket
352  ">" @punctuation.bracket)
353
354(decorator "@" @punctuation.special)
355
356(union_type
357  ("|") @punctuation.special)
358
359(intersection_type
360  ("&") @punctuation.special)
361
362(type_annotation
363  (":") @punctuation.special)
364
365(index_signature
366  (":") @punctuation.special)
367
368(type_predicate_annotation
369  (":") @punctuation.special)
370
371(public_field_definition
372  ("?") @punctuation.special)
373
374(property_signature
375  ("?") @punctuation.special)
376
377(method_signature
378  ("?") @punctuation.special)
379
380(optional_parameter
381  ([
382    "?"
383    ":"
384  ]) @punctuation.special)
385
386; Keywords
387
388[ "abstract"
389  "declare"
390  "enum"
391  "export"
392  "implements"
393  "interface"
394  "keyof"
395  "module"
396  "namespace"
397  "private"
398  "protected"
399  "public"
400  "type"
401  "readonly"
402  "override"
403] @keyword
404
405(jsx_opening_element
406  [
407    (identifier) @type
408    (member_expression
409      object: (identifier) @type
410      property: (property_identifier) @type
411    )
412  ]
413)
414(jsx_closing_element
415  [
416    (identifier) @type
417    (member_expression
418      object: (identifier) @type
419      property: (property_identifier) @type
420    )
421  ]
422)
423(jsx_self_closing_element
424  [
425    (identifier) @type
426    (member_expression
427      object: (identifier) @type
428      property: (property_identifier) @type
429    )
430  ]
431)
432
433(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
434(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
435(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
436
437(jsx_attribute (property_identifier) @attribute.jsx)
438(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx)
439(jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
440(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
441(jsx_attribute "=" @punctuation.delimiter.jsx)
442(jsx_text) @text.jsx