Skip to content

Commit

Permalink
Merge pull request #1630 from sveltejs/gh-1621
Browse files Browse the repository at this point in the history
register dependencies of dynamic component expressions
  • Loading branch information
Rich-Harris authored Aug 4, 2018
2 parents 6012c96 + 48bd025 commit 7c51094
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compile/nodes/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ export default class Component extends Node {
) {
this.cannotUseInnerHTML();

if (this.expression) {
block.addDependencies(this.expression.dependencies);
}

this.attributes.forEach(attr => {
block.addDependencies(attr.dependencies);
});
Expand Down
1 change: 1 addition & 0 deletions test/runtime/samples/dynamic-component-in-if/Bar.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Bar</p>
1 change: 1 addition & 0 deletions test/runtime/samples/dynamic-component-in-if/Foo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Foo</p>
17 changes: 17 additions & 0 deletions test/runtime/samples/dynamic-component-in-if/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default {
html: `
<p>Foo</p>
`,

test(assert, component, target) {
const { Bar } = component.get();

component.set({
x: Bar
});

assert.htmlEqual(target.innerHTML, `
<p>Bar</p>
`);
}
};
18 changes: 18 additions & 0 deletions test/runtime/samples/dynamic-component-in-if/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{#if x}
<svelte:component this={x}/>
{/if}

<script>
import Foo from './Foo.html';
import Bar from './Bar.html';

export default {
data() {
return {
x: Foo,
Foo,
Bar
};
}
};
</script>

0 comments on commit 7c51094

Please sign in to comment.