Improve TypeScript highlights (#18525)

- Move function queries under constant queries to avoid uppercase
functions highlighted as constants
- Merge keywords and remove duplicates
- Highlights type aliases on import
- Highlights literal built-in types (null, undefined, true, false) as
`@type.builtin`

Confused about case-based queries, should they be rewritten?

Release Notes:

- N/A

---------

Co-authored-by: Marshall Bowers <elliott.codes@gmail.com>
This commit is contained in:
狐狸 2025-01-11 06:00:28 +08:00 committed by GitHub
parent 1e0ded4feb
commit 8bd7a048ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,38 @@
(identifier) @variable (identifier) @variable
; Special identifiers
((identifier) @type
(#match? @type "^[A-Z]"))
(type_identifier) @type
(predefined_type) @type.builtin
(import_specifier
"type"
name: (identifier) @type
alias: (identifier) @type
)
(import_statement
"type"
(import_clause
(named_imports
(import_specifier
name: (identifier) @type
alias: (identifier) @type
)
)
)
)
([
(identifier)
(shorthand_property_identifier)
(shorthand_property_identifier_pattern)
] @constant
(#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
; Properties ; Properties
(property_identifier) @property (property_identifier) @property
@ -43,23 +75,6 @@
left: (identifier) @function left: (identifier) @function
right: [(function_expression) (arrow_function)]) right: [(function_expression) (arrow_function)])
; Special identifiers
((identifier) @constructor
(#match? @constructor "^[A-Z]"))
((identifier) @type
(#match? @type "^[A-Z]"))
(type_identifier) @type
(predefined_type) @type.builtin
([
(identifier)
(shorthand_property_identifier)
(shorthand_property_identifier_pattern)
] @constant
(#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
; Literals ; Literals
(this) @variable.special (this) @variable.special
@ -75,6 +90,15 @@
(false) (false)
] @boolean ] @boolean
(literal_type
[
(null)
(undefined)
(true)
(false)
] @type.builtin
)
(comment) @comment (comment) @comment
[ [
@ -90,15 +114,6 @@
; Tokens ; Tokens
[
";"
"?."
"."
","
":"
"?"
] @punctuation.delimiter
[ [
"..." "..."
"-" "-"
@ -147,15 +162,6 @@
"??=" "??="
] @operator ] @operator
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
(ternary_expression (ternary_expression
[ [
"?" "?"
@ -164,51 +170,22 @@
) )
[ [
"as" ";"
"async" "?."
"await" "."
"break" ","
"case" ":"
"catch" "?"
"class" ] @punctuation.delimiter
"const"
"continue" [
"debugger" "("
"default" ")"
"delete" "["
"do" "]"
"else" "{"
"export" "}"
"extends" ] @punctuation.bracket
"finally"
"for"
"from"
"function"
"get"
"if"
"import"
"in"
"instanceof"
"is"
"let"
"new"
"of"
"return"
"satisfies"
"set"
"static"
"switch"
"target"
"throw"
"try"
"typeof"
"using"
"var"
"void"
"while"
"with"
"yield"
] @keyword
(template_substitution (template_substitution
"${" @punctuation.special "${" @punctuation.special
@ -224,19 +201,63 @@
; Keywords ; Keywords
[ "abstract" [
"abstract"
"as"
"async"
"await"
"break"
"case"
"catch"
"class"
"const"
"continue"
"debugger"
"declare" "declare"
"default"
"delete"
"do"
"else"
"enum" "enum"
"export" "export"
"extends"
"finally"
"for"
"from"
"function"
"get"
"if"
"implements" "implements"
"import"
"in"
"infer" "infer"
"instanceof"
"interface" "interface"
"is"
"keyof" "keyof"
"let"
"namespace" "namespace"
"new"
"of"
"override"
"private" "private"
"protected" "protected"
"public" "public"
"type"
"readonly" "readonly"
"override" "return"
"satisfies"
"set"
"static"
"switch"
"target"
"throw"
"try"
"type"
"typeof"
"using"
"var"
"void"
"while"
"with"
"yield"
] @keyword ] @keyword