mirror of https://github.com/sveltejs/svelte
fix: declare `let:` directives before `{@const}` on slotted elements (#18271)
Fixes #18119 (missed a spot in #16985)pull/18273/head
parent
8b961be0b1
commit
bb69f9c44c
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: declare `let:` directives before `{@const}` declarations on slotted elements
|
||||||
@ -0,0 +1,7 @@
|
|||||||
|
<script>
|
||||||
|
export let things;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#each things as thing}
|
||||||
|
<slot name="foo" {thing} />
|
||||||
|
{/each}
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
// `let:` directives on a slotted element must be declared before sibling `{@const}`
|
||||||
|
// declarations that capture them. In dev mode the `{@const}` derived is read eagerly,
|
||||||
|
// so a wrong declaration order throws "Cannot access '...' before initialization".
|
||||||
|
export default test({
|
||||||
|
compileOptions: {
|
||||||
|
dev: true
|
||||||
|
},
|
||||||
|
|
||||||
|
html: `
|
||||||
|
<div slot="foo"><span>1</span></div>
|
||||||
|
<div slot="foo"><span>2</span></div>
|
||||||
|
`
|
||||||
|
});
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
<script>
|
||||||
|
import Nested from './Nested.svelte';
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Nested things={[1, 2]}>
|
||||||
|
<div slot="foo" let:thing>
|
||||||
|
{@const props = { thing }}
|
||||||
|
<span>{props.thing}</span>
|
||||||
|
</div>
|
||||||
|
</Nested>
|
||||||
Loading…
Reference in new issue