Skip to content

Commit

Permalink
propagate changes through slots with props (sveltejs#4091)
Browse files Browse the repository at this point in the history
  • Loading branch information
Timothy Johnson authored and taylorzane committed Dec 17, 2020
1 parent 78a7596 commit d7e5f1c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,9 @@ export default class InlineComponentWrapper extends Wrapper {
});
});

const non_let_dependencies = Array.from(fragment_dependencies).filter(name => !this.node.scope.is_let(name));

const dynamic_attributes = this.node.attributes.filter(a => a.get_dependencies().length > 0);

if (!uses_spread && (dynamic_attributes.length > 0 || this.node.bindings.length > 0 || non_let_dependencies.length > 0)) {
if (!uses_spread && (dynamic_attributes.length > 0 || this.node.bindings.length > 0 || fragment_dependencies.size > 0)) {
updates.push(b`const ${name_changes} = {};`);
}

Expand Down Expand Up @@ -266,9 +264,9 @@ export default class InlineComponentWrapper extends Wrapper {
}
}

if (non_let_dependencies.length > 0) {
if (fragment_dependencies.size > 0) {
updates.push(b`
if (${renderer.dirty(non_let_dependencies)}) {
if (${renderer.dirty(Array.from(fragment_dependencies))}) {
${name_changes}.$$scope = { dirty: #dirty, ctx: #ctx };
}`);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<slot/>
5 changes: 5 additions & 0 deletions test/runtime/samples/component-slot-let-in-slot/Outer.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let prop
</script>

<slot value={prop} />
12 changes: 12 additions & 0 deletions test/runtime/samples/component-slot-let-in-slot/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
props: {
prop: 'a',
},

html: 'a',

test({ assert, component, target }) {
component.prop = 'b';
assert.htmlEqual( target.innerHTML, 'b' );
}
};
10 changes: 10 additions & 0 deletions test/runtime/samples/component-slot-let-in-slot/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script>
import Outer from './Outer.svelte'
import Inner from './Inner.svelte'
export let prop
</script>

<Outer {prop} let:value>
<Inner>{value}</Inner>
</Outer>

0 comments on commit d7e5f1c

Please sign in to comment.