diff options
author | Gammut | 2023-07-09 16:35:32 +0000 |
---|---|---|
committer | GitHub | 2023-07-09 16:35:32 +0000 |
commit | 607b426e269b17f4ad32dca9c612c4a9f8541766 (patch) | |
tree | f9e57fa45041c066bf2ea4ecca692986f66291c1 /runtime/queries/_typescript/highlights.scm | |
parent | 28452e1f2a63fe4806078da0f854d01506fc0c0c (diff) |
Refactor queries for ecma based languages (#7207)
Diffstat (limited to 'runtime/queries/_typescript/highlights.scm')
-rw-r--r-- | runtime/queries/_typescript/highlights.scm | 139 |
1 files changed, 139 insertions, 0 deletions
diff --git a/runtime/queries/_typescript/highlights.scm b/runtime/queries/_typescript/highlights.scm new file mode 100644 index 00000000..02f3aab7 --- /dev/null +++ b/runtime/queries/_typescript/highlights.scm @@ -0,0 +1,139 @@ +; Namespaces +; ---------- + +(internal_module + [((identifier) @namespace) ((nested_identifier (identifier) @namespace))]) + +(ambient_declaration "global" @namespace) + +; 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: t) +; (p: t = 1) +(required_parameter + (identifier) @variable.parameter) + +; (...p: t) +(required_parameter + (rest_pattern + (identifier) @variable.parameter)) + +; ({ p }: { p: t }) +(required_parameter + (object_pattern + (shorthand_property_identifier_pattern) @variable.parameter)) + +; ({ a: p }: { a: t }) +(required_parameter + (object_pattern + (pair_pattern + value: (identifier) @variable.parameter))) + +; ([ p ]: t[]) +(required_parameter + (array_pattern + (identifier) @variable.parameter)) + +; (p?: t) +; (p?: t = 1) // Invalid but still posible to hihglight. +(optional_parameter + (identifier) @variable.parameter) + +; (...p?: t) // Invalid but still posible to hihglight. +(optional_parameter + (rest_pattern + (identifier) @variable.parameter)) + +; ({ p }: { p?: t}) +(optional_parameter + (object_pattern + (shorthand_property_identifier_pattern) @variable.parameter)) + +; ({ a: p }: { a?: t }) +(optional_parameter + (object_pattern + (pair_pattern + value: (identifier) @variable.parameter))) + +; ([ p ]?: t[]) // Invalid but still posible to hihglight. +(optional_parameter + (array_pattern + (identifier) @variable.parameter)) + +; Punctuation +; ----------- + +[ + ":" +] @punctuation.delimiter + +(optional_parameter "?" @punctuation.special) +(property_signature "?" @punctuation.special) + +(conditional_type ["?" ":"] @operator) + +; Keywords +; -------- + +[ + "abstract" + "declare" + "export" + "infer" + "implements" + "keyof" + "namespace" + "override" +] @keyword + +[ + "type" + "interface" + "enum" +] @keyword.storage.type + +[ + "public" + "private" + "protected" + "readonly" +] @keyword.storage.modifier + +; Types +; ----- + +(type_identifier) @type +(predefined_type) @type.builtin + +; Type arguments and parameters +; ----------------------------- + +(type_arguments + [ + "<" + ">" + ] @punctuation.bracket) + +(type_parameters + [ + "<" + ">" + ] @punctuation.bracket) + +; Literals +; -------- + +[ + (template_literal_type) +] @string + +; Tokens +; ------ + +(template_type + "${" @punctuation.special + "}" @punctuation.special) @embedded |