Skip to content

Commit

Permalink
fix: Improve JSX and TSX tag highlighting (#3973)
Browse files Browse the repository at this point in the history
  • Loading branch information
jchand99 authored Sep 26, 2022
1 parent d2bb7f5 commit 90468ad
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions runtime/queries/jsx/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
; inherits: ecma

; Highlight component names differently
(jsx_opening_element ((identifier) @constructor
(#match? @constructor "^[A-Z]")))

; Handle the dot operator effectively - <My.Component>
(jsx_opening_element ((nested_identifier (identifier) @tag (identifier) @constructor)))

; Highlight brackets differently
(jsx_opening_element ["<" ">"] @punctuation.bracket)

(jsx_closing_element ((identifier) @constructor
(#match? @constructor "^[A-Z]")))

; Handle the dot operator effectively - </My.Component>
(jsx_closing_element ((nested_identifier (identifier) @tag (identifier) @constructor)))

; Highlight brackets differently
(jsx_closing_element ["<" "/" ">"] @punctuation.bracket)

(jsx_self_closing_element ((identifier) @constructor
(#match? @constructor "^[A-Z]")))

; Handle the dot operator effectively - <My.Component />
(jsx_self_closing_element ((nested_identifier (identifier) @tag (identifier) @constructor)))

; TODO: also tag @punctuation.delimiter?
; Highlight brackets differently
(jsx_self_closing_element ["<" "/" ">"] @punctuation.bracket)

; Handle attribute delimiter
(jsx_attribute "=" @punctuation.delimiter)

(jsx_opening_element (identifier) @tag)
(jsx_closing_element (identifier) @tag)
(jsx_self_closing_element (identifier) @tag)
(jsx_attribute (property_identifier) @variable.other.member)

; inherits: ecma
2 changes: 1 addition & 1 deletion runtime/queries/tsx/highlights.scm
Original file line number Diff line number Diff line change
@@ -1 +1 @@
; inherits: typescript
; inherits: jsx,typescript

0 comments on commit 90468ad

Please sign in to comment.