mirror of https://github.com/sveltejs/svelte
feat: enable snippets to fill slots (#13427)
* feat: enable snippets to fill slots This allows people to use snippets to fill slots. It is implemented in the same way the default slot interop is already implemented, by passing a boolean to the hidden `$$slots` object, and using that at runtime to determine the correct outcome. The impact on bundle size is neglible. By enabling this, we can enhance our migration script to always transform slot usages (including `let:x` etc) to snippets. This wasn't possible before because we couldn't be sure if the other side was transformed to using render tags at the same time. This will be part of #13419. This is important because currently the migration script is transforming `<slot />` creations inside components, but since it's not touching its usage points the migration will make your app end up in a broken state which you have to finish by hand. This is a reduced alternative to, and closes #11619, which was also enabling the other way around, but that is a) not as necessary and b) more likely to confuse people / break, because it only works if your render function has 0-1 arguments. * unused * ditto - annotation is redundant * couple of drive-by consistency tweaks --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>pull/13486/head
parent
59b608c16e
commit
e8508526e7
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
feat: enable snippets to fill slots
|
@ -0,0 +1,5 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
html: `<p>Default</p> <p>Named foo</p>`
|
||||||
|
});
|
@ -0,0 +1,2 @@
|
|||||||
|
<p><slot /></p>
|
||||||
|
<p><slot name="named" foo="foo" /></p>
|
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
import Child from './child.svelte';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Child>
|
||||||
|
Default
|
||||||
|
{#snippet named({ foo })}
|
||||||
|
Named {foo}
|
||||||
|
{/snippet}
|
||||||
|
</Child>
|
Loading…
Reference in new issue