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.operator.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(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 "is"
195 "let"
196 "new"
197 "of"
198 "return"
199 "satisfies"
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(template_type
220 "${" @punctuation.special
221 "}" @punctuation.special) @embedded
222
223(type_arguments
224 "<" @punctuation.bracket
225 ">" @punctuation.bracket)
226
227(decorator "@" @punctuation.special)
228
229; Keywords
230
231[ "abstract"
232 "declare"
233 "enum"
234 "export"
235 "implements"
236 "interface"
237 "keyof"
238 "namespace"
239 "private"
240 "protected"
241 "public"
242 "type"
243 "readonly"
244 "override"
245] @keyword
246
247; JSX elements
248(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
249(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
250(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
251
252(jsx_attribute (property_identifier) @attribute.jsx)
253(jsx_opening_element (["<" ">"]) @punctuation.bracket.jsx)
254(jsx_closing_element (["</" ">"]) @punctuation.bracket.jsx)
255(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket.jsx)
256(jsx_attribute "=" @punctuation.delimiter.jsx)
257(jsx_text) @text.jsx