From 83a5eaac8e3ad2c549c640549d84b6bd3efd01c4 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Fri, 25 Oct 2024 22:04:54 +0100 Subject: [PATCH] fix: skip comment nodes in snippet validation logic (#13936) --- .changeset/shy-penguins-beg.md | 5 +++++ .../compiler/phases/2-analyze/visitors/SnippetBlock.js | 5 ++++- .../samples/snippet-comment-sibling/Child.svelte | 5 +++++ .../samples/snippet-comment-sibling/_config.js | 5 +++++ .../samples/snippet-comment-sibling/main.svelte | 10 ++++++++++ 5 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 .changeset/shy-penguins-beg.md create mode 100644 packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/Child.svelte create mode 100644 packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/_config.js create mode 100644 packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/main.svelte diff --git a/.changeset/shy-penguins-beg.md b/.changeset/shy-penguins-beg.md new file mode 100644 index 000000000000..77b614c3d50b --- /dev/null +++ b/.changeset/shy-penguins-beg.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: skip comment nodes in snippet validation logic diff --git a/packages/svelte/src/compiler/phases/2-analyze/visitors/SnippetBlock.js b/packages/svelte/src/compiler/phases/2-analyze/visitors/SnippetBlock.js index 94bbd3cde17a..356cf2eeae68 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/visitors/SnippetBlock.js +++ b/packages/svelte/src/compiler/phases/2-analyze/visitors/SnippetBlock.js @@ -46,7 +46,10 @@ export function SnippetBlock(node, context) { ) { if ( parent.fragment.nodes.some( - (node) => node.type !== 'SnippetBlock' && (node.type !== 'Text' || node.data.trim()) + (node) => + node.type !== 'SnippetBlock' && + (node.type !== 'Text' || node.data.trim()) && + node.type !== 'Comment' ) ) { e.snippet_conflict(node); diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/Child.svelte b/packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/Child.svelte new file mode 100644 index 000000000000..5da1d878e8c4 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/Child.svelte @@ -0,0 +1,5 @@ + + +{@render children()} \ No newline at end of file diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/_config.js b/packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/_config.js new file mode 100644 index 000000000000..17eaeb955304 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/_config.js @@ -0,0 +1,5 @@ +import { test } from '../../test'; + +export default test({ + html: `The content` +}); diff --git a/packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/main.svelte b/packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/main.svelte new file mode 100644 index 000000000000..c1073ede0681 --- /dev/null +++ b/packages/svelte/tests/runtime-runes/samples/snippet-comment-sibling/main.svelte @@ -0,0 +1,10 @@ + + + + + {#snippet children()} + The content + {/snippet} +