Skip to content

Commit

Permalink
Improve JavaScript syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
chbk committed Feb 21, 2025
1 parent dff47a8 commit 110bede
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 24 deletions.
25 changes: 15 additions & 10 deletions crates/languages/src/javascript/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
(identifier)
(shorthand_property_identifier)
(shorthand_property_identifier_pattern)
] @constant
(#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
] @constant.variable
(#match? @constant.variable "^_*[A-Z_][A-Z\\d_]*$"))

; Literals

Expand All @@ -82,6 +82,7 @@
(escape_sequence) @string.escape

(regex) @string.regex
(regex_flags) @keyword.regex
(number) @number

; Tokens
Expand Down Expand Up @@ -210,6 +211,8 @@
"<" @punctuation.bracket
">" @punctuation.bracket)

(decorator "@" @punctuation.special)

; Keywords

[ "abstract"
Expand All @@ -229,11 +232,13 @@
] @keyword

; JSX elements
(jsx_opening_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
(jsx_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
(jsx_self_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))

(jsx_attribute (property_identifier) @attribute)
(jsx_opening_element (["<" ">"]) @punctuation.bracket)
(jsx_closing_element (["</" ">"]) @punctuation.bracket)
(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket)
(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))

(jsx_attribute (property_identifier) @attribute.jsx)
(jsx_opening_element (["<" ">"]) @punctuation.jsx.bracket)
(jsx_closing_element (["</" ">"]) @punctuation.jsx.bracket)
(jsx_self_closing_element (["<" "/>"]) @punctuation.jsx.bracket)
(jsx_attribute "=" @punctuation.jsx.delimiter)
(jsx_text) @text.jsx
4 changes: 2 additions & 2 deletions crates/languages/src/jsdoc/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
(tag_name) @keyword
(type) @type
(tag_name) @comment.doc.keyword
(type) @comment.doc.type
25 changes: 15 additions & 10 deletions crates/languages/src/tsx/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
(identifier)
(shorthand_property_identifier)
(shorthand_property_identifier_pattern)
] @constant
(#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
] @constant.variable
(#match? @constant.variable "^_*[A-Z_][A-Z\\d_]*$"))

; Literals

Expand Down Expand Up @@ -86,6 +86,7 @@
(escape_sequence) @string.escape

(regex) @string.regex
(regex_flags) @keyword.regex
(number) @number

; Tokens
Expand Down Expand Up @@ -221,6 +222,8 @@
"<" @punctuation.bracket
">" @punctuation.bracket)

(decorator "@" @punctuation.special)

; Keywords

[ "abstract"
Expand All @@ -240,11 +243,13 @@
] @keyword

; JSX elements
(jsx_opening_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
(jsx_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))
(jsx_self_closing_element (identifier) @tag (#match? @tag "^[a-z][^.]*$"))

(jsx_attribute (property_identifier) @attribute)
(jsx_opening_element (["<" ">"]) @punctuation.bracket)
(jsx_closing_element (["</" ">"]) @punctuation.bracket)
(jsx_self_closing_element (["<" "/>"]) @punctuation.bracket)
(jsx_opening_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
(jsx_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))
(jsx_self_closing_element (identifier) @tag.jsx (#match? @tag.jsx "^[a-z][^.]*$"))

(jsx_attribute (property_identifier) @attribute.jsx)
(jsx_opening_element (["<" ">"]) @punctuation.jsx.bracket)
(jsx_closing_element (["</" ">"]) @punctuation.jsx.bracket)
(jsx_self_closing_element (["<" "/>"]) @punctuation.jsx.bracket)
(jsx_attribute "=" @punctuation.jsx.delimiter)
(jsx_text) @text.jsx
7 changes: 5 additions & 2 deletions crates/languages/src/typescript/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
(identifier)
(shorthand_property_identifier)
(shorthand_property_identifier_pattern)
] @constant
(#match? @constant "^_*[A-Z_][A-Z\\d_]*$"))
] @constant.variable
(#match? @constant.variable "^_*[A-Z_][A-Z\\d_]*$"))

; Properties

Expand Down Expand Up @@ -110,6 +110,7 @@
(escape_sequence) @string.escape

(regex) @string.regex
(regex_flags) @keyword.regex
(number) @number

; Tokens
Expand Down Expand Up @@ -199,6 +200,8 @@
"<" @punctuation.bracket
">" @punctuation.bracket)

(decorator "@" @punctuation.special)

; Keywords

[
Expand Down

0 comments on commit 110bede

Please sign in to comment.