Skip to content

Commit 1863cb2

Browse files
authored
feat(queries): Extract ecma rules (#499)
* feat(queries): Extra ecma rules * Update typescript queries * changelog * fix typo * ignore queries test for ecma
1 parent 065531e commit 1863cb2

File tree

6 files changed

+385
-234
lines changed

6 files changed

+385
-234
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- feat(queries): Extract `ecma` rules
45

56
## 0.12.165 - 2024-03-31
67

queries/ecma/highlights.scm

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
;; Special identifiers
2+
3+
((identifier) @constant
4+
(.match? @constant "^[A-Z_][A-Z_\\d]*$"))
5+
6+
((shorthand_property_identifier) @constant
7+
(.match? @constant "^[A-Z_][A-Z_\\d]*$"))
8+
9+
((identifier) @constructor
10+
(.match? @constructor "^[A-Z]"))
11+
12+
((identifier) @variable.builtin
13+
(.match? @variable.builtin "^(arguments|module|console|window|document)$")
14+
(.is-not? local))
15+
16+
((identifier) @function.builtin
17+
(.eq? @function.builtin "require")
18+
(.is-not? local))
19+
20+
;; Function and method definitions
21+
22+
(function_expression
23+
name: (identifier) @function)
24+
(function_declaration
25+
name: (identifier) @function)
26+
(generator_function_declaration
27+
name: (identifier) @function)
28+
(method_definition
29+
name: (property_identifier) @method)
30+
31+
(variable_declarator
32+
name: (identifier) @function
33+
value: [(function_expression) (arrow_function)])
34+
35+
(assignment_expression
36+
left: [(identifier) @function
37+
(member_expression property: (property_identifier) @method)]
38+
right: [(function_expression) (arrow_function)])
39+
40+
(pair key: (property_identifier) @method
41+
value: [(function_expression) (arrow_function)])
42+
43+
;; Function and method calls
44+
45+
(call_expression
46+
function: [(identifier) @function.call
47+
(member_expression
48+
property: (property_identifier) @method.call)])
49+
50+
;; Variables
51+
52+
(variable_declarator
53+
name: (identifier) @variable)
54+
(assignment_expression
55+
left: [(identifier) @variable
56+
(member_expression property: (property_identifier) @variable)])
57+
(augmented_assignment_expression
58+
left: [(identifier) @variable
59+
(member_expression property: (property_identifier) @variable)])
60+
(for_in_statement
61+
left: (identifier) @variable)
62+
63+
(arrow_function
64+
parameter: (identifier) @variable.parameter)
65+
;; TypeScript's highlighting patterns reuse this file, so the atter below must work for both
66+
;; JavaScript and TypeScript. Since TypeScript grammar redefines `_formal_parameter`, we use
67+
;; wildcard pattern instead of `formal_parameters`.
68+
(arrow_function
69+
parameters: [(_ (identifier) @variable.parameter)
70+
(_ (_ (identifier) @variable.parameter))
71+
(_ (_ (_ (identifier) @variable.parameter)))])
72+
73+
;; Properties
74+
75+
(pair key: (property_identifier) @property.definition)
76+
(member_expression
77+
property: (property_identifier) @property)
78+
((shorthand_property_identifier) @property.definition)
79+
80+
;; Punctuation
81+
82+
(template_substitution
83+
"${" @punctuation.special
84+
(_)
85+
"}" @punctuation.special)
86+
87+
[";"
88+
"."
89+
","] @punctuation.delimiter
90+
91+
["--"
92+
"-"
93+
"-="
94+
"&&"
95+
"+"
96+
"++"
97+
"+="
98+
"<"
99+
"<="
100+
"<<"
101+
"="
102+
"=="
103+
"==="
104+
"!"
105+
"!="
106+
"!=="
107+
"=>"
108+
">"
109+
">="
110+
">>"
111+
"||"] @operator
112+
113+
["("
114+
")"
115+
"["
116+
"]"
117+
"{"
118+
"}"] @punctuation.bracket
119+
120+
;; Keywords
121+
122+
["as"
123+
"async"
124+
"await"
125+
"break"
126+
"case"
127+
"catch"
128+
"class"
129+
"const"
130+
"continue"
131+
"debugger"
132+
"default"
133+
"delete"
134+
"do"
135+
"else"
136+
"export"
137+
"extends"
138+
"finally"
139+
"for"
140+
"from"
141+
"function"
142+
"get"
143+
"if"
144+
"import"
145+
"in"
146+
"instanceof"
147+
"let"
148+
"new"
149+
"of"
150+
"return"
151+
"set"
152+
"static"
153+
"switch"
154+
"target"
155+
"throw"
156+
"try"
157+
"typeof"
158+
"var"
159+
"void"
160+
"while"
161+
"with"
162+
"yield"] @keyword
163+
164+
165+
;; Misc.
166+
(statement_identifier) @label
167+
168+
169+
;; Literals
170+
171+
[(this) (super) (true) (false)] @variable.builtin
172+
173+
(regex) @string.special
174+
(number) @number
175+
176+
(string) @string
177+
(comment) @comment
178+
179+
(template_substitution
180+
"${"
181+
(_) @embedded
182+
"}")
183+
184+
;; template strings need to be last in the file for embedded expressions
185+
;; to work properly
186+
(template_string) @string

queries/javascript/highlights.scm

Lines changed: 6 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -1,188 +1,8 @@
1-
;; Special identifiers
1+
;; Parameters
22

3-
((identifier) @constant
4-
(.match? @constant "^[A-Z_][A-Z_\\d]*$"))
3+
(formal_parameters
4+
(identifier) @variable.parameter)
55

6-
((shorthand_property_identifier) @constant
7-
(.match? @constant "^[A-Z_][A-Z_\\d]*$"))
8-
9-
((identifier) @constructor
10-
(.match? @constructor "^[A-Z]"))
11-
12-
((identifier) @variable.builtin
13-
(.match? @variable.builtin "^(arguments|module|console|window|document)$")
14-
(.is-not? local))
15-
16-
((identifier) @function.builtin
17-
(.eq? @function.builtin "require")
18-
(.is-not? local))
19-
20-
;; Function and method definitions
21-
22-
(function_expression
23-
name: (identifier) @function)
24-
(function_declaration
25-
name: (identifier) @function)
26-
(generator_function_declaration
27-
name: (identifier) @function)
28-
(method_definition
29-
name: (property_identifier) @method)
30-
31-
(variable_declarator
32-
name: (identifier) @function
33-
value: [(function_expression) (arrow_function)])
34-
35-
(assignment_expression
36-
left: [(identifier) @function
37-
(member_expression property: (property_identifier) @method)]
38-
right: [(function_expression) (arrow_function)])
39-
40-
(pair key: (property_identifier) @method
41-
value: [(function_expression) (arrow_function)])
42-
43-
;; Function and method calls
44-
45-
(call_expression
46-
function: [(identifier) @function.call
47-
(member_expression
48-
property: (property_identifier) @method.call)])
49-
50-
;; Variables
51-
52-
(variable_declarator
53-
name: (identifier) @variable)
54-
(assignment_expression
55-
left: [(identifier) @variable
56-
(member_expression property: (property_identifier) @variable)])
57-
(augmented_assignment_expression
58-
left: [(identifier) @variable
59-
(member_expression property: (property_identifier) @variable)])
60-
(for_in_statement
61-
left: (identifier) @variable)
62-
63-
(arrow_function
64-
parameter: (identifier) @variable.parameter)
65-
;; TypeScript's highlighting patterns reuse this file, so the atter below must work for both
66-
;; JavaScript and TypeScript. Since TypeScript grammar redefines `_formal_parameter`, we use
67-
;; wildcard pattern instead of `formal_parameters`.
68-
(arrow_function
69-
parameters: [(_ (identifier) @variable.parameter)
70-
(_ (_ (identifier) @variable.parameter))
71-
(_ (_ (_ (identifier) @variable.parameter)))])
72-
73-
;; Properties
74-
75-
(pair key: (property_identifier) @property.definition)
76-
(member_expression
77-
property: (property_identifier) @property)
78-
((shorthand_property_identifier) @property.definition)
79-
80-
81-
82-
;; Punctuation
83-
84-
(template_substitution
85-
"${" @punctuation.special
86-
(_)
87-
"}" @punctuation.special)
88-
89-
[";"
90-
"."
91-
","] @punctuation.delimiter
92-
93-
["--"
94-
"-"
95-
"-="
96-
"&&"
97-
"+"
98-
"++"
99-
"+="
100-
"<"
101-
"<="
102-
"<<"
103-
"="
104-
"=="
105-
"==="
106-
"!"
107-
"!="
108-
"!=="
109-
"=>"
110-
">"
111-
">="
112-
">>"
113-
"||"] @operator
114-
115-
["("
116-
")"
117-
"["
118-
"]"
119-
"{"
120-
"}"] @punctuation.bracket
121-
122-
;; Keywords
123-
124-
["as"
125-
"async"
126-
"await"
127-
"break"
128-
"case"
129-
"catch"
130-
"class"
131-
"const"
132-
"continue"
133-
"debugger"
134-
"default"
135-
"delete"
136-
"do"
137-
"else"
138-
"export"
139-
"extends"
140-
"finally"
141-
"for"
142-
"from"
143-
"function"
144-
"get"
145-
"if"
146-
"import"
147-
"in"
148-
"instanceof"
149-
"let"
150-
"new"
151-
"of"
152-
"return"
153-
"set"
154-
"static"
155-
"switch"
156-
"target"
157-
"throw"
158-
"try"
159-
"typeof"
160-
"var"
161-
"void"
162-
"while"
163-
"with"
164-
"yield"] @keyword
165-
166-
167-
;; Misc.
168-
(statement_identifier) @label
169-
170-
171-
;; Literals
172-
173-
[(this) (super) (true) (false)] @variable.builtin
174-
175-
(regex) @string.special
176-
(number) @number
177-
178-
(string) @string
179-
(comment) @comment
180-
181-
(template_substitution
182-
"${"
183-
(_) @embedded
184-
"}")
185-
186-
;; template strings need to be last in the file for embedded expressions
187-
;; to work properly
188-
(template_string) @string
6+
(formal_parameters
7+
(rest_pattern
8+
(identifier) @variable.parameter))

0 commit comments

Comments
 (0)