From ac8ae3b1c7b5644f8317cdc88d604cdb558b6296 Mon Sep 17 00:00:00 2001 From: Steven Sojka Date: Fri, 12 Jun 2020 07:41:20 -0500 Subject: [PATCH 1/2] feat(queries): add typescript and javascript queries --- README.md | 4 +- queries/javascript/highlights.scm | 190 ++++++++++++++++++++++++++ queries/javascript/locals.scm | 35 +++++ queries/typescript/highlights.scm | 215 ++++++++++++++++++++++++++++++ queries/typescript/locals.scm | 37 +++++ 5 files changed, 479 insertions(+), 2 deletions(-) create mode 100644 queries/javascript/highlights.scm create mode 100644 queries/javascript/locals.scm create mode 100644 queries/typescript/highlights.scm create mode 100644 queries/typescript/locals.scm 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) From a600be80b68803c949d43e384c847315f5ab4155 Mon Sep 17 00:00:00 2001 From: Steven Sojka Date: Mon, 15 Jun 2020 08:53:49 -0500 Subject: [PATCH 2/2] chore(queries): use inherited queries for ts/js --- queries/typescript/highlights.scm | 188 ------------------------------ queries/typescript/locals.scm | 35 ------ 2 files changed, 223 deletions(-) diff --git a/queries/typescript/highlights.scm b/queries/typescript/highlights.scm index 92820105b..dd0dd778f 100644 --- a/queries/typescript/highlights.scm +++ b/queries/typescript/highlights.scm @@ -1,192 +1,4 @@ -; 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" diff --git a/queries/typescript/locals.scm b/queries/typescript/locals.scm index d308e9873..cb064b823 100644 --- a/queries/typescript/locals.scm +++ b/queries/typescript/locals.scm @@ -1,37 +1,2 @@ -; 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)