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:
commit
7bf1ead963
@ -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;
|
||||
|
@ -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})
|
||||
);
|
||||
}
|
||||
`);
|
||||
|
||||
|
9
test/runtime/samples/component-slot-let-f/A.svelte
Normal file
9
test/runtime/samples/component-slot-let-f/A.svelte
Normal 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>
|
5
test/runtime/samples/component-slot-let-f/B.svelte
Normal file
5
test/runtime/samples/component-slot-let-f/B.svelte
Normal file
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
export let x;
|
||||
</script>
|
||||
|
||||
<slot reflected={x}/>
|
15
test/runtime/samples/component-slot-let-f/_config.js
Normal file
15
test/runtime/samples/component-slot-let-f/_config.js
Normal 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>
|
||||
`);
|
||||
}
|
||||
};
|
8
test/runtime/samples/component-slot-let-f/main.svelte
Normal file
8
test/runtime/samples/component-slot-let-f/main.svelte
Normal file
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
import A from './A.svelte';
|
||||
export let x = 1;
|
||||
</script>
|
||||
|
||||
<A {x} let:reflected>
|
||||
<span>{reflected}</span>
|
||||
</A>
|
Loading…
Reference in New Issue
Block a user