Skip to content

Commit 6a063ec

Browse files
committed
fix: allow svelte:self in snippets
1 parent 66661ef commit 6a063ec

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

packages/svelte/src/compiler/errors.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ const special_elements = {
141141
/** @param {string} name */
142142
'duplicate-svelte-element': (name) => `A component can only have one <${name}> element`,
143143
'invalid-self-placement': () =>
144-
`<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components`,
144+
`<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, {#snippet} blocks or slots passed to components`,
145145
'missing-svelte-element-definition': () => `<svelte:element> must have a 'this' attribute`,
146146
'missing-svelte-component-definition': () => `<svelte:component> must have a 'this' attribute`,
147147
'invalid-svelte-element-definition': () => `Invalid element definition — must be an {expression}`,

packages/svelte/src/compiler/phases/1-parse/state/element.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ function read_tag_name(parser) {
331331
if (
332332
fragment.type === 'IfBlock' ||
333333
fragment.type === 'EachBlock' ||
334-
fragment.type === 'Component'
334+
fragment.type === 'Component' ||
335+
fragment.type === 'SnippetBlock'
335336
) {
336337
legal = true;
337338
break;

packages/svelte/tests/compiler-errors/samples/self-reference/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default test({
44
error: {
55
code: 'invalid-self-placement',
66
message:
7-
'<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components',
7+
'<svelte:self> components can only exist inside {#if} blocks, {#each} blocks,, {#snippet} blocks or slots passed to components',
88
position: [1, 1]
99
}
1010
});

0 commit comments

Comments
 (0)