aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md4
-rw-r--r--queries/javascript/highlights.scm190
-rw-r--r--queries/javascript/locals.scm35
-rw-r--r--queries/typescript/highlights.scm215
-rw-r--r--queries/typescript/locals.scm37
5 files changed, 479 insertions, 2 deletions
diff --git a/README.md b/README.md
index c31ce8985..0401128b8 100644
--- a/README.md
+++ b/README.md
@@ -159,8 +159,8 @@ List of currently supported languages:
- [ ] cpp
- [ ] rust
- [x] python (maintained by @theHamsta)
-- [ ] javascript
-- [ ] typescript
+- [x] javascript (maintained by @steelsojka)
+- [x] typescript (maintained by @steelsojka)
- [ ] tsx
- [ ] json
- [x] html (maintained by @TravonteD)
diff --git a/queries/javascript/highlights.scm b/queries/javascript/highlights.scm
new file mode 100644
index 000000000..da88d85d0
--- /dev/null
+++ b/queries/javascript/highlights.scm
@@ -0,0 +1,190 @@
+; Types
+
+; Javascript
+; Special identifiers
+;--------------------
+
+((identifier) @constant
+ (#match? @constant "^[A-Z_][A-Z\\d_]+$"))
+
+((shorthand_property_identifier) @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)$"))
+
+((identifier) @function.builtin
+ (#eq? @function.builtin "require"))
+
+; 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))
+(pair
+ key: (property_identifier) @function.method
+ value: (arrow_function))
+
+(assignment_expression
+ left: (member_expression
+ property: (property_identifier) @function.method)
+ right: (arrow_function))
+(assignment_expression
+ 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))
+
+(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_expression
+ function: (member_expression
+ property: (property_identifier) @function.method))
+
+; Variables
+;----------
+
+(formal_parameters (identifier) @variable.parameter)
+
+(identifier) @variable
+
+; Properties
+;-----------
+
+(property_identifier) @property
+
+; Literals
+;---------
+
+(this) @variable.builtin
+(super) @variable.builtin
+
+(true) @constant.builtin
+(false) @constant.builtin
+(null) @constant.builtin
+(comment) @comment
+(string) @string
+(regex) @string.special
+(template_string) @string
+(number) @number
+
+; Punctuation
+;------------
+
+(template_substitution
+ "${" @punctuation.special
+ "}" @punctuation.special) @embedded
+
+";" @punctuation.delimiter
+"." @punctuation.delimiter
+"," @punctuation.delimiter
+
+"--" @operator
+"-" @operator
+"-=" @operator
+"&&" @operator
+"+" @operator
+"++" @operator
+"+=" @operator
+"<" @operator
+"<<" @operator
+"=" @operator
+"==" @operator
+"===" @operator
+"=>" @operator
+">" @operator
+">>" @operator
+"||" @operator
+"??" @operator
+
+"(" @punctuation.bracket
+")" @punctuation.bracket
+"[" @punctuation.bracket
+"]" @punctuation.bracket
+"{" @punctuation.bracket
+"}" @punctuation.bracket
+
+; Keywords
+;----------
+
+[
+"if"
+"else"
+"switch"
+"case"
+"default"
+] @conditional
+
+[
+"import"
+"from"
+"as"
+] @include
+
+[
+"for"
+"of"
+"do"
+"while"
+"continue"
+] @repeat
+
+[
+"async"
+"await"
+"break"
+"catch"
+"class"
+"const"
+"debugger"
+"delete"
+"export"
+"extends"
+"finally"
+"function"
+"get"
+"in"
+"instanceof"
+"let"
+"new"
+"return"
+"set"
+"static"
+"switch"
+"target"
+"throw"
+"try"
+"typeof"
+"var"
+"void"
+"with"
+"yield"
+] @keyword
diff --git a/queries/javascript/locals.scm b/queries/javascript/locals.scm
new file mode 100644
index 000000000..165adfed9
--- /dev/null
+++ b/queries/javascript/locals.scm
@@ -0,0 +1,35 @@
+; Scopes
+;-------
+
+(statement_block) @scope
+(function) @scope
+(arrow_function) @scope
+(function_declaration) @scope
+(method_definition) @scope
+
+; Definitions
+;------------
+
+(formal_parameters
+ (identifier) @definition)
+
+(formal_parameters
+ (object_pattern
+ (identifier) @definition))
+
+(formal_parameters
+ (object_pattern
+ (shorthand_property_identifier) @definition))
+
+(formal_parameters
+ (array_pattern
+ (identifier) @definition))
+
+(variable_declarator
+ name: (identifier) @definition)
+
+; References
+;------------
+
+(identifier) @reference
+
diff --git a/queries/typescript/highlights.scm b/queries/typescript/highlights.scm
new file mode 100644
index 000000000..92820105b
--- /dev/null
+++ b/queries/typescript/highlights.scm
@@ -0,0 +1,215 @@
+; Types
+
+; Javascript
+; Special identifiers
+;--------------------
+
+((identifier) @constant
+ (#match? @constant "^[A-Z_][A-Z\\d_]+$"))
+
+((shorthand_property_identifier) @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)$"))
+
+((identifier) @function.builtin
+ (#eq? @function.builtin "require"))
+
+; 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))
+(pair
+ key: (property_identifier) @function.method
+ value: (arrow_function))
+
+(assignment_expression
+ left: (member_expression
+ property: (property_identifier) @function.method)
+ right: (arrow_function))
+(assignment_expression
+ 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))
+
+(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_expression
+ function: (member_expression
+ property: (property_identifier) @function.method))
+
+; Variables
+;----------
+
+(formal_parameters (identifier) @variable.parameter)
+
+(identifier) @variable
+
+; Properties
+;-----------
+
+(property_identifier) @property
+
+; Literals
+;---------
+
+(this) @variable.builtin
+(super) @variable.builtin
+
+(true) @constant.builtin
+(false) @constant.builtin
+(null) @constant.builtin
+(comment) @comment
+(string) @string
+(regex) @string.special
+(template_string) @string
+(number) @number
+
+; Punctuation
+;------------
+
+(template_substitution
+ "${" @punctuation.special
+ "}" @punctuation.special) @embedded
+
+";" @punctuation.delimiter
+"." @punctuation.delimiter
+"," @punctuation.delimiter
+
+"--" @operator
+"-" @operator
+"-=" @operator
+"&&" @operator
+"+" @operator
+"++" @operator
+"+=" @operator
+"<" @operator
+"<<" @operator
+"=" @operator
+"==" @operator
+"===" @operator
+"=>" @operator
+">" @operator
+">>" @operator
+"||" @operator
+"??" @operator
+
+"(" @punctuation.bracket
+")" @punctuation.bracket
+"[" @punctuation.bracket
+"]" @punctuation.bracket
+"{" @punctuation.bracket
+"}" @punctuation.bracket
+
+; Keywords
+;----------
+
+[
+"if"
+"else"
+"switch"
+"case"
+"default"
+] @conditional
+
+[
+"import"
+"from"
+"as"
+] @include
+
+[
+"for"
+"of"
+"do"
+"while"
+"continue"
+] @repeat
+
+[
+"async"
+"await"
+"break"
+"catch"
+"class"
+"const"
+"debugger"
+"delete"
+"export"
+"extends"
+"finally"
+"function"
+"get"
+"in"
+"instanceof"
+"let"
+"new"
+"return"
+"set"
+"static"
+"switch"
+"target"
+"throw"
+"try"
+"typeof"
+"var"
+"void"
+"with"
+"yield"
+"abstract"
+"declare"
+"enum"
+"export"
+"implements"
+"interface"
+"keyof"
+"namespace"
+"private"
+"protected"
+"public"
+"type"
+] @keyword
+
+(readonly) @keyword
+(type_identifier) @type
+(predefined_type) @type.builtin
+
+(type_arguments
+ "<" @punctuation.bracket
+ ">" @punctuation.bracket)
+
+; Variables
+
+(required_parameter (identifier) @variable.parameter)
+(optional_parameter (identifier) @variable.parameter)
diff --git a/queries/typescript/locals.scm b/queries/typescript/locals.scm
new file mode 100644
index 000000000..d308e9873
--- /dev/null
+++ b/queries/typescript/locals.scm
@@ -0,0 +1,37 @@
+; Scopes
+;-------
+
+(statement_block) @scope
+(function) @scope
+(arrow_function) @scope
+(function_declaration) @scope
+(method_definition) @scope
+
+; Definitions
+;------------
+
+(formal_parameters
+ (identifier) @definition)
+
+(formal_parameters
+ (object_pattern
+ (identifier) @definition))
+
+(formal_parameters
+ (object_pattern
+ (shorthand_property_identifier) @definition))
+
+(formal_parameters
+ (array_pattern
+ (identifier) @definition))
+
+(variable_declarator
+ name: (identifier) @definition)
+
+; References
+;------------
+
+(identifier) @reference
+
+(required_parameter (identifier) @definition)
+(optional_parameter (identifier) @definition)