Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ignore text and expressions outside the template when validating HTML #14468

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brave-keys-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'svelte': patch
---

fix: ignore text and expressions outside the template when validating HTML
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import { mark_subtree_dynamic } from './shared/fragment.js';
* @param {Context} context
*/
export function ExpressionTag(node, context) {
const in_attribute = context.path.at(-1)?.type === 'Attribute';
const in_template = context.path.at(-1)?.type === 'Fragment';

if (!in_attribute && context.state.parent_element) {
if (in_template && context.state.parent_element) {
if (!is_tag_valid_with_parent('#text', context.state.parent_element)) {
e.node_invalid_placement(node, '`{expression}`', context.state.parent_element);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import * as e from '../../../errors.js';
* @param {Context} context
*/
export function Text(node, context) {
const in_attribute = context.path.at(-1)?.type === 'Attribute';
const in_template = context.path.at(-1)?.type === 'Fragment';

if (!in_attribute && context.state.parent_element && regex_not_whitespace.test(node.data)) {
if (in_template && context.state.parent_element && regex_not_whitespace.test(node.data)) {
if (!is_tag_valid_with_parent('#text', context.state.parent_element)) {
e.node_invalid_placement(node, 'Text node', context.state.parent_element);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"code": "node_invalid_placement",
"message": "Text node is invalid inside `<tbody>`",
"start": {
"line": 3,
"column": 8
},
"end": {
"line": 3,
"column": 13
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<table attr={value} style:x={y} class="I'm not {counted} as text in the table">
<tbody>I am {bad}</tbody>
</table>