aboutsummaryrefslogtreecommitdiff
path: root/runtime/queries/javascript
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-04-09 08:42:49 +0000
committerBlaž Hrastnik2021-04-09 09:57:46 +0000
commit4e31d1521bf9bb59f6485954d4ada16bf853c85a (patch)
treed8d05c9303701590dee6351eea693887dbab3981 /runtime/queries/javascript
parentc1e5733b02e4ba39b82d7b330fab0b2ded2220f2 (diff)
Add tree-sitter queries.
Diffstat (limited to 'runtime/queries/javascript')
-rw-r--r--runtime/queries/javascript/highlights-jsx.scm4
-rw-r--r--runtime/queries/javascript/highlights-params.scm12
-rw-r--r--runtime/queries/javascript/highlights.scm205
-rw-r--r--runtime/queries/javascript/injections.scm20
-rw-r--r--runtime/queries/javascript/locals.scm23
-rw-r--r--runtime/queries/javascript/tags.scm88
6 files changed, 352 insertions, 0 deletions
diff --git a/runtime/queries/javascript/highlights-jsx.scm b/runtime/queries/javascript/highlights-jsx.scm
new file mode 100644
index 00000000..751da081
--- /dev/null
+++ b/runtime/queries/javascript/highlights-jsx.scm
@@ -0,0 +1,4 @@
+(jsx_opening_element (identifier) @tag)
+(jsx_closing_element (identifier) @tag)
+(jsx_self_closing_element (identifier) @tag)
+(jsx_attribute (property_identifier) @attribute)
diff --git a/runtime/queries/javascript/highlights-params.scm b/runtime/queries/javascript/highlights-params.scm
new file mode 100644
index 00000000..95ffc724
--- /dev/null
+++ b/runtime/queries/javascript/highlights-params.scm
@@ -0,0 +1,12 @@
+(formal_parameters
+ [
+ (identifier) @variable.parameter
+ (array_pattern
+ (identifier) @variable.parameter)
+ (object_pattern
+ [
+ (pair_pattern value: (identifier) @variable.parameter)
+ (shorthand_property_identifier_pattern) @variable.parameter
+ ])
+ ]
+)
diff --git a/runtime/queries/javascript/highlights.scm b/runtime/queries/javascript/highlights.scm
new file mode 100644
index 00000000..a18c38d9
--- /dev/null
+++ b/runtime/queries/javascript/highlights.scm
@@ -0,0 +1,205 @@
+; Special identifiers
+;--------------------
+
+([
+ (identifier)
+ (shorthand_property_identifier)
+ (shorthand_property_identifier_pattern)
+ ] @constant
+ (#match? @constant "^[A-Z_][A-Z\\d_]+$"))
+
+
+((identifier) @constructor
+ (#match? @constructor "^[A-Z]"))
+
+((identifier) @variable.builtin
+ (#match? @variable.builtin "^(arguments|module|console|window|document)$")
+ (#is-not? local))
+
+((identifier) @function.builtin
+ (#eq? @function.builtin "require")
+ (#is-not? local))
+
+; Function and method definitions
+;--------------------------------
+
+(function
+ name: (identifier) @function)
+(function_declaration
+ name: (identifier) @function)
+(method_definition
+ name: (property_identifier) @function.method)
+
+(pair
+ key: (property_identifier) @function.method
+ value: [(function) (arrow_function)])
+
+(assignment_expression
+ left: (member_expression
+ property: (property_identifier) @function.method)
+ right: [(function) (arrow_function)])
+
+(variable_declarator
+ name: (identifier) @function
+ value: [(function) (arrow_function)])
+
+(assignment_expression
+ left: (identifier) @function
+ right: [(function) (arrow_function)])
+
+; Function and method calls
+;--------------------------
+
+(call_expression
+ function: (identifier) @function)
+
+(call_expression
+ function: (member_expression
+ property: (property_identifier) @function.method))
+
+; Variables
+;----------
+
+(identifier) @variable
+
+; Properties
+;-----------
+
+(property_identifier) @property
+
+; Literals
+;---------
+
+(this) @variable.builtin
+(super) @variable.builtin
+
+[
+ (true)
+ (false)
+ (null)
+ (undefined)
+] @constant.builtin
+
+(comment) @comment
+
+[
+ (string)
+ (template_string)
+] @string
+
+(regex) @string.special
+(number) @number
+
+; Tokens
+;-------
+
+(template_substitution
+ "${" @punctuation.special
+ "}" @punctuation.special) @embedded
+
+[
+ ";"
+ "?."
+ "."
+ ","
+] @punctuation.delimiter
+
+[
+ "-"
+ "--"
+ "-="
+ "+"
+ "++"
+ "+="
+ "*"
+ "*="
+ "**"
+ "**="
+ "/"
+ "/="
+ "%"
+ "%="
+ "<"
+ "<="
+ "<<"
+ "<<="
+ "="
+ "=="
+ "==="
+ "!"
+ "!="
+ "!=="
+ "=>"
+ ">"
+ ">="
+ ">>"
+ ">>="
+ ">>>"
+ ">>>="
+ "~"
+ "^"
+ "&"
+ "|"
+ "^="
+ "&="
+ "|="
+ "&&"
+ "||"
+ "??"
+ "&&="
+ "||="
+ "??="
+] @operator
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+] @punctuation.bracket
+
+[
+ "as"
+ "async"
+ "await"
+ "break"
+ "case"
+ "catch"
+ "class"
+ "const"
+ "continue"
+ "debugger"
+ "default"
+ "delete"
+ "do"
+ "else"
+ "export"
+ "extends"
+ "finally"
+ "for"
+ "from"
+ "function"
+ "get"
+ "if"
+ "import"
+ "in"
+ "instanceof"
+ "let"
+ "new"
+ "of"
+ "return"
+ "set"
+ "static"
+ "switch"
+ "target"
+ "throw"
+ "try"
+ "typeof"
+ "var"
+ "void"
+ "while"
+ "with"
+ "yield"
+] @keyword
diff --git a/runtime/queries/javascript/injections.scm b/runtime/queries/javascript/injections.scm
new file mode 100644
index 00000000..5539241a
--- /dev/null
+++ b/runtime/queries/javascript/injections.scm
@@ -0,0 +1,20 @@
+; Parse the contents of tagged template literals using
+; a language inferred from the tag.
+
+(call_expression
+ function: [
+ (identifier) @injection.language
+ (member_expression
+ property: (property_identifier) @injection.language)
+ ]
+ arguments: (template_string) @injection.content)
+
+; Parse regex syntax within regex literals
+
+((regex_pattern) @injection.content
+ (#set! injection.language "regex"))
+
+ ; Parse JSDoc annotations in comments
+
+((comment) @injection.content
+ (#set! injection.language "jsdoc"))
diff --git a/runtime/queries/javascript/locals.scm b/runtime/queries/javascript/locals.scm
new file mode 100644
index 00000000..5d680acf
--- /dev/null
+++ b/runtime/queries/javascript/locals.scm
@@ -0,0 +1,23 @@
+; Scopes
+;-------
+
+[
+ (statement_block)
+ (function)
+ (arrow_function)
+ (function_declaration)
+ (method_definition)
+] @local.scope
+
+; Definitions
+;------------
+
+(pattern/identifier)@local.definition
+
+(variable_declarator
+ name: (identifier) @local.definition)
+
+; References
+;------------
+
+(identifier) @local.reference
diff --git a/runtime/queries/javascript/tags.scm b/runtime/queries/javascript/tags.scm
new file mode 100644
index 00000000..a7bbd311
--- /dev/null
+++ b/runtime/queries/javascript/tags.scm
@@ -0,0 +1,88 @@
+(
+ (comment)* @doc
+ .
+ (method_definition
+ name: (property_identifier) @name) @definition.method
+ (#not-eq? @name "constructor")
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
+ (#select-adjacent! @doc @definition.method)
+)
+
+(
+ (comment)* @doc
+ .
+ [
+ (class
+ name: (_) @name)
+ (class_declaration
+ name: (_) @name)
+ ] @definition.class
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
+ (#select-adjacent! @doc @definition.class)
+)
+
+(
+ (comment)* @doc
+ .
+ [
+ (function
+ name: (identifier) @name)
+ (function_declaration
+ name: (identifier) @name)
+ (generator_function
+ name: (identifier) @name)
+ (generator_function_declaration
+ name: (identifier) @name)
+ ] @definition.function
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
+ (#select-adjacent! @doc @definition.function)
+)
+
+(
+ (comment)* @doc
+ .
+ (lexical_declaration
+ (variable_declarator
+ name: (identifier) @name
+ value: [(arrow_function) (function)]) @definition.function)
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
+ (#select-adjacent! @doc @definition.function)
+)
+
+(
+ (comment)* @doc
+ .
+ (variable_declaration
+ (variable_declarator
+ name: (identifier) @name
+ value: [(arrow_function) (function)]) @definition.function)
+ (#strip! @doc "^[\\s\\*/]+|^[\\s\\*/]$")
+ (#select-adjacent! @doc @definition.function)
+)
+
+(assignment_expression
+ left: [
+ (identifier) @name
+ (member_expression
+ property: (property_identifier) @name)
+ ]
+ right: [(arrow_function) (function)]
+) @definition.function
+
+(pair
+ key: (property_identifier) @name
+ value: [(arrow_function) (function)]) @definition.function
+
+(
+ (call_expression
+ function: (identifier) @name) @reference.call
+ (#not-match? @name "^(require)$")
+)
+
+(call_expression
+ function: (member_expression
+ property: (property_identifier) @name)
+ arguments: (_) @reference.call)
+
+(new_expression
+ constructor: (_) @name) @reference.class