From 70419daf5f33adddd1b552df8c202fde93ed992f Mon Sep 17 00:00:00 2001 From: Paolo Ricciuti Date: Thu, 9 May 2024 01:30:02 +0200 Subject: [PATCH] fix: use snippet as parent element of snippets childrens in validator (#11463) * fix: use snippet as parent element of snippets childrens in validator * Update packages/svelte/src/compiler/phases/2-analyze/validation.js * Update .changeset/wet-pears-remain.md --------- Co-authored-by: Rich Harris --- .changeset/wet-pears-remain.md | 5 +++++ .../svelte/src/compiler/phases/2-analyze/validation.js | 2 ++ .../non-invalid-node-placement-if-snippet/errors.json | 1 + .../non-invalid-node-placement-if-snippet/input.svelte | 10 ++++++++++ 4 files changed, 18 insertions(+) create mode 100644 .changeset/wet-pears-remain.md create mode 100644 packages/svelte/tests/validator/samples/non-invalid-node-placement-if-snippet/errors.json create mode 100644 packages/svelte/tests/validator/samples/non-invalid-node-placement-if-snippet/input.svelte diff --git a/.changeset/wet-pears-remain.md b/.changeset/wet-pears-remain.md new file mode 100644 index 0000000000..48a69d89b1 --- /dev/null +++ b/.changeset/wet-pears-remain.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: skip parent element validation for snippet contents diff --git a/packages/svelte/src/compiler/phases/2-analyze/validation.js b/packages/svelte/src/compiler/phases/2-analyze/validation.js index c2c7dece31..00985e8381 100644 --- a/packages/svelte/src/compiler/phases/2-analyze/validation.js +++ b/packages/svelte/src/compiler/phases/2-analyze/validation.js @@ -622,6 +622,8 @@ const validation = { SnippetBlock(node, context) { validate_block_not_empty(node.body, context); + context.next({ ...context.state, parent_element: null }); + if (node.expression.name !== 'children') return; const { path } = context; diff --git a/packages/svelte/tests/validator/samples/non-invalid-node-placement-if-snippet/errors.json b/packages/svelte/tests/validator/samples/non-invalid-node-placement-if-snippet/errors.json new file mode 100644 index 0000000000..fe51488c70 --- /dev/null +++ b/packages/svelte/tests/validator/samples/non-invalid-node-placement-if-snippet/errors.json @@ -0,0 +1 @@ +[] diff --git a/packages/svelte/tests/validator/samples/non-invalid-node-placement-if-snippet/input.svelte b/packages/svelte/tests/validator/samples/non-invalid-node-placement-if-snippet/input.svelte new file mode 100644 index 0000000000..1e315eb038 --- /dev/null +++ b/packages/svelte/tests/validator/samples/non-invalid-node-placement-if-snippet/input.svelte @@ -0,0 +1,10 @@ + + + + {#snippet cell(v)}Value: {v}{/snippet} + {#each [1, 2, 3] as v} + + {/each} + + +
{@render cell(v)}
\ No newline at end of file