highlights.scm

  1; Variables
  2
  3(identifier) @variable
  4
  5; Properties
  6
  7(property_identifier) @property
  8(shorthand_property_identifier) @property
  9(shorthand_property_identifier_pattern) @property
 10
 11; Function and method calls
 12
 13(call_expression
 14  function: (identifier) @function)
 15
 16(call_expression
 17  function: (member_expression
 18    property: (property_identifier) @function.method))
 19
 20; Function and method definitions
 21
 22(function_expression
 23  name: (identifier) @function)
 24(function_declaration
 25  name: (identifier) @function)
 26(method_definition
 27  name: (property_identifier) @function.method)
 28(method_definition
 29    name: (property_identifier) @constructor
 30    (#eq? @constructor "constructor"))
 31
 32(pair
 33  key: (property_identifier) @function.method
 34  value: [(function_expression) (arrow_function)])
 35
 36(assignment_expression
 37  left: (member_expression
 38    property: (property_identifier) @function.method)
 39  right: [(function_expression) (arrow_function)])
 40
 41(variable_declarator
 42  name: (identifier) @function
 43  value: [(function_expression) (arrow_function)])
 44
 45(assignment_expression
 46  left: (identifier) @function
 47  right: [(function_expression) (arrow_function)])
 48
 49; Special identifiers
 50
 51((identifier) @type
 52 (#match? @type "^[A-Z]"))
 53(type_identifier) @type
 54(predefined_type) @type.builtin
 55
 56([
 57  (identifier)
 58  (shorthand_property_identifier)
 59  (shorthand_property_identifier_pattern)
 60 ] @constant
 61 (#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
 62
 63; Literals
 64
 65(this) @variable.special
 66(super) @variable.special
 67
 68[
 69  (null)
 70  (undefined)
 71] @constant.builtin
 72
 73[
 74  (true)
 75  (false)
 76] @boolean
 77
 78(comment) @comment
 79
 80[
 81  (string)
 82  (template_string)
 83  (template_literal_type)
 84] @string
 85
 86(escape_sequence) @string.escape
 87
 88(regex) @string.regex
 89(regex_flags) @keyword.regex
 90(number) @number
 91
 92; Tokens
 93
 94[
 95  ";"
 96  "?."
 97  "."
 98  ","
 99  ":"
100  "?"
101] @punctuation.delimiter
102
103[
104  "-"
105  "--"
106  "-="
107  "+"
108  "++"
109  "+="
110  "*"
111  "*="
112  "**"
113  "**="
114  "/"
115  "/="
116  "%"
117  "%="
118  "<"
119  "<="
120  "<<"
121  "<<="
122  "="
123  "=="
124  "==="
125  "!"
126  "!="
127  "!=="
128  "=>"
129  ">"
130  ">="
131  ">>"
132  ">>="
133  ">>>"
134  ">>>="
135  "~"
136  "^"
137  "&"
138  "|"
139  "^="
140  "&="
141  "|="
142  "&&"
143  "||"
144  "??"
145  "&&="
146  "||="
147  "??="
148] @operator
149
150[
151  "("
152  ")"
153  "["
154  "]"
155  "{"
156  "}"
157]  @punctuation.bracket
158
159(ternary_expression
160  [
161    "?"
162    ":"
163  ] @operator
164)
165
166[
167  "as"
168  "async"
169  "await"
170  "break"
171  "case"
172  "catch"
173  "class"
174  "const"
175  "continue"
176  "debugger"
177  "default"
178  "delete"
179  "do"
180  "else"
181  "export"
182  "extends"
183  "finally"
184  "for"
185  "from"
186  "function"
187  "get"
188  "if"
189  "import"
190  "in"
191  "instanceof"
192  "is"
193  "let"
194  "new"
195  "of"
196  "return"
197  "satisfies"
198  "set"
199  "static"
200  "switch"
201  "target"
202  "throw"
203  "try"
204  "typeof"
205  "using"
206  "var"
207  "void"
208  "while"
209  "with"
210  "yield"
211] @keyword
212
213(template_substitution
214  "${" @punctuation.special
215  "}" @punctuation.special) @embedded
216
217(template_type
218  "${" @punctuation.special
219  "}" @punctuation.special) @embedded
220
221(type_arguments
222  "<" @punctuation.bracket
223  ">" @punctuation.bracket)
224
225(decorator "@" @punctuation.special)
226
227; Keywords
228
229[ "abstract"
230  "declare"
231  "enum"
232  "export"
233  "implements"
234  "interface"
235  "keyof"
236  "namespace"
237  "private"
238  "protected"
239  "public"
240  "type"
241  "readonly"
242  "override"
243] @keyword
244
245; JSX elements
246(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
247(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
248(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
249
250(jsx_attribute (property_identifier) @attribute.jsx)
251(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx)
252(jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
253(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
254(jsx_attribute "=" @punctuation.delimiter.jsx)
255(jsx_text) @text.jsx