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] @string
 84
 85(escape_sequence) @string.escape
 86
 87(regex) @string.regex
 88(regex_flags) @keyword.regex
 89(number) @number
 90
 91; Tokens
 92
 93[
 94  ";"
 95  "?."
 96  "."
 97  ","
 98  ":"
 99] @punctuation.delimiter
100
101[
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] @operator
147
148[
149  "("
150  ")"
151  "["
152  "]"
153  "{"
154  "}"
155]  @punctuation.bracket
156
157(ternary_expression
158  [
159    "?"
160    ":"
161  ] @operator
162)
163
164[
165  "as"
166  "async"
167  "await"
168  "break"
169  "case"
170  "catch"
171  "class"
172  "const"
173  "continue"
174  "debugger"
175  "default"
176  "delete"
177  "do"
178  "else"
179  "export"
180  "extends"
181  "finally"
182  "for"
183  "from"
184  "function"
185  "get"
186  "if"
187  "import"
188  "in"
189  "instanceof"
190  "let"
191  "new"
192  "of"
193  "return"
194  "set"
195  "static"
196  "switch"
197  "target"
198  "throw"
199  "try"
200  "typeof"
201  "using"
202  "var"
203  "void"
204  "while"
205  "with"
206  "yield"
207] @keyword
208
209(template_substitution
210  "${" @punctuation.special
211  "}" @punctuation.special) @embedded
212
213(type_arguments
214  "<" @punctuation.bracket
215  ">" @punctuation.bracket)
216
217(decorator "@" @punctuation.special)
218
219; Keywords
220
221[ "abstract"
222  "declare"
223  "enum"
224  "export"
225  "implements"
226  "interface"
227  "keyof"
228  "namespace"
229  "private"
230  "protected"
231  "public"
232  "type"
233  "readonly"
234  "override"
235] @keyword
236
237; JSX elements
238(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
239(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
240(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
241
242(jsx_attribute (property_identifier) @attribute.jsx)
243(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx)
244(jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
245(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
246(jsx_attribute "=" @punctuation.delimiter.jsx)
247(jsx_text) @text.jsx