0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-12-01 17:30:59 +01:00

Merge pull request #3355 from sveltejs/gh-3354

Assume let variables are dynamic in slots
This commit is contained in:
Rich Harris 2019-08-06 08:58:06 -04:00 committed by GitHub
commit 7bf1ead963
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 45 additions and 3 deletions

View File

@ -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;

View File

@ -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);
});
@ -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)};
@ -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);
});
@ -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})
);
}
`);

View File

@ -0,0 +1,9 @@
<script>
import B from './B.svelte';
export let x;
</script>
<B {x} let:reflected>
<span>{reflected}</span>
<slot {reflected} />
</B>

View File

@ -0,0 +1,5 @@
<script>
export let x;
</script>
<slot reflected={x}/>

View File

@ -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>
`);
}
};

View File

@ -0,0 +1,8 @@
<script>
import A from './A.svelte';
export let x = 1;
</script>
<A {x} let:reflected>
<span>{reflected}</span>
</A>