[WIP] fix(html): register {@html} expression as a template reference in Svelte#10535
[WIP] fix(html): register {@html} expression as a template reference in Svelte#10535Mokto wants to merge 2 commits into
Conversation
🦋 Changeset detectedLatest commit: e89610b The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Organic activityNo automation signals detected in the analyzed events. This is an automated analysis by AgentScan |
…s unused
The `parse_embedded_nodes` function was silently skipping `SvelteHtmlBlock`
nodes (`{@html expr}`), so the JS expression inside them was never added to
the embedded snippet list. As a result, any variable referenced only via
`{@html variable}` was incorrectly reported as unused by `noUnusedVariables`.
Now `SvelteHtmlBlock` is handled the same way as other expression-bearing
blocks (`SvelteIfBlock`, `SvelteKeyBlock`, etc.): the expression is parsed as
a JS snippet and visited so its identifier references are tracked.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
df0ee3c to
f49103e
Compare
WalkthroughThe PR fixes a false positive in the Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
In Svelte files, <pre> was being parsed the same way as <script>/<style>:
its entire content was consumed as a single raw HTML_LITERAL token inside
HtmlEmbeddedContent. That prevented the expression-tracking passes in
parse_embedded_nodes from seeing any Svelte blocks inside <pre>, so
variables referenced only via <pre>{@html expr}</pre> or <pre>{expr}</pre>
were still incorrectly reported as unused by noUnusedVariables.
The formatter already has an independent HTML_VERBATIM_TAGS list that
includes "pre", which causes it to emit <pre> content verbatim regardless
of how the parser represents the children. Skipping the embedded-language
path in the parser for Svelte is therefore safe: formatting is unchanged,
and {@html} / interpolation nodes inside <pre> are now visible as proper
AST descendants.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Merging this PR will not alter performance
Comparing Footnotes
|
Summary
{@html expr}is a Svelte template tag that renders raw HTML. The expression inside it references script variables, butparse_embedded_nodes.rshad an empty arm forSvelteHtmlBlock:This meant the identifier inside
{@html html}was never registered as a template reference, causingnoUnusedVariablesto falsely flag the variable as unused:Fix: parse the expression inside
SvelteHtmlBlockusingbuild_svelte_text_expression_candidateand push it as an embedded snippet, the same waySvelteIfBlock,SvelteKeyBlock, andSvelteRenderBlockhandle their expressions.Test Plan
New fixture
valid-svelte-at-html.svelteadded tonoUnusedVariablestest specs. All existing tests pass.Docs
N/A