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