aboutsummaryrefslogtreecommitdiff
path: root/runtime/queries/_javascript
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/queries/_javascript')
-rw-r--r--runtime/queries/_javascript/highlights.scm36
-rw-r--r--runtime/queries/_javascript/locals.scm14
-rw-r--r--runtime/queries/_javascript/tags.scm88
3 files changed, 138 insertions, 0 deletions
diff --git a/runtime/queries/_javascript/highlights.scm b/runtime/queries/_javascript/highlights.scm
new file mode 100644
index 00000000..8b0bbb94
--- /dev/null
+++ b/runtime/queries/_javascript/highlights.scm
@@ -0,0 +1,36 @@
+; Function and method parameters
+;-------------------------------
+
+; Javascript and Typescript Treesitter grammars deviate when defining the
+; tree structure for parameters, so we need to address them in each specific
+; language instead of ecma.
+
+; (p)
+(formal_parameters
+ (identifier) @variable.parameter)
+
+; (...p)
+(formal_parameters
+ (rest_pattern
+ (identifier) @variable.parameter))
+
+; ({ p })
+(formal_parameters
+ (object_pattern
+ (shorthand_property_identifier_pattern) @variable.parameter))
+
+; ({ a: p })
+(formal_parameters
+ (object_pattern
+ (pair_pattern
+ value: (identifier) @variable.parameter)))
+
+; ([ p ])
+(formal_parameters
+ (array_pattern
+ (identifier) @variable.parameter))
+
+; (p = 1)
+(formal_parameters
+ (assignment_pattern
+ left: (identifier) @variable.parameter))
diff --git a/runtime/queries/_javascript/locals.scm b/runtime/queries/_javascript/locals.scm
new file mode 100644
index 00000000..94356616
--- /dev/null
+++ b/runtime/queries/_javascript/locals.scm
@@ -0,0 +1,14 @@
+; Definitions
+;------------
+; Javascript and Typescript Treesitter grammars deviate when defining the
+; tree structure for parameters, so we need to address them in each specific
+; language instead of ecma.
+
+; (i)
+(formal_parameters
+ (identifier) @local.definition)
+
+; (i = 1)
+(formal_parameters
+ (assignment_pattern
+ left: (identifier) @local.definition))
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