on master help sign in
Inherit javascript/typescript from common 'ecma' queries (#3301)
08b442fMichael Davis
runtime/queries/ecma/highlights.scmnew file+221
@@ -0,0 +1,221 @@
1+; Special identifiers
2+;--------------------
3+
4+([
5+ (identifier)
6+ (shorthand_property_identifier)
7+ (shorthand_property_identifier_pattern)
8+ ] @constant
9+ (#match? @constant "^[A-Z_][A-Z\\d_]+$"))
10+
11+
12+((identifier) @constructor
13+ (#match? @constructor "^[A-Z]"))
14+
15+((identifier) @variable.builtin
16+ (#match? @variable.builtin "^(arguments|module|console|window|document)$")
17+ (#is-not? local))
18+
19+((identifier) @function.builtin
20+ (#eq? @function.builtin "require")
21+ (#is-not? local))
22+
23+; Function and method definitions
24+;--------------------------------
25+
26+(function
27+ name: (identifier) @function)
28+(function_declaration
29+ name: (identifier) @function)
30+(method_definition
31+ name: (property_identifier) @function.method)
32+
33+(pair
34+ key: (property_identifier) @function.method
35+ value: [(function) (arrow_function)])
36+
37+(assignment_expression
38+ left: (member_expression
39+ property: (property_identifier) @function.method)
40+ right: [(function) (arrow_function)])
41+
42+(variable_declarator
43+ name: (identifier) @function
44+ value: [(function) (arrow_function)])
45+
46+(assignment_expression
47+ left: (identifier) @function
48+ right: [(function) (arrow_function)])
49+
50+
51+; Function and method calls
52+;--------------------------
53+
54+(call_expression
55+ function: (identifier) @function)
56+
57+(call_expression
58+ function: (member_expression
59+ property: (property_identifier) @function.method))
60+
61+; Variables
62+;----------
63+
64+(identifier) @variable
65+
66+; Properties
67+;-----------
68+
69+(property_identifier) @variable.other.member
70+(shorthand_property_identifier) @variable.other.member
71+(shorthand_property_identifier_pattern) @variable.other.member
72+
73+; Literals
74+;---------
75+
76+(this) @variable.builtin
77+(super) @variable.builtin
78+
79+[
80+ (true)
81+ (false)
82+ (null)
83+ (undefined)
84+] @constant.builtin
85+
86+(comment) @comment
87+
88+[
89+ (string)
90+ (template_string)
91+] @string
92+
93+(regex) @string.regexp
94+(number) @constant.numeric.integer
95+
96+; Tokens
97+;-------
98+
99+(template_substitution
100+ "${" @punctuation.special
101+ "}" @punctuation.special) @embedded
102+
103+[
104+ ";"
105+ "?."
106+ "."
107+ ","
108+] @punctuation.delimiter
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+ "||"
151+ "??"
152+ "&&="
153+ "||="
154+ "??="
155+ "..."
156+] @operator
157+
158+(ternary_expression ["?" ":"] @operator)
159+
160+[
161+ "("
162+ ")"
163+ "["
164+ "]"
165+ "{"
166+ "}"
167+] @punctuation.bracket
168+
169+[
170+ "as"
171+ "async"
172+ "debugger"
173+ "delete"
174+ "extends"
175+ "from"
176+ "function"
177+ "get"
178+ "in"
179+ "instanceof"
180+ "new"
181+ "of"
182+ "set"
183+ "static"
184+ "target"
185+ "try"
186+ "typeof"
187+ "void"
188+ "with"
189+] @keyword
190+
191+[
192+ "class"
193+ "let"
194+ "const"
195+ "var"
196+] @keyword.storage.type
197+
198+[
199+ "switch"
200+ "case"
201+ "default"
202+ "if"
203+ "else"
204+ "yield"
205+ "throw"
206+ "finally"
207+ "return"
208+ "catch"
209+ "continue"
210+ "while"
211+ "break"
212+ "for"
213+ "do"
214+ "await"
215+] @keyword.control
216+
217+[
218+ "import"
219+ "export"
220+] @keyword.control.import
221+
runtime/queries/ecma/indents.scmnew file+22
@@ -0,0 +1,22 @@
1+[
2+ (array)
3+ (object)
4+ (arguments)
5+ (formal_parameters)
6+
7+ (statement_block)
8+ (object_pattern)
9+ (class_body)
10+ (named_imports)
11+
12+ (binary_expression)
13+ (return_statement)
14+ (template_substitution)
15+ (export_clause)
16+] @indent
17+
18+[
19+ "}"
20+ "]"
21+ ")"
22+] @outdent
runtime/queries/ecma/injections.scmnew file+36
@@ -0,0 +1,36 @@
1+; Parse the contents of tagged template literals using
2+; a language inferred from the tag.
3+
4+(call_expression
5+ function: [
6+ (identifier) @injection.language
7+ (member_expression
8+ property: (property_identifier) @injection.language)
9+ ]
10+ arguments: (template_string) @injection.content)
11+
12+; Parse the contents of gql template literals
13+
14+((call_expression
15+ function: (identifier) @_template_function_name
16+ arguments: (template_string) @injection.content)
17+ (#eq? @_template_function_name "gql")
18+ (#set! injection.language "graphql"))
19+
20+; Parse regex syntax within regex literals
21+
22+((regex_pattern) @injection.content
23+ (#set! injection.language "regex"))
24+
25+; Parse JSDoc annotations in multiline comments
26+
27+((comment) @injection.content
28+ (#set! injection.language "jsdoc")
29+ (#match? @injection.content "^/\\*+"))
30+
31+; Parse general tags in single line comments
32+
33+((comment) @injection.content
34+ (#set! injection.language "comment")
35+ (#match? @injection.content "^//"))
36+
runtime/queries/ecma/locals.scmnew file+29
@@ -0,0 +1,29 @@
1+; Scopes
2+;-------
3+
4+[
5+ (statement_block)
6+ (function)
7+ (arrow_function)
8+ (function_declaration)
9+ (method_definition)
10+] @local.scope
11+
12+; Definitions
13+;------------
14+
15+(pattern/identifier) @local.definition
16+
17+(pattern/rest_pattern
18+ (identifier) @local.definition)
19+
20+(arrow_function
21+ parameter: (identifier) @local.definition)
22+
23+(variable_declarator
24+ name: (identifier) @local.definition)
25+
26+; References
27+;------------
28+
29+(identifier) @local.reference
runtime/queries/ecma/textobjects.scmnew file+36
@@ -0,0 +1,36 @@
1+(function_declaration
2+ body: (_) @function.inside) @function.around
3+
4+(function
5+ body: (_) @function.inside) @function.around
6+
7+(arrow_function
8+ body: (_) @function.inside) @function.around
9+
10+(method_definition
11+ body: (_) @function.inside) @function.around
12+
13+(generator_function_declaration
14+ body: (_) @function.inside) @function.around
15+
16+(class_declaration
17+ body: (class_body) @class.inside) @class.around
18+
19+(class
20+ (class_body) @class.inside) @class.around
21+
22+(export_statement
23+ declaration: [
24+ (function_declaration) @function.around
25+ (class_declaration) @class.around
26+ ])
27+
28+(formal_parameters
29+ ((_) @parameter.inside . ","? @parameter.around) @parameter.around)
30+
31+(arguments
32+ ((_) @parameter.inside . ","? @parameter.around) @parameter.around)
33+
34+(comment) @comment.inside
35+
36+(comment)+ @comment.around
runtime/queries/javascript/highlights.scm+1−220
@@ -1,52 +1,3 @@
1−; Special identifiers
2−;--------------------
3−
4−([
5− (identifier)
6− (shorthand_property_identifier)
7− (shorthand_property_identifier_pattern)
8− ] @constant
9− (#match? @constant "^[A-Z_][A-Z\\d_]+$"))
10−
11−
12−((identifier) @constructor
13− (#match? @constructor "^[A-Z]"))
14−
15−((identifier) @variable.builtin
16− (#match? @variable.builtin "^(arguments|module|console|window|document)$")
17− (#is-not? local))
18−
19−((identifier) @function.builtin
20− (#eq? @function.builtin "require")
21− (#is-not? local))
22−
23−; Function and method definitions
24−;--------------------------------
25−
26−(function
27− name: (identifier) @function)
28−(function_declaration
29− name: (identifier) @function)
30−(method_definition
31− name: (property_identifier) @function.method)
32−
33−(pair
34− key: (property_identifier) @function.method
35− value: [(function) (arrow_function)])
36−
37−(assignment_expression
38− left: (member_expression
39− property: (property_identifier) @function.method)
40− right: [(function) (arrow_function)])
41−
42−(variable_declarator
43− name: (identifier) @function
44− value: [(function) (arrow_function)])
45−
46−(assignment_expression
47− left: (identifier) @function
48− right: [(function) (arrow_function)])
49−
50; Function and method parameters
1; Function and method parameters
51;-------------------------------
2;-------------------------------
52
3
@@ -84,174 +35,4 @@
84(arrow_function
35(arrow_function
85 parameter: (identifier) @variable.parameter)
36 parameter: (identifier) @variable.parameter)
86
37
87−; Function and method calls
38+; inherits: ecma
88−;--------------------------
89−
90−(call_expression
91− function: (identifier) @function)
92−
93−(call_expression
94− function: (member_expression
95− property: (property_identifier) @function.method))
96−
97−; Variables
98−;----------
99−
100−(identifier) @variable
101−
102−; Properties
103−;-----------
104−
105−(property_identifier) @variable.other.member
106−(shorthand_property_identifier) @variable.other.member
107−(shorthand_property_identifier_pattern) @variable.other.member
108−
109−; Literals
110−;---------
111−
112−(this) @variable.builtin
113−(super) @variable.builtin
114−
115−[
116− (true)
117− (false)
118− (null)
119− (undefined)
120−] @constant.builtin
121−
122−(comment) @comment
123−
124−[
125− (string)
126− (template_string)
127−] @string
128−
129−(regex) @string.regexp
130−(number) @constant.numeric.integer
131−
132−; Tokens
133−;-------
134−
135−(template_substitution
136− "${" @punctuation.special
137− "}" @punctuation.special) @embedded
138−
139−[
140− ";"
141− "?."
142− "."
143− ","
144−] @punctuation.delimiter
145−
146−[
147− "-"
148− "--"
149− "-="
150− "+"
151− "++"
152− "+="
153− "*"
154− "*="
155− "**"
156− "**="
157− "/"
158− "/="
159− "%"
160− "%="
161− "<"
162− "<="
163− "<<"
164− "<<="
165− "="
166− "=="
167− "==="
168− "!"
169− "!="
170− "!=="
171− "=>"
172− ">"
173− ">="
174− ">>"
175− ">>="
176− ">>>"
177− ">>>="
178− "~"
179− "^"
180− "&"
181− "|"
182− "^="
183− "&="
184− "|="
185− "&&"
186− "||"
187− "??"
188− "&&="
189− "||="
190− "??="
191− "..."
192−] @operator
193−
194−(ternary_expression ["?" ":"] @operator)
195−
196−[
197− "("
198− ")"
199− "["
200− "]"
201− "{"
202− "}"
203−] @punctuation.bracket
204−
205−[
206− "as"
207− "async"
208− "debugger"
209− "delete"
210− "extends"
211− "from"
212− "function"
213− "get"
214− "in"
215− "instanceof"
216− "new"
217− "of"
218− "set"
219− "static"
220− "target"
221− "try"
222− "typeof"
223− "void"
224− "with"
225−] @keyword
226−
227−[
228− "class"
229− "let"
230− "const"
231− "var"
232−] @keyword.storage.type
233−
234−[
235− "switch"
236− "case"
237− "default"
238− "if"
239− "else"
240− "yield"
241− "throw"
242− "finally"
243− "return"
244− "catch"
245− "continue"
246− "while"
247− "break"
248− "for"
249− "do"
250− "await"
251−] @keyword.control
252−
253−[
254− "import"
255− "export"
256−] @keyword.control.import
257−
runtime/queries/javascript/indents.scm+1−22
@@ -1,22 +1 @@
1−[
1+; inherits: ecma
2− (array)
3− (object)
4− (arguments)
5− (formal_parameters)
6−
7− (statement_block)
8− (object_pattern)
9− (class_body)
10− (named_imports)
11−
12− (binary_expression)
13− (return_statement)
14− (template_substitution)
15− (export_clause)
16−] @indent
17−
18−[
19− "}"
20− "]"
21− ")"
22−] @outdent
runtime/queries/javascript/injections.scm+1−36
@@ -1,36 +1 @@
1−; Parse the contents of tagged template literals using
1+; inherits: ecma
2−; a language inferred from the tag.
3−
4−(call_expression
5− function: [
6− (identifier) @injection.language
7− (member_expression
8− property: (property_identifier) @injection.language)
9− ]
10− arguments: (template_string) @injection.content)
11−
12−; Parse the contents of gql template literals
13−
14−((call_expression
15− function: (identifier) @_template_function_name
16− arguments: (template_string) @injection.content)
17− (#eq? @_template_function_name "gql")
18− (#set! injection.language "graphql"))
19−
20−; Parse regex syntax within regex literals
21−
22−((regex_pattern) @injection.content
23− (#set! injection.language "regex"))
24−
25−; Parse JSDoc annotations in multiline comments
26−
27−((comment) @injection.content
28− (#set! injection.language "jsdoc")
29− (#match? @injection.content "^/\\*+"))
30−
31−; Parse general tags in single line comments
32−
33−((comment) @injection.content
34− (#set! injection.language "comment")
35− (#match? @injection.content "^//"))
36−
runtime/queries/javascript/locals.scm+1−29
@@ -1,29 +1 @@
1−; Scopes
1+; inherits: ecma
2−;-------
3−
4−[
5− (statement_block)
6− (function)
7− (arrow_function)
8− (function_declaration)
9− (method_definition)
10−] @local.scope
11−
12−; Definitions
13−;------------
14−
15−(pattern/identifier) @local.definition
16−
17−(pattern/rest_pattern
18− (identifier) @local.definition)
19−
20−(arrow_function
21− parameter: (identifier) @local.definition)
22−
23−(variable_declarator
24− name: (identifier) @local.definition)
25−
26−; References
27−;------------
28−
29−(identifier) @local.reference
runtime/queries/javascript/textobjects.scm+1−36
@@ -1,36 +1 @@
1−(function_declaration
1+; inherits: ecma
2− body: (_) @function.inside) @function.around
3−
4−(function
5− body: (_) @function.inside) @function.around
6−
7−(arrow_function
8− body: (_) @function.inside) @function.around
9−
10−(method_definition
11− body: (_) @function.inside) @function.around
12−
13−(generator_function_declaration
14− body: (_) @function.inside) @function.around
15−
16−(class_declaration
17− body: (class_body) @class.inside) @class.around
18−
19−(class
20− (class_body) @class.inside) @class.around
21−
22−(export_statement
23− declaration: [
24− (function_declaration) @function.around
25− (class_declaration) @class.around
26− ])
27−
28−(formal_parameters
29− ((_) @parameter.inside . ","? @parameter.around) @parameter.around)
30−
31−(arguments
32− ((_) @parameter.inside . ","? @parameter.around) @parameter.around)
33−
34−(comment) @comment.inside
35−
36−(comment)+ @comment.around
runtime/queries/jsx/highlights.scm+1−1
@@ -1,4 +1,4 @@
1−; inherits: javascript
1+; inherits: ecma
2
2
3; Highlight component names differently
3; Highlight component names differently
4(jsx_opening_element ((identifier) @constructor
4(jsx_opening_element ((identifier) @constructor
runtime/queries/jsx/indents.scm+1−1
@@ -1 +1 @@
1−; inherits: javascript
1+; inherits: ecma
runtime/queries/jsx/injections.scm+1−1
@@ -1 +1 @@
1−; inherits: javascript
1+; inherits: ecma
runtime/queries/jsx/locals.scm+1−1
@@ -1 +1 @@
1−; inherits: javascript
1+; inherits: ecma
runtime/queries/jsx/textobjects.scm+1−1
@@ -1 +1 @@
1−; inherits: javascript
1+; inherits: ecma
runtime/queries/svelte/indents.scm+1−1
@@ -1,4 +1,4 @@
1−; inherits: javascript
1+; inherits: ecma
2
2
3[
3[
4 (element)
4 (element)
runtime/queries/typescript/highlights.scm+1−1
@@ -49,7 +49,7 @@
49 "readonly"
49 "readonly"
50] @keyword.storage.modifier
50] @keyword.storage.modifier
51
51
52−; inherits: javascript
52+; inherits: ecma
53
53
54; Types
54; Types
55
55
runtime/queries/typescript/indents.scm+1−1
@@ -1,4 +1,4 @@
1−; inherits: javascript
1+; inherits: ecma
2
2
3[
3[
4 (enum_declaration)
4 (enum_declaration)
runtime/queries/typescript/injections.scm+1−1
@@ -1 +1 @@
1−; inherits: javascript
1+; inherits: ecma
runtime/queries/typescript/textobjects.scm+1−1
@@ -1,4 +1,4 @@
1−; inherits: javascript
1+; inherits: ecma
2
2
3[
3[
4 (interface_declaration
4 (interface_declaration