aboutsummaryrefslogtreecommitdiffstats
path: root/queries/ecma
diff options
context:
space:
mode:
authorPham Huy Hoang <hoangtun0810@gmail.com>2024-01-06 15:05:50 +0900
committerChristian Clason <c.clason@uni-graz.at>2024-01-19 16:58:37 +0100
commit57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9 (patch)
tree70bf645539882b88e6fa129cefd30986b89bbac3 /queries/ecma
parentci: add query lint job (diff)
downloadnvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar.gz
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar.bz2
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar.lz
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar.xz
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.tar.zst
nvim-treesitter-57a8acf0c4ed5e7f6dda83c3f9b073f8a99a70f9.zip
chore: query formatting
Diffstat (limited to 'queries/ecma')
-rw-r--r--queries/ecma/highlights.scm207
-rw-r--r--queries/ecma/indents.scm52
-rw-r--r--queries/ecma/injections.scm155
-rw-r--r--queries/ecma/locals.scm15
4 files changed, 243 insertions, 186 deletions
diff --git a/queries/ecma/highlights.scm b/queries/ecma/highlights.scm
index b6fd64668..223198410 100644
--- a/queries/ecma/highlights.scm
+++ b/queries/ecma/highlights.scm
@@ -1,92 +1,60 @@
; Types
-
; Javascript
-
; Variables
;-----------
(identifier) @variable
; Properties
;-----------
-
(property_identifier) @property
+
(shorthand_property_identifier) @property
+
(private_property_identifier) @property
(variable_declarator
- name: (object_pattern
- (shorthand_property_identifier_pattern))) @variable
+ name:
+ (object_pattern
+ (shorthand_property_identifier_pattern))) @variable
; Special identifiers
;--------------------
-
((identifier) @type
- (#lua-match? @type "^[A-Z]"))
+ (#lua-match? @type "^[A-Z]"))
((identifier) @constant
- (#lua-match? @constant "^_*[A-Z][A-Z%d_]*$"))
+ (#lua-match? @constant "^_*[A-Z][A-Z%d_]*$"))
((shorthand_property_identifier) @constant
- (#lua-match? @constant "^_*[A-Z][A-Z%d_]*$"))
+ (#lua-match? @constant "^_*[A-Z][A-Z%d_]*$"))
((identifier) @variable.builtin
- (#any-of? @variable.builtin
- "arguments"
- "module"
- "console"
- "window"
- "document"))
+ (#any-of? @variable.builtin "arguments" "module" "console" "window" "document"))
((identifier) @type.builtin
- (#any-of? @type.builtin
- "Object"
- "Function"
- "Boolean"
- "Symbol"
- "Number"
- "Math"
- "Date"
- "String"
- "RegExp"
- "Map"
- "Set"
- "WeakMap"
- "WeakSet"
- "Promise"
- "Array"
- "Int8Array"
- "Uint8Array"
- "Uint8ClampedArray"
- "Int16Array"
- "Uint16Array"
- "Int32Array"
- "Uint32Array"
- "Float32Array"
- "Float64Array"
- "ArrayBuffer"
- "DataView"
- "Error"
- "EvalError"
- "InternalError"
- "RangeError"
- "ReferenceError"
- "SyntaxError"
- "TypeError"
- "URIError"))
+ (#any-of? @type.builtin "Object" "Function" "Boolean" "Symbol" "Number" "Math" "Date" "String" "RegExp" "Map" "Set" "WeakMap" "WeakSet" "Promise" "Array" "Int8Array" "Uint8Array" "Uint8ClampedArray" "Int16Array" "Uint16Array" "Int32Array" "Uint32Array" "Float32Array" "Float64Array" "ArrayBuffer" "DataView" "Error" "EvalError" "InternalError" "RangeError" "ReferenceError" "SyntaxError" "TypeError" "URIError"))
; Function and method definitions
;--------------------------------
-
(function
name: (identifier) @function)
+
(function_declaration
name: (identifier) @function)
+
(generator_function
name: (identifier) @function)
+
(generator_function_declaration
name: (identifier) @function)
+
(method_definition
- name: [(property_identifier) (private_property_identifier)] @function.method)
+ name:
+ [
+ (property_identifier)
+ (private_property_identifier)
+ ] @function.method)
+
(method_definition
name: (property_identifier) @constructor
(#eq? @constructor "constructor"))
@@ -94,22 +62,27 @@
(pair
key: (property_identifier) @function.method
value: (function))
+
(pair
key: (property_identifier) @function.method
value: (arrow_function))
(assignment_expression
- left: (member_expression
- property: (property_identifier) @function.method)
+ left:
+ (member_expression
+ property: (property_identifier) @function.method)
right: (arrow_function))
+
(assignment_expression
- left: (member_expression
- property: (property_identifier) @function.method)
+ left:
+ (member_expression
+ property: (property_identifier) @function.method)
right: (function))
(variable_declarator
name: (identifier) @function
value: (arrow_function))
+
(variable_declarator
name: (identifier) @function
value: (function))
@@ -117,42 +90,35 @@
(assignment_expression
left: (identifier) @function
right: (arrow_function))
+
(assignment_expression
left: (identifier) @function
right: (function))
; Function and method calls
;--------------------------
-
(call_expression
function: (identifier) @function.call)
(call_expression
- function: (member_expression
- property: [(property_identifier) (private_property_identifier)] @function.method.call))
+ function:
+ (member_expression
+ property:
+ [
+ (property_identifier)
+ (private_property_identifier)
+ ] @function.method.call))
; Builtins
;---------
-
((identifier) @module.builtin
- (#eq? @module.builtin "Intl"))
+ (#eq? @module.builtin "Intl"))
((identifier) @function.builtin
- (#any-of? @function.builtin
- "eval"
- "isFinite"
- "isNaN"
- "parseFloat"
- "parseInt"
- "decodeURI"
- "decodeURIComponent"
- "encodeURI"
- "encodeURIComponent"
- "require"))
+ (#any-of? @function.builtin "eval" "isFinite" "isNaN" "parseFloat" "parseInt" "decodeURI" "decodeURIComponent" "encodeURI" "encodeURIComponent" "require"))
; Constructor
;------------
-
(new_expression
constructor: (identifier) @constructor)
@@ -163,19 +129,24 @@
; Decorators
;----------
-(decorator "@" @attribute (identifier) @attribute)
-(decorator "@" @attribute (call_expression (identifier) @attribute))
+(decorator
+ "@" @attribute
+ (identifier) @attribute)
+
+(decorator
+ "@" @attribute
+ (call_expression
+ (identifier) @attribute))
; Literals
;---------
-
[
(this)
(super)
] @variable.builtin
((identifier) @variable.builtin
- (#eq? @variable.builtin "self"))
+ (#eq? @variable.builtin "self"))
[
(true)
@@ -195,30 +166,45 @@
(hash_bang_line) @keyword.directive
((string_fragment) @keyword.directive
- (#eq? @keyword.directive "use strict"))
+ (#eq? @keyword.directive "use strict"))
(string) @string
+
(template_string) @string
+
(escape_sequence) @string.escape
+
(regex_pattern) @string.regexp
+
(regex_flags) @character.special
-(regex "/" @punctuation.bracket) ; Regex delimiters
+
+(regex
+ "/" @punctuation.bracket) ; Regex delimiters
(number) @number
+
((identifier) @number
(#any-of? @number "NaN" "Infinity"))
; Punctuation
;------------
-
";" @punctuation.delimiter
+
"." @punctuation.delimiter
+
"," @punctuation.delimiter
-(pair ":" @punctuation.delimiter)
-(pair_pattern ":" @punctuation.delimiter)
-(switch_case ":" @punctuation.delimiter)
-(switch_default ":" @punctuation.delimiter)
+(pair
+ ":" @punctuation.delimiter)
+
+(pair_pattern
+ ":" @punctuation.delimiter)
+
+(switch_case
+ ":" @punctuation.delimiter)
+
+(switch_default
+ ":" @punctuation.delimiter)
[
"--"
@@ -265,10 +251,28 @@
"..."
] @operator
-(binary_expression "/" @operator)
-(ternary_expression ["?" ":"] @keyword.conditional.ternary)
-(unary_expression ["!" "~" "-" "+"] @operator)
-(unary_expression ["delete" "void"] @keyword.operator)
+(binary_expression
+ "/" @operator)
+
+(ternary_expression
+ [
+ "?"
+ ":"
+ ] @keyword.conditional.ternary)
+
+(unary_expression
+ [
+ "!"
+ "~"
+ "-"
+ "+"
+ ] @operator)
+
+(unary_expression
+ [
+ "delete"
+ "void"
+ ] @keyword.operator)
[
"("
@@ -279,11 +283,14 @@
"}"
] @punctuation.bracket
-((template_substitution ["${" "}"] @punctuation.special) @none)
+((template_substitution
+ [
+ "${"
+ "}"
+ ] @punctuation.special) @none)
; Keywords
;----------
-
[
"if"
"else"
@@ -296,10 +303,17 @@
"from"
] @keyword.import
-(export_specifier "as" @keyword.import)
-(import_specifier "as" @keyword.import)
-(namespace_export "as" @keyword.import)
-(namespace_import "as" @keyword.import)
+(export_specifier
+ "as" @keyword.import)
+
+(import_specifier
+ "as" @keyword.import)
+
+(namespace_export
+ "as" @keyword.import)
+
+(namespace_import
+ "as" @keyword.import)
[
"for"
@@ -335,9 +349,7 @@
"yield"
] @keyword.return
-[
- "function"
-] @keyword.function
+"function" @keyword.function
[
"new"
@@ -356,5 +368,6 @@
(export_statement
"default" @keyword)
+
(switch_default
"default" @keyword.conditional)
diff --git a/queries/ecma/indents.scm b/queries/ecma/indents.scm
index 538c5bdc7..03b10c605 100644
--- a/queries/ecma/indents.scm
+++ b/queries/ecma/indents.scm
@@ -18,36 +18,56 @@
(ternary_expression)
] @indent.begin
-(arguments (call_expression) @indent.begin)
-(binary_expression (call_expression) @indent.begin)
-(expression_statement (call_expression) @indent.begin)
+(arguments
+ (call_expression) @indent.begin)
+
+(binary_expression
+ (call_expression) @indent.begin)
+
+(expression_statement
+ (call_expression) @indent.begin)
+
(arrow_function
body: (_) @_body
- (#not-has-type? @_body statement_block)
-) @indent.begin
+ (#not-has-type? @_body statement_block)) @indent.begin
+
(assignment_expression
right: (_) @_right
- (#not-has-type? @_right arrow_function function)
-) @indent.begin
+ (#not-has-type? @_right arrow_function function)) @indent.begin
+
(variable_declarator
value: (_) @_value
- (#not-has-type? @_value arrow_function call_expression function)
-) @indent.begin
+ (#not-has-type? @_value arrow_function call_expression function)) @indent.begin
+
+(arguments
+ ")" @indent.end)
-(arguments ")" @indent.end)
-(object "}" @indent.end)
-(statement_block "}" @indent.end)
+(object
+ "}" @indent.end)
+
+(statement_block
+ "}" @indent.end)
[
- (arguments (object))
+ (arguments
+ (object))
")"
"}"
"]"
] @indent.branch
-(statement_block "{" @indent.branch)
-(parenthesized_expression ("(" (_) ")" @indent.end))
-["}" "]"] @indent.end
+(statement_block
+ "{" @indent.branch)
+
+(parenthesized_expression
+ ("("
+ (_)
+ ")" @indent.end))
+
+[
+ "}"
+ "]"
+] @indent.end
(template_string) @indent.ignore
diff --git a/queries/ecma/injections.scm b/queries/ecma/injections.scm
index 97dbbb628..9421d8113 100644
--- a/queries/ecma/injections.scm
+++ b/queries/ecma/injections.scm
@@ -3,98 +3,116 @@
(#set! injection.language "jsdoc"))
((comment) @injection.content
- (#set! injection.language "comment"))
+ (#set! injection.language "comment"))
; html(`...`), html`...`, sql(...) etc
(call_expression
- function: ((identifier) @injection.language)
- arguments: [
- (arguments
- (template_string) @injection.content)
- (template_string) @injection.content
- ]
- (#lua-match? @injection.language "^[a-zA-Z][a-zA-Z0-9]*$")
- (#offset! @injection.content 0 1 0 -1)
- (#not-eq? @injection.language "svg"))
+ function:
+ ((identifier) @injection.language)
+ arguments:
+ [
+ (arguments
+ (template_string) @injection.content)
+ (template_string) @injection.content
+ ]
+ (#lua-match? @injection.language "^[a-zA-Z][a-zA-Z0-9]*$")
+ (#offset! @injection.content 0 1 0 -1)
+ (#not-eq? @injection.language "svg"))
; svg`...` or svg(`...`), which uses the html parser, so is not included in the previous query
(call_expression
- function: ((identifier) @_name (#eq? @_name "svg"))
- arguments: [
- (arguments
- (template_string) @injection.content)
- (template_string) @injection.content
- ]
- (#offset! @injection.content 0 1 0 -1)
- (#set! injection.language "html"))
-
+ function:
+ ((identifier) @_name
+ (#eq? @_name "svg"))
+ arguments:
+ [
+ (arguments
+ (template_string) @injection.content)
+ (template_string) @injection.content
+ ]
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "html"))
(call_expression
- function: ((identifier) @_name
- (#eq? @_name "gql"))
- arguments: ((template_string) @injection.content
- (#offset! @injection.content 0 1 0 -1)
- (#set! injection.language "graphql")))
+ function:
+ ((identifier) @_name
+ (#eq? @_name "gql"))
+ arguments:
+ ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "graphql")))
(call_expression
- function: ((identifier) @_name
- (#eq? @_name "hbs"))
- arguments: ((template_string) @injection.content
- (#offset! @injection.content 0 1 0 -1)
- (#set! injection.language "glimmer")))
+ function:
+ ((identifier) @_name
+ (#eq? @_name "hbs"))
+ arguments:
+ ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "glimmer")))
((glimmer_template) @injection.content
- (#set! injection.language "glimmer"))
+ (#set! injection.language "glimmer"))
; styled.div`<css>`
(call_expression
- function: (member_expression
- object: (identifier) @_name
- (#eq? @_name "styled"))
- arguments: ((template_string) @injection.content
- (#offset! @injection.content 0 1 0 -1)
- (#set! injection.language "styled")))
+ function:
+ (member_expression
+ object: (identifier) @_name
+ (#eq? @_name "styled"))
+ arguments:
+ ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "styled")))
; styled(Component)`<css>`
(call_expression
- function: (call_expression
- function: (identifier) @_name
- (#eq? @_name "styled"))
- arguments: ((template_string) @injection.content
- (#offset! @injection.content 0 1 0 -1)
- (#set! injection.language "styled")))
+ function:
+ (call_expression
+ function: (identifier) @_name
+ (#eq? @_name "styled"))
+ arguments:
+ ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "styled")))
; styled.div.attrs({ prop: "foo" })`<css>`
(call_expression
- function: (call_expression
- function: (member_expression
- object: (member_expression
- object: (identifier) @_name
- (#eq? @_name "styled"))))
- arguments: ((template_string) @injection.content
- (#offset! @injection.content 0 1 0 -1)
- (#set! injection.language "styled")))
-
+ function:
+ (call_expression
+ function:
+ (member_expression
+ object:
+ (member_expression
+ object: (identifier) @_name
+ (#eq? @_name "styled"))))
+ arguments:
+ ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "styled")))
; styled(Component).attrs({ prop: "foo" })`<css>`
(call_expression
- function: (call_expression
- function: (member_expression
- object: (call_expression
- function: (identifier) @_name
- (#eq? @_name "styled"))))
- arguments: ((template_string) @injection.content
- (#offset! @injection.content 0 1 0 -1)
- (#set! injection.language "styled")))
+ function:
+ (call_expression
+ function:
+ (member_expression
+ object:
+ (call_expression
+ function: (identifier) @_name
+ (#eq? @_name "styled"))))
+ arguments:
+ ((template_string) @injection.content
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "styled")))
((regex_pattern) @injection.content
- (#set! injection.language "regex"))
+ (#set! injection.language "regex"))
; ((comment) @_gql_comment
; (#eq? @_gql_comment "/* GraphQL */")
; (template_string) @injection.content
; (#set! injection.language "graphql"))
-
((template_string) @injection.content
(#lua-match? @injection.content "^`#graphql")
(#offset! @injection.content 0 1 0 -1)
@@ -102,20 +120,21 @@
; el.innerHTML = `<html>`
(assignment_expression
- left:
+ left:
(member_expression
property: (property_identifier) @_prop
(#any-of? @_prop "outerHTML" "innerHTML"))
right: (template_string) @injection.content
- (#offset! @injection.content 0 1 0 -1)
- (#set! injection.language "html"))
+ (#offset! @injection.content 0 1 0 -1)
+ (#set! injection.language "html"))
; el.innerHTML = '<html>'
(assignment_expression
- left:
+ left:
(member_expression
property: (property_identifier) @_prop
(#any-of? @_prop "outerHTML" "innerHTML"))
- right:
- (string (string_fragment) @injection.content)
- (#set! injection.language "html"))
+ right:
+ (string
+ (string_fragment) @injection.content)
+ (#set! injection.language "html"))
diff --git a/queries/ecma/locals.scm b/queries/ecma/locals.scm
index 86e565490..54da79335 100644
--- a/queries/ecma/locals.scm
+++ b/queries/ecma/locals.scm
@@ -1,18 +1,23 @@
; Scopes
;-------
-
(statement_block) @local.scope
+
(function) @local.scope
+
(arrow_function) @local.scope
+
(function_declaration) @local.scope
+
(method_definition) @local.scope
+
(for_statement) @local.scope
+
(for_in_statement) @local.scope
+
(catch_clause) @local.scope
; Definitions
;------------
-
(variable_declarator
name: (identifier) @local.definition.var)
@@ -24,14 +29,14 @@
(function_declaration
((identifier) @local.definition.function)
- (#set! definition.var.scope parent))
+ (#set! definition.var.scope parent))
(method_definition
((property_identifier) @local.definition.function)
- (#set! definition.var.scope parent))
+ (#set! definition.var.scope parent))
; References
;------------
-
(identifier) @local.reference
+
(shorthand_property_identifier) @local.reference