Skip to content

Commit

Permalink
Merge pull request #3171 from sveltejs/gh-3140
Browse files Browse the repository at this point in the history
Pass context used in bindings down to slots
  • Loading branch information
Rich-Harris authored Jul 6, 2019
2 parents e0874d1 + e85f8af commit 8203c22
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compiler/compile/nodes/shared/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ export default class Expression {
}

if (template_scope.is_let(name)) {
if (!function_expression) {
if (!function_expression) { // TODO should this be `!lazy` ?
contextual_dependencies.add(name);
dependencies.add(name);
}
} else if (template_scope.names.has(name)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
export let items;
</script>

<div>
{#each items as item, index}
<slot {index}/>
{/each}
</div>
26 changes: 26 additions & 0 deletions test/runtime/samples/component-slot-let-in-binding/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export default {
html: `
<div>
<label>1: <input></label>
<label>2: <input></label>
<label>3: <input></label>
</div>
`,

ssrHtml: `
<div>
<label>1: <input value="a"></label>
<label>2: <input value="b"></label>
<label>3: <input value="c"></label>
</div>
`,

async test({ assert, component, target, window }) {
const inputs = target.querySelectorAll('input');

inputs[2].value = 'd';
await inputs[2].dispatchEvent(new window.Event('input'));

assert.deepEqual(component.letters, ['a', 'b', 'd']);
}
};
11 changes: 11 additions & 0 deletions test/runtime/samples/component-slot-let-in-binding/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script>
import Nested from './Nested.svelte';
export let letters = ['a', 'b', 'c'];
</script>

<Nested items={letters} let:index>
<label>
{index + 1}: <input bind:value={letters[index]}>
</label>
</Nested>

0 comments on commit 8203c22

Please sign in to comment.