Skip to content

Commit

Permalink
build(tree-sitter): update javascript, typescript and tsx (helix-edit…
Browse files Browse the repository at this point in the history
…or#7852)

* build(tree-sitter): update javascript, typescript and tsx

* update revision of tree-sitter parsers for these languages.
* rename `?.` to `optional_chain`, introduced in tree-sitter/tree-sitter-javascript@186f2ad.

* fix(highlight): change jsx queries to match latest tree-sitter

Latest tree-sitter/tree-sitter-javascript@bb1f97b added some breaking changes that broke highlighting.
* Remove some queries with `nested_identifier`.
* Remove deprecated `jsx_fragment` from indent query.
* Count `</` and `/>` as a single token.
  • Loading branch information
woojiq authored and Schuyler Mortimer committed Jul 10, 2024
1 parent f06289f commit 1fa86bb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
6 changes: 3 additions & 3 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ args = { program = "{0}" }

[[grammar]]
name = "javascript"
source = { git = "https://github.com/tree-sitter/tree-sitter-javascript", rev = "4a95461c4761c624f2263725aca79eeaefd36cad" }
source = { git = "https://github.com/tree-sitter/tree-sitter-javascript", rev = "f772967f7b7bc7c28f845be2420a38472b16a8ee" }

[[language]]
name = "jsx"
Expand All @@ -590,7 +590,7 @@ indent = { tab-width = 2, unit = " " }

[[grammar]]
name = "typescript"
source = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259", subpath = "typescript" }
source = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "b1bf4825d9eaa0f3bdeb1e52f099533328acfbdf", subpath = "typescript" }

[[language]]
name = "tsx"
Expand All @@ -604,7 +604,7 @@ indent = { tab-width = 2, unit = " " }

[[grammar]]
name = "tsx"
source = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "5d20856f34315b068c41edaee2ac8a100081d259", subpath = "tsx" }
source = { git = "https://github.com/tree-sitter/tree-sitter-typescript", rev = "b1bf4825d9eaa0f3bdeb1e52f099533328acfbdf", subpath = "tsx" }

[[language]]
name = "css"
Expand Down
18 changes: 3 additions & 15 deletions runtime/queries/_jsx/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
(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)))

(jsx_opening_element (identifier) @tag)

; Closing elements
Expand All @@ -15,9 +12,6 @@
(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)))

(jsx_closing_element (identifier) @tag)

; Self-closing elements
Expand All @@ -26,9 +20,6 @@
(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)))

(jsx_self_closing_element (identifier) @tag)

; Attributes
Expand All @@ -39,17 +30,14 @@
; Punctuation
; -----------

; Handle attribute delimiter
; Handle attribute delimiter (<Component color="red"/>)
(jsx_attribute "=" @punctuation.delimiter)

; <Component>
(jsx_opening_element ["<" ">"] @punctuation.bracket)

; </Component>
(jsx_closing_element ["<" "/" ">"] @punctuation.bracket)
(jsx_closing_element ["</" ">"] @punctuation.bracket)

; <Component />
(jsx_self_closing_element ["<" "/" ">"] @punctuation.bracket)

; <> ... </>
(jsx_fragment ["<" "/" ">"] @punctuation.bracket)
(jsx_self_closing_element ["<" "/>"] @punctuation.braket)
1 change: 0 additions & 1 deletion runtime/queries/_jsx/indents.scm
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[
(jsx_fragment)
(jsx_element)
(jsx_self_closing_element)
] @indent
Expand Down
2 changes: 1 addition & 1 deletion runtime/queries/ecma/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@

[
";"
"?."
(optional_chain) ; ?.
"."
","
] @punctuation.delimiter
Expand Down

0 comments on commit 1fa86bb

Please sign in to comment.