feat(svelte)!: switch parser repo and update queries

Breaking change: switch to themixednuts/tree-sitter-htmlx.

Update Svelte queries for the new node names.
This commit is contained in:
themixednuts 2026-03-24 15:55:05 -05:00
parent 6620ae1c44
commit a1bee9959b
7 changed files with 228 additions and 94 deletions

View file

@ -280,7 +280,7 @@ jsx (queries only)[^jsx] | unstable | `HFIJ ` | @steelsojka
[supercollider](https://github.com/madskjeldgaard/tree-sitter-supercollider) | unstable | `HFIJL` | @madskjeldgaard, @elgiano
[superhtml](https://github.com/kristoff-it/superhtml) | unstable | `H  J ` | @rockorager
[surface](https://github.com/connorlay/tree-sitter-surface) | unstable | `HFIJ ` | @connorlay
[svelte](https://github.com/tree-sitter-grammars/tree-sitter-svelte) | unstable | `HFIJL` | @amaanq
[svelte](https://github.com/themixednuts/tree-sitter-htmlx) | unstable | `HFIJL` | @amaanq
[sway](https://github.com/FuelLabs/tree-sitter-sway.git) | unstable | `HFIJL` | @ribru17
[swift](https://github.com/alex-pinkus/tree-sitter-swift) | unstable | `HFIJL` | @alex-pinkus
[sxhkdrc](https://github.com/RaafatTurki/tree-sitter-sxhkdrc) | unstable | `HF J ` | @RaafatTurki

View file

@ -2208,8 +2208,9 @@ return {
},
svelte = {
install_info = {
revision = 'ae5199db47757f785e43a14b332118a5474de1a2',
url = 'https://github.com/tree-sitter-grammars/tree-sitter-svelte',
location = 'crates/tree-sitter-svelte',
revision = '3be6db3dc94478b089a64e59e4d855fc3041a7be',
url = 'https://github.com/themixednuts/tree-sitter-htmlx',
},
maintainers = { '@amaanq' },
requires = { 'html_tags' },

View file

@ -1,13 +1,12 @@
; inherits: html
[
(if_statement)
(else_if_block)
(else_block)
(each_statement)
(await_statement)
(then_block)
(catch_block)
(key_statement)
(snippet_statement)
(if_block)
(else_if_clause)
(else_clause)
(each_block)
(await_block)
(await_branch)
(key_block)
(snippet_block)
] @fold

View file

@ -2,42 +2,83 @@
(raw_text) @none
[
"as"
"key"
"html"
"snippet"
"render"
] @keyword
((tag_name) @type
(#match? @type "^[A-Z]"))
"const" @keyword.modifier
(tag_name
namespace: (tag_namespace) @keyword
":" @punctuation.delimiter
name: (tag_local_name) @tag)
[
"if"
"else if"
"else"
"then"
] @keyword.conditional
(tag_name
object: (tag_member) @type
"." @punctuation.delimiter
property: (tag_member) @tag)
"each" @keyword.repeat
(attribute_directive) @keyword
(attribute_name ":" @punctuation.delimiter)
(attribute_identifier) @property
(attribute_modifier) @attribute
(attribute_modifiers "|" @punctuation.delimiter)
[
"await"
"then"
] @keyword.coroutine
(expression) @embedded
(expression_value) @embedded
"catch" @keyword.exception
"debug" @keyword.debug
(shorthand_attribute content: (_) @variable)
[
"{"
"}"
] @punctuation.bracket
"|" @punctuation.delimiter
(tag_comment kind: (line_comment) @comment)
(tag_comment kind: (block_comment) @comment)
[
"#"
":"
"/"
"@"
] @tag.delimiter
"if"
"each"
"await"
"key"
"snippet"
"else"
"html"
"debug"
"const"
"render"
"attach"
"as"
] @keyword.control
(block_keyword) @keyword.control
(block_open) @tag.delimiter
(block_close) @tag.delimiter
(shorthand_kind) @keyword.control
(branch_kind) @keyword.control
(block_sigil) @keyword.control
(if_block expression: (expression) @embedded)
(else_if_clause expression: (expression_value) @embedded)
(each_block expression: (expression) @embedded)
(each_block binding: (pattern) @variable)
(each_block index: (pattern) @variable)
(each_block key: (expression) @embedded)
(await_block expression: (expression) @embedded)
(await_branch (pattern) @variable)
(await_block (pattern) @variable)
(orphan_branch (pattern) @variable)
(key_block expression: (expression) @embedded)
(snippet_block name: (snippet_name) @function)
(snippet_parameters parameter: (pattern) @variable)
(snippet_type_parameters) @type
[
"("
")"
","
] @punctuation.delimiter

View file

@ -1,34 +1,19 @@
; inherits: html
[
(if_statement)
(each_statement)
(await_statement)
(key_statement)
(snippet_statement)
(if_block)
(each_block)
(await_block)
(key_block)
(snippet_block)
] @indent.begin
(if_end
"}" @indent.end)
(each_end
"}" @indent.end)
(await_end
"}" @indent.end)
(key_end
"}" @indent.end)
(snippet_end
"}" @indent.end)
(block_end
(block_close) @indent.end)
[
(if_end)
(else_if_block)
(else_block)
(each_end)
(await_end)
(key_end)
(snippet_end)
(block_end)
(else_if_clause)
(else_clause)
(await_branch)
] @indent.branch

View file

@ -1,47 +1,141 @@
; inherits: html_tags
((comment) @injection.content
(#set! injection.language "comment"))
((style_element
((element
(start_tag
(tag_name) @_tag
(attribute
(attribute_name) @_attr
(attribute_name) @_lang
(quoted_attribute_value
(attribute_value) @_lang)))
(attribute_value) @_value)))
(raw_text) @injection.content)
(#eq? @_attr "lang")
(#any-of? @_lang "scss" "postcss" "less")
(#set! injection.language "scss"))
((svelte_raw_text) @injection.content
(#set! injection.language "javascript"))
((script_element
(start_tag
(attribute
(attribute_name) @_attr
(quoted_attribute_value
(attribute_value) @_lang)))
(raw_text) @injection.content)
(#eq? @_attr "lang")
(#any-of? @_lang "ts" "typescript")
(#eq? @_tag "script")
(#eq? @_lang "lang")
(#any-of? @_value "ts" "typescript" "text/typescript")
(#set! injection.language "typescript"))
((script_element
((element
(start_tag
(tag_name) @_tag
(attribute
(attribute_name) @_attr
(attribute_name) @_lang
(quoted_attribute_value
(attribute_value) @_lang)))
(attribute_value) @injection.language)))
(raw_text) @injection.content)
(#eq? @_attr "lang")
(#any-of? @_lang "js" "javascript")
(#eq? @_tag "script")
(#eq? @_lang "lang")
(#not-any-of? @injection.language
"ts"
"typescript"
"text/typescript"
"js"
"javascript"
"text/javascript"))
((element
(start_tag
(tag_name) @_tag
(attribute
(attribute_name) @_lang
(quoted_attribute_value
(attribute_value) @_value)))
(raw_text) @injection.content)
(#eq? @_tag "script")
(#eq? @_lang "lang")
(#any-of? @_value "js" "javascript" "text/javascript")
(#set! injection.language "javascript"))
((element
(start_tag
(tag_name) @_tag
(attribute
(attribute_name) @_attr
(attribute_name) @_script_attr)*)
(raw_text) @injection.content)
(#eq? @_tag "script")
(#not-any-of? @_script_attr "lang")
(#set! injection.language "javascript"))
((element
(start_tag
(tag_name) @_tag
(attribute
(attribute_name) @_lang
(quoted_attribute_value
(attribute_value) @_value)))
(raw_text) @injection.content)
(#eq? @_tag "style")
(#eq? @_lang "lang")
(#any-of? @_value "scss" "sass" "less" "postcss")
(#set! injection.language "scss"))
((element
(start_tag
(tag_name) @_tag
(attribute
(attribute_name) @_lang
(quoted_attribute_value
(attribute_value) @injection.language)))
(text) @injection.content)
(#eq? @_attr "lang")
(#eq? @injection.language "pug"))
(raw_text) @injection.content)
(#eq? @_tag "style")
(#eq? @_lang "lang")
(#not-any-of? @injection.language "scss" "sass" "less" "postcss"))
((element
(start_tag
(tag_name) @_tag
(attribute
(attribute_name) @_style_attr)*)
(raw_text) @injection.content)
(#eq? @_tag "style")
(#not-any-of? @_style_attr "lang")
(#set! injection.language "css"))
((attribute
(attribute_name) @_style_name
(quoted_attribute_value (attribute_value) @injection.content))
(#eq? @_style_name "style")
(#set! injection.language "css"))
(element
(start_tag
(tag_name) @_tag
(#eq? @_tag "input")
(attribute
(attribute_name) @_attr
[
(quoted_attribute_value
(attribute_value) @injection.content)
(attribute_value) @injection.content
]
(#eq? @_attr "pattern")))
(#set! injection.language "regex"))
(attribute
(attribute_name) @_name
(#lua-match? @_name "^on[a-z]+$")
(quoted_attribute_value
(attribute_value) @injection.content)
(#set! injection.language "javascript"))
((expression content: (js) @injection.content)
(#set! injection.language "javascript"))
((expression content: (ts) @injection.content)
(#set! injection.language "typescript"))
((shorthand_attribute content: (js) @injection.content)
(#set! injection.language "javascript"))
((shorthand_attribute content: (ts) @injection.content)
(#set! injection.language "typescript"))
((expression_value content: (js) @injection.content)
(#set! injection.language "javascript"))
((expression_value content: (ts) @injection.content)
(#set! injection.language "typescript"))
((pattern content: (js) @injection.content)
(#set! injection.language "javascript"))
((pattern content: (ts) @injection.content)
(#set! injection.language "typescript"))
((snippet_type_parameters) @injection.content
(#set! injection.language "typescript"))

View file

@ -1 +1,15 @@
; inherits: html
(snippet_block) @local.scope
(snippet_parameters
parameter: (pattern) @local.definition.parameter)
(snippet_name) @local.definition.function
((tag_name) @local.reference
(#lua-match? @local.reference "^[A-Z]"))
(tag_name
object: (tag_member) @local.reference
property: (tag_member) @local.reference)