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