From a60a5c97b39414d636c65f0cb245092e9d9cc19c Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 3 Dec 2024 22:48:46 -0500 Subject: [PATCH] fix --- packages/svelte/src/html-tree-validation.js | 26 ++++++++++--------- .../invalid-html-ssr-ancestor/_config.js | 2 +- .../samples/invalid-html-ssr/_config.js | 4 +-- .../invalid-nested-svelte-element/_config.js | 2 +- .../_expected_head.html | 2 +- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/svelte/src/html-tree-validation.js b/packages/svelte/src/html-tree-validation.js index 9561a4e784..98e74b638f 100644 --- a/packages/svelte/src/html-tree-validation.js +++ b/packages/svelte/src/html-tree-validation.js @@ -163,10 +163,12 @@ export function is_tag_valid_with_ancestor(child_tag, ancestors, child_loc, ance } if ('descendant' in disallowed && disallowed.descendant.includes(child_tag)) { - const child = child_loc ? `<${child_tag}> (${child_loc})` : `<${child_tag}>`; - const ancestor = ancestor_loc ? `<${ancestor_tag}> (${ancestor_loc})` : `<${ancestor_tag}>`; + const child = child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``; + const ancestor = ancestor_loc + ? `\`<${ancestor_tag}>\` (${ancestor_loc})` + : `\`<${ancestor_tag}>\``; - return `\`${child}\` cannot be a descendant of \`${ancestor}\``; + return `${child} cannot be a descendant of ${ancestor}`; } return null; @@ -186,23 +188,23 @@ export function is_tag_valid_with_parent(child_tag, parent_tag, child_loc, paren const disallowed = disallowed_children[parent_tag]; - const child = child_loc ? `<${child_tag}> (${child_loc})` : `<${child_tag}>`; - const parent = parent_loc ? `<${parent_tag}> (${parent_loc})` : `<${parent_tag}>`; + const child = child_loc ? `\`<${child_tag}>\` (${child_loc})` : `\`<${child_tag}>\``; + const parent = parent_loc ? `\`<${parent_tag}>\` (${parent_loc})` : `\`<${parent_tag}>\``; if (disallowed) { if ('direct' in disallowed && disallowed.direct.includes(child_tag)) { - return `\`${child}\` cannot be a direct child of \`${parent}\``; + return `${child} cannot be a direct child of ${parent}`; } if ('descendant' in disallowed && disallowed.descendant.includes(child_tag)) { - return `\`${child}\` cannot be a child of \`${parent}\``; + return `${child} cannot be a child of ${parent}`; } if ('only' in disallowed && disallowed.only) { if (disallowed.only.includes(child_tag)) { return null; } else { - return `\`${child}\` cannot be a child of \`${parent}\`. \`<${parent_tag}>\` only allows these children: ${disallowed.only.map((d) => `\`<${d}>\``).join(', ')}`; + return `${child} cannot be a child of ${parent}. \`<${parent_tag}>\` only allows these children: ${disallowed.only.map((d) => `\`<${d}>\``).join(', ')}`; } } } @@ -220,16 +222,16 @@ export function is_tag_valid_with_parent(child_tag, parent_tag, child_loc, paren case 'frame': case 'head': case 'html': - return `\`${child}\` cannot be a child of \`${parent}\``; + return `${child} cannot be a child of ${parent}`; case 'thead': case 'tbody': case 'tfoot': - return `\`${child}\` must be the child of a \`\`, not a \`${parent}\``; + return `${child} must be the child of a \`
\`, not a ${parent}`; case 'td': case 'th': - return `\`${child}\` must be the child of a \`\`, not a \`${parent}\``; + return `${child} must be the child of a \`\`, not a ${parent}`; case 'tr': - return `\`\` must be the child of a \`\`, \`\`, or \`\`, not a \`${parent}\``; + return `\`\` must be the child of a \`\`, \`\`, or \`\`, not a ${parent}`; } return null; diff --git a/packages/svelte/tests/runtime-runes/samples/invalid-html-ssr-ancestor/_config.js b/packages/svelte/tests/runtime-runes/samples/invalid-html-ssr-ancestor/_config.js index 351e4f49ee..4c45b26179 100644 --- a/packages/svelte/tests/runtime-runes/samples/invalid-html-ssr-ancestor/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/invalid-html-ssr-ancestor/_config.js @@ -12,7 +12,7 @@ export default test({ mode: ['hydrate'], errors: [ - 'node_invalid_placement_ssr: ` (form.svelte:1:0)` cannot be a descendant of ` (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.' + 'node_invalid_placement_ssr: `` (form.svelte:1:0) cannot be a descendant of `` (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.' ], warnings: [ diff --git a/packages/svelte/tests/runtime-runes/samples/invalid-html-ssr/_config.js b/packages/svelte/tests/runtime-runes/samples/invalid-html-ssr/_config.js index 62b06ccab0..bc4d709b19 100644 --- a/packages/svelte/tests/runtime-runes/samples/invalid-html-ssr/_config.js +++ b/packages/svelte/tests/runtime-runes/samples/invalid-html-ssr/_config.js @@ -12,8 +12,8 @@ export default test({ mode: ['hydrate'], errors: [ - 'node_invalid_placement_ssr: `

(h1.svelte:1:0)` cannot be a child of `

(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.', - 'node_invalid_placement_ssr: ` (form.svelte:1:0)` cannot be a child of ` (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.' + 'node_invalid_placement_ssr: `

` (h1.svelte:1:0) cannot be a child of `

` (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.', + 'node_invalid_placement_ssr: `` (form.svelte:1:0) cannot be a child of `` (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.' ], warnings: [ diff --git a/packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/_config.js b/packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/_config.js index 172c695a7b..71edff6a68 100644 --- a/packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/_config.js +++ b/packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/_config.js @@ -6,6 +6,6 @@ export default test({ }, errors: [ - 'node_invalid_placement_ssr: `

` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:1:0) cannot contain `

` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:2:1) (`

` cannot be a child of `

`)\n\nThis can cause content to shift around as the browser repairs the HTML, and will likely result in a `hydration_mismatch` warning.' + 'node_invalid_placement_ssr: `

` (packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/main.svelte:2:1) cannot be a child of `

` (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.' ] }); diff --git a/packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/_expected_head.html b/packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/_expected_head.html index bf6e59d578..6d9ea9de5f 100644 --- a/packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/_expected_head.html +++ b/packages/svelte/tests/server-side-rendering/samples/invalid-nested-svelte-element/_expected_head.html @@ -1 +1 @@ - \ No newline at end of file +