Skip to content

Commit c0d4b0c

Browse files
authored
fix(parse/html): don't lex "use" as USE_KW when in html text content (#9151)
<!-- IMPORTANT!! If you generated this PR with the help of any AI assistance, please disclose it in the PR. https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#ai-assistance-notice --> <!-- Thanks for submitting a Pull Request! We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your PR. Once created, your PR will be automatically labeled according to changed files. Learn more about contributing: https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md --> ## Summary <!-- Explain the **motivation** for making this change. What existing problem does the pull request solve?--> Previously, the HTML lexer emitted keyword tokens (e.g. `USE_KW`, `STYLE_KW`) when those words appear as plain text content between HTML tags. The parser has a guard (`is_at_svelte_keyword`) that re-lexes keyword tokens as `HtmlText` when they appear in a text-content position, but `T![use]` and `T![style]` were missing from that guard. planned by sonnet 4.6 and tests generated by kimi k2.5 <!-- Link any relevant issues if necessary or include a transcript of any Discord discussion. --> <!-- If you create a user-facing change, please write a changeset: https://github.com/biomejs/biome/blob/main/CONTRIBUTING.md#writing-a-changeset (your changeset is often a good starting point for this summary as well) --> ## Test Plan <!-- What demonstrates that your implementation is correct? --> added snapshot tests ## Docs <!-- If you're submitting a new rule or action (or an option for them), the documentation is part of the code. Make sure rules and actions have example usages, and that all options are documented. --> <!-- For other features, please submit a documentation PR to the `next` branch of our website: https://github.com/biomejs/website/. Link the PR here once it's ready. -->
1 parent 4317572 commit c0d4b0c

6 files changed

Lines changed: 825 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Fixed parsing of Svelte directive keywords (`use`, `style`) when used as plain text content in HTML/Svelte files. Previously, `<p>use JavaScript</p>` or `<p>style it</p>` would incorrectly produce a bogus element instead of proper text content.

crates/biome_html_parser/src/syntax/svelte.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,13 +1241,8 @@ const SVELTE_KEYWORDS: TokenSet<HtmlSyntaxKind> = token_set!(
12411241
T![catch],
12421242
T![then],
12431243
T![snippet],
1244-
T![class],
1245-
T![in],
1246-
T![out],
1247-
T![transition],
1248-
T![animate],
1249-
T![bind]
1250-
);
1244+
)
1245+
.union(SVELTE_DIRECTIVE_KEYWORDS);
12511246

12521247
const SVELTE_DIRECTIVE_KEYWORDS: TokenSet<HtmlSyntaxKind> = token_set!(
12531248
T![bind],
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<span>use </span>
2+
<span>style </span>
3+
<span>bind </span>
4+
<span>transition </span>
5+
<span>in </span>
6+
<span>out </span>
7+
<span>class </span>
8+
<span>animate </span>
9+
<p>
10+
use JavaScript on the
11+
</p>

0 commit comments

Comments
 (0)