diff --git a/.changeset/funny-wombats-argue.md b/.changeset/funny-wombats-argue.md new file mode 100644 index 0000000000..2d5a707a17 --- /dev/null +++ b/.changeset/funny-wombats-argue.md @@ -0,0 +1,5 @@ +--- +"svelte": patch +--- + +fix: allow svelte:self in snippets diff --git a/packages/svelte/src/compiler/errors.js b/packages/svelte/src/compiler/errors.js index 51e0644c4c..615123088f 100644 --- a/packages/svelte/src/compiler/errors.js +++ b/packages/svelte/src/compiler/errors.js @@ -141,7 +141,7 @@ const special_elements = { /** @param {string} name */ 'duplicate-svelte-element': (name) => `A component can only have one <${name}> element`, 'invalid-self-placement': () => - ` components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components`, + ` components can only exist inside {#if} blocks, {#each} blocks, {#snippet} blocks or slots passed to components`, 'missing-svelte-element-definition': () => ` must have a 'this' attribute`, 'missing-svelte-component-definition': () => ` must have a 'this' attribute`, 'invalid-svelte-element-definition': () => `Invalid element definition — must be an {expression}`, diff --git a/packages/svelte/src/compiler/phases/1-parse/state/element.js b/packages/svelte/src/compiler/phases/1-parse/state/element.js index 51eac9ca53..d193aeaeb6 100644 --- a/packages/svelte/src/compiler/phases/1-parse/state/element.js +++ b/packages/svelte/src/compiler/phases/1-parse/state/element.js @@ -333,7 +333,8 @@ function read_tag_name(parser) { if ( fragment.type === 'IfBlock' || fragment.type === 'EachBlock' || - fragment.type === 'Component' + fragment.type === 'Component' || + fragment.type === 'SnippetBlock' ) { legal = true; break; diff --git a/packages/svelte/tests/compiler-errors/samples/self-reference/_config.js b/packages/svelte/tests/compiler-errors/samples/self-reference/_config.js index c1793c3043..5f5980b7ed 100644 --- a/packages/svelte/tests/compiler-errors/samples/self-reference/_config.js +++ b/packages/svelte/tests/compiler-errors/samples/self-reference/_config.js @@ -4,7 +4,7 @@ export default test({ error: { code: 'invalid-self-placement', message: - ' components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components', + ' components can only exist inside {#if} blocks, {#each} blocks,, {#snippet} blocks or slots passed to components', position: [1, 1] } });