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[
82 (string)
83 (template_string)
84 (template_literal_type)
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 "?"
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 "class"
175 "const"
176 "debugger"
177 "default"
178 "delete"
179 "export"
180 "extends"
181 "from"
182 "function"
183 "get"
184 "import"
185 "in"
186 "instanceof"
187 "is"
188 "let"
189 "new"
190 "of"
191 "satisfies"
192 "set"
193 "static"
194 "target"
195 "typeof"
196 "using"
197 "var"
198 "void"
199 "with"
200] @keyword
201
202[
203 "break"
204 "case"
205 "catch"
206 "continue"
207 "do"
208 "else"
209 "finally"
210 "for"
211 "if"
212 "return"
213 "switch"
214 "throw"
215 "try"
216 "while"
217 "yield"
218] @keyword.control
219
220(switch_default "default" @keyword.control)
221
222(template_substitution
223 "${" @punctuation.special
224 "}" @punctuation.special) @embedded
225
226(template_type
227 "${" @punctuation.special
228 "}" @punctuation.special) @embedded
229
230(type_arguments
231 "<" @punctuation.bracket
232 ">" @punctuation.bracket)
233
234(decorator "@" @punctuation.special)
235
236; Keywords
237
238[ "abstract"
239 "declare"
240 "enum"
241 "export"
242 "implements"
243 "interface"
244 "keyof"
245 "module"
246 "namespace"
247 "private"
248 "protected"
249 "public"
250 "type"
251 "readonly"
252 "override"
253] @keyword
254
255; JSX elements
256(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
257(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
258(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
259
260(jsx_attribute (property_identifier) @attribute.jsx)
261(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx)
262(jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
263(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
264(jsx_attribute "=" @punctuation.delimiter.jsx)
265(jsx_text) @text.jsx