Repository navigation
fix(parse/html): read top-level Svelte script and style attributes as strings - #12189
MustafaKemal0146 wants to merge 1 commit into
Conversation
… strings Co-Authored-By: Claude Opus 5.5 <[email protected]>
🦋 Changeset detectedLatest commit: 646e0c6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 15 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 |
|
A maintainer will take a look as soon as they can. In the meantime, please make sure that:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
⛔ Files ignored due to path filters (2)
📒 Files selected for processing (5)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. WalkthroughThe HTML parser now tracks whether an element is at the document root. For direct-root Svelte Suggested reviewers: Priority: ⬇️ Low Change: Bug fix · Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to The change addresses the reported top-level Svelte generic parse error while preserving nested template parsing. No concrete merge-blocking issue remains in the supplied evidence. Security Architecture ReviewSecurity architecture risk: ⚪ Minimal · up to The change corrects attribute interpretation within a narrowly defined Svelte context. The reviewed paths do not introduce new execution authority or weaken a security boundary, and nested elements retain their existing behavior. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Merging this PR will not alter performance
Comparing Footnotes
|
ematipico
left a comment
There was a problem hiding this comment.
Thank you for the PR, but I don't this is the right fix. I added some comments. Why can't we emit the same CST we do for the Vue generics? See playground
| } | ||
|
|
||
| #[test] | ||
| fn full_support_script_generics_with_braces() { |
There was a problem hiding this comment.
The parser test was enough. At most, you could add a formatter test. This wasn't a CLI bug, after all
| // Svelte reads the attributes of a top-level `<script>` or `<style>` as plain | ||
| // strings, so `generics="T extends { id: string }"` holds no `{expression}`. | ||
| // Nested ones, such as a `<script>` inside `<svelte:head>`, keep templates. |
There was a problem hiding this comment.
I don't think the comment is correct. What you want to say is that generics has special parsing only when it's in a top-level <script>. A script tag under a div, for example, triggers a parser error.
Also, we don't care how Svelte parses things; we care more about the parsing business logic (error path, happy path, etc.), because the "how" is our business logic.
| initializer: HtmlAttributeInitializerClause { | ||
| eq_token: [email protected] "=" [] [], | ||
| value: HtmlString { | ||
| value_token: [email protected] "\"T extends { selected?: boolean; name?: string }\"" [] [], |
There was a problem hiding this comment.
This is an incorrect representation of the code, we can't accept that. We're adding quotes even though there aren't.
Summary
Fixes #10896.
In Svelte, quoted attribute values were always parsed as templates, so
generics="T extends { selected?: boolean }"on<script>was read as a{...}expression and failed to parse. Svelte reads attributes of top-level<script>/<style>as static strings (is_top_level_script_or_stylein itselement.js), so Biome now does the same. Nested ones, like a<script>inside<svelte:head>, still get templates.Related: #10952 handles type references inside
generics, this one only fixes the parse error.This PR was written primarily by Claude Code.
Test Plan
ok/svelte/script_generics_with_braces.svelte: top-level<script>/<style>values areHtmlString,<div title="{...}">and the ones in<svelte:head>stay templates.full_support_script_generics_with_braces: fails on main with a parse error, passes with the fix.biome_html_parserandbiome_html_formattertests, the Svelte/Astro/Vue CLI cases, the Svelte analyzer specs,just fandjust l.Docs
No changes needed.