Skip to content

Assume let variables are dynamic in slots #3355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/compile/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class Component {
stats: Stats;
warnings: Warning[];
ignores: Set<string>;
ignore_stack: Set<string>[] = [];
ignore_stack: Array<Set<string>> = [];

ast: Ast;
source: string;
Expand Down
9 changes: 7 additions & 2 deletions src/compiler/compile/render_dom/wrappers/Slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default class SlotWrapper extends Wrapper {
});

const dynamic_dependencies = Array.from(attribute.dependencies).filter(name => {
if (this.node.scope.is_let(name)) return true;
const variable = renderer.component.var_lookup.get(name);
return is_dynamic(variable);
});
Expand All @@ -105,7 +106,7 @@ export default class SlotWrapper extends Wrapper {
}

const slot = block.get_unique_name(`${sanitize(slot_name)}_slot`);
const slot_definition = block.get_unique_name(`${sanitize(slot_name)}_slot`);
const slot_definition = block.get_unique_name(`${sanitize(slot_name)}_slot_template`);

block.builders.init.add_block(deindent`
const ${slot_definition} = ctx.$$slots${quote_prop_if_necessary(slot_name)};
Expand Down Expand Up @@ -162,6 +163,7 @@ export default class SlotWrapper extends Wrapper {

const dynamic_dependencies = Array.from(this.dependencies).filter(name => {
if (name === '$$scope') return true;
if (this.node.scope.is_let(name)) return true;
const variable = renderer.component.var_lookup.get(name);
return is_dynamic(variable);
});
Expand All @@ -171,7 +173,10 @@ export default class SlotWrapper extends Wrapper {

block.builders.update.add_block(deindent`
if (${slot} && ${slot}.p && ${update_conditions}) {
${slot}.p(@get_slot_changes(${slot_definition}, ctx, changed, ${get_slot_changes}), @get_slot_context(${slot_definition}, ctx, ${get_slot_context}));
${slot}.p(
@get_slot_changes(${slot_definition}, ctx, changed, ${get_slot_changes}),
@get_slot_context(${slot_definition}, ctx, ${get_slot_context})
);
}
`);

Expand Down
9 changes: 9 additions & 0 deletions test/runtime/samples/component-slot-let-f/A.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
import B from './B.svelte';
export let x;
</script>

<B {x} let:reflected>
<span>{reflected}</span>
<slot {reflected} />
</B>
5 changes: 5 additions & 0 deletions test/runtime/samples/component-slot-let-f/B.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script>
export let x;
</script>

<slot reflected={x}/>
15 changes: 15 additions & 0 deletions test/runtime/samples/component-slot-let-f/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default {
html: `
<span>1</span>
<span>1</span>
`,

async test({ assert, target, component }) {
component.x = 2;

assert.htmlEqual(target.innerHTML, `
<span>2</span>
<span>2</span>
`);
}
};
8 changes: 8 additions & 0 deletions test/runtime/samples/component-slot-let-f/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import A from './A.svelte';
export let x = 1;
</script>

<A {x} let:reflected>
<span>{reflected}</span>
</A>