Skip to content

Commit

Permalink
fix: allow svelte:self in snippets (#9439)
Browse files Browse the repository at this point in the history
* fix: allow svelte:self in snippets

* Create funny-wombats-argue.md
  • Loading branch information
paoloricciuti committed Nov 14, 2023
1 parent 73ae5ef commit e90ded6
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-wombats-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: allow svelte:self in snippets
2 changes: 1 addition & 1 deletion packages/svelte/src/compiler/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': () =>
`<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components`,
`<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, {#snippet} blocks or slots passed to components`,
'missing-svelte-element-definition': () => `<svelte:element> must have a 'this' attribute`,
'missing-svelte-component-definition': () => `<svelte:component> must have a 'this' attribute`,
'invalid-svelte-element-definition': () => `Invalid element definition — must be an {expression}`,
Expand Down
3 changes: 2 additions & 1 deletion packages/svelte/src/compiler/phases/1-parse/state/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default test({
error: {
code: 'invalid-self-placement',
message:
'<svelte:self> components can only exist inside {#if} blocks, {#each} blocks, or slots passed to components',
'<svelte:self> components can only exist inside {#if} blocks, {#each} blocks,, {#snippet} blocks or slots passed to components',
position: [1, 1]
}
});

1 comment on commit e90ded6

@vercel
Copy link

@vercel vercel bot commented on e90ded6 Nov 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

svelte-5-preview – ./sites/svelte-5-preview

svelte-5-preview.vercel.app
svelte-5-preview-git-main-svelte.vercel.app
svelte-5-preview-svelte.vercel.app
svelte-octane.vercel.app

Please sign in to comment.