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(hash_bang_line) @comment
 81
 82[
 83  (string)
 84  (template_string)
 85] @string
 86
 87(escape_sequence) @string.escape
 88
 89(regex) @string.regex
 90(regex_flags) @keyword.operator.regex
 91(number) @number
 92
 93; Tokens
 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(regex "/" @string.regex)
151
152[
153  "("
154  ")"
155  "["
156  "]"
157  "{"
158  "}"
159]  @punctuation.bracket
160
161(ternary_expression
162  [
163    "?"
164    ":"
165  ] @operator
166)
167
168[
169  "as"
170  "async"
171  "await"
172  "break"
173  "case"
174  "catch"
175  "class"
176  "const"
177  "continue"
178  "debugger"
179  "default"
180  "delete"
181  "do"
182  "else"
183  "export"
184  "extends"
185  "finally"
186  "for"
187  "from"
188  "function"
189  "get"
190  "if"
191  "import"
192  "in"
193  "instanceof"
194  "let"
195  "new"
196  "of"
197  "return"
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(type_arguments
218  "<" @punctuation.bracket
219  ">" @punctuation.bracket)
220
221(decorator "@" @punctuation.special)
222
223; Keywords
224
225[ "abstract"
226  "declare"
227  "enum"
228  "export"
229  "implements"
230  "interface"
231  "keyof"
232  "namespace"
233  "private"
234  "protected"
235  "public"
236  "type"
237  "readonly"
238  "override"
239] @keyword
240
241; JSX elements
242(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
243(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
244(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
245
246(jsx_attribute (property_identifier) @attribute.jsx)
247(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx)
248(jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
249(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
250(jsx_attribute "=" @punctuation.delimiter.jsx)
251(jsx_text) @text.jsx