Skip to content

Commit a60a5c9

Browse files
committed
fix
1 parent 67e8974 commit a60a5c9

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

packages/svelte/src/html-tree-validation.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,12 @@ export function is_tag_valid_with_ancestor(child_tag, ancestors, child_loc, ance
163163
}
164164

165165
if ('descendant' in disallowed && disallowed.descendant.includes(child_tag)) {
166-
const child = child_loc ? `<${child_tag}> (${child_loc})` : `<${child_tag}>`;
167-
const ancestor = ancestor_loc ? `<${ancestor_tag}> (${ancestor_loc})` : `<${ancestor_tag}>`;
166+
const child = child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``;
167+
const ancestor = ancestor_loc
168+
? `\`<${ancestor_tag}>\` (${ancestor_loc})`
169+
: `\`<${ancestor_tag}>\``;
168170

169-
return `\`${child}\` cannot be a descendant of \`${ancestor}\``;
171+
return `${child} cannot be a descendant of ${ancestor}`;
170172
}
171173

172174
return null;
@@ -186,23 +188,23 @@ export function is_tag_valid_with_parent(child_tag, parent_tag, child_loc, paren
186188

187189
const disallowed = disallowed_children[parent_tag];
188190

189-
const child = child_loc ? `<${child_tag}> (${child_loc})` : `<${child_tag}>`;
190-
const parent = parent_loc ? `<${parent_tag}> (${parent_loc})` : `<${parent_tag}>`;
191+
const child = child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``;
192+
const parent = parent_loc ? `\`<${parent_tag}>\` (${parent_loc})` : `\`<${parent_tag}>\``;
191193

192194
if (disallowed) {
193195
if ('direct' in disallowed && disallowed.direct.includes(child_tag)) {
194-
return `\`${child}\` cannot be a direct child of \`${parent}\``;
196+
return `${child} cannot be a direct child of ${parent}`;
195197
}
196198

197199
if ('descendant' in disallowed && disallowed.descendant.includes(child_tag)) {
198-
return `\`${child}\` cannot be a child of \`${parent}\``;
200+
return `${child} cannot be a child of ${parent}`;
199201
}
200202

201203
if ('only' in disallowed && disallowed.only) {
202204
if (disallowed.only.includes(child_tag)) {
203205
return null;
204206
} else {
205-
return `\`${child}\` cannot be a child of \`${parent}\`. \`<${parent_tag}>\` only allows these children: ${disallowed.only.map((d) => `\`<${d}>\``).join(', ')}`;
207+
return `${child} cannot be a child of ${parent}. \`<${parent_tag}>\` only allows these children: ${disallowed.only.map((d) => `\`<${d}>\``).join(', ')}`;
206208
}
207209
}
208210
}
@@ -220,16 +222,16 @@ export function is_tag_valid_with_parent(child_tag, parent_tag, child_loc, paren
220222
case 'frame':
221223
case 'head':
222224
case 'html':
223-
return `\`${child}\` cannot be a child of \`${parent}\``;
225+
return `${child} cannot be a child of ${parent}`;
224226
case 'thead':
225227
case 'tbody':
226228
case 'tfoot':
227-
return `\`${child}\` must be the child of a \`<table>\`, not a \`${parent}\``;
229+
return `${child} must be the child of a \`<table>\`, not a ${parent}`;
228230
case 'td':
229231
case 'th':
230-
return `\`${child}\` must be the child of a \`<tr>\`, not a \`${parent}\``;
232+
return `${child} must be the child of a \`<tr>\`, not a ${parent}`;
231233
case 'tr':
232-
return `\`<tr>\` must be the child of a \`<thead>\`, \`<tbody>\`, or \`<tfoot>\`, not a \`${parent}\``;
234+
return `\`<tr>\` must be the child of a \`<thead>\`, \`<tbody>\`, or \`<tfoot>\`, not a ${parent}`;
233235
}
234236

235237
return null;

packages/svelte/tests/runtime-runes/samples/invalid-html-ssr-ancestor/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default test({
1212
mode: ['hydrate'],
1313

1414
errors: [
15-
'node_invalid_placement_ssr: `<form> (form.svelte:1:0)` cannot be a descendant of `<form> (main.svelte:5:0)`\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.'
15+
'node_invalid_placement_ssr: `<form>` (form.svelte:1:0) cannot be a descendant of `<form>` (main.svelte:5:0)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.'
1616
],
1717

1818
warnings: [

packages/svelte/tests/runtime-runes/samples/invalid-html-ssr/_config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ export default test({
1212
mode: ['hydrate'],
1313

1414
errors: [
15-
'node_invalid_placement_ssr: `<h1> (h1.svelte:1:0)` cannot be a child of `<p> (main.svelte:6:0)`\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.',
16-
'node_invalid_placement_ssr: `<form> (form.svelte:1:0)` cannot be a child of `<form> (main.svelte:9:0)`\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.'
15+
'node_invalid_placement_ssr: `<h1>` (h1.svelte:1:0) cannot be a child of `<p>` (main.svelte:6:0)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.',
16+
'node_invalid_placement_ssr: `<form>` (form.svelte:1:0) cannot be a child of `<form>` (main.svelte:9:0)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.'
1717
],
1818

1919
warnings: [

packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export default test({
66
},
77

88
errors: [
9-
'node_invalid_placement_ssr: `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:1:0) cannot contain `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:2:1) (`<p>` cannot be a child of `<p>`)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.'
9+
'node_invalid_placement_ssr: `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:2:1) cannot be a child of `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:1:0)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.'
1010
]
1111
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<script>console.error("node_invalid_placement_ssr: `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:1:0) cannot contain `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:2:1) (`<p>` cannot be a child of `<p>`)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.")</script>
1+
<script>console.error("node_invalid_placement_ssr: `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:2:1) cannot be a child of `<p>` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:1:0)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.")</script>

0 commit comments

Comments
 (0)