Skip to content

[WIP] fix(html): register {@html} expression as a template reference in Svelte#10535

Open
Mokto wants to merge 2 commits into
biomejs:mainfrom
Mokto:fix/svelte-at-html-reference
Open

[WIP] fix(html): register {@html} expression as a template reference in Svelte#10535
Mokto wants to merge 2 commits into
biomejs:mainfrom
Mokto:fix/svelte-at-html-reference

Conversation

@Mokto

@Mokto Mokto commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Summary

{@html expr} is a Svelte template tag that renders raw HTML. The expression inside it references script variables, but parse_embedded_nodes.rs had an empty arm for SvelteHtmlBlock:

AnySvelteBlock::SvelteHtmlBlock(_) => {}

This meant the identifier inside {@html html} was never registered as a template reference, causing noUnusedVariables to falsely flag the variable as unused:

<script lang="ts">
  const { html }: Props = $props();
</script>

{@html html}  <!-- html was flagged as unused ✗ -->

Fix: parse the expression inside SvelteHtmlBlock using build_svelte_text_expression_candidate and push it as an embedded snippet, the same way SvelteIfBlock, SvelteKeyBlock, and SvelteRenderBlock handle their expressions.

This PR was written primarily by Claude Code.

Test Plan

New fixture valid-svelte-at-html.svelte added to noUnusedVariables test specs. All existing tests pass.

Docs

N/A

@changeset-bot

changeset-bot Bot commented Jun 2, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e89610b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

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

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

✅ Organic activity

No automation signals detected in the analyzed events.

View full analysis →

This is an automated analysis by AgentScan

@github-actions github-actions Bot added A-Project Area: project A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Jun 2, 2026
@Mokto Mokto changed the title fix(html): register {@html} expression as a template reference in Svelte [WIP - waiting for 10000] fix(html): register {@html} expression as a template reference in Svelte Jun 2, 2026
@Mokto Mokto changed the title [WIP - waiting for 10000] fix(html): register {@html} expression as a template reference in Svelte [WIP - waiting for 10473] fix(html): register {@html} expression as a template reference in Svelte Jun 2, 2026
…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>
@Mokto Mokto force-pushed the fix/svelte-at-html-reference branch from df0ee3c to f49103e Compare June 11, 2026 03:43
@Mokto Mokto changed the title [WIP - waiting for 10473] fix(html): register {@html} expression as a template reference in Svelte fix(html): register {@html} expression as a template reference in Svelte Jun 11, 2026
@Mokto Mokto marked this pull request as ready for review June 11, 2026 03:44
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The PR fixes a false positive in the noUnusedVariables rule for Svelte by extracting expressions from {@html ...} blocks as embedded JavaScript (TextExpression) and parsing them for analysis. It also prevents Svelte <pre> elements from being treated as generic embedded-language tags so Svelte text/interpolation nodes are produced. A new Svelte fixture and a patch changeset are included.

Possibly related PRs

  • biomejs/biome#9877: Expands Svelte embed and block-kind tracking to resolve noUnusedVariables detection across various Svelte template constructs.

Suggested labels

A-Parser, L-HTML

Suggested reviewers

  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description is well-related to the changeset, explaining the root cause, the fix approach, test coverage, and attribution—all pertinent to the changes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title accurately describes the main fix: registering {@html} expressions as template references in Svelte to resolve false positives in the noUnusedVariables rule.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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>
@github-actions github-actions Bot added A-Parser Area: parser L-HTML Language: HTML and super languages labels Jun 11, 2026
@codspeed-hq

codspeed-hq Bot commented Jun 11, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 67 untouched benchmarks
⏩ 189 skipped benchmarks1


Comparing Mokto:fix/svelte-at-html-reference (e89610b) with main (263c7cc)

Open in CodSpeed

Footnotes

  1. 189 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@Mokto Mokto changed the title fix(html): register {@html} expression as a template reference in Svelte [WIP] fix(html): register {@html} expression as a template reference in Svelte Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter A-Parser Area: parser A-Project Area: project L-HTML Language: HTML and super languages L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant