Skip to content

Commit

Permalink
Merge pull request #851 from sveltejs/gh-850
Browse files Browse the repository at this point in the history
use anchor.parentNode as target instead of slot document fragment
  • Loading branch information
Rich-Harris authored Sep 16, 2017
2 parents fbbaff5 + 0a0f474 commit 1446338
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/generators/dom/visitors/IfBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function simple(
`if (${name}) ${name}.${mountOrIntro}(${targetNode}, ${anchorNode});`
);

const parentNode = (state.parentNode && !needsAnchor) ? state.parentNode : `${anchor}.parentNode`;
const parentNode = isDomNode(node.parent, generator) ? node.parent.var : `${anchor}.parentNode`;

const enter = dynamic
? branch.hasIntroMethod
Expand Down Expand Up @@ -255,7 +255,7 @@ function compound(
`${if_name}${name}.${mountOrIntro}(${targetNode}, ${anchorNode});`
);

const parentNode = (state.parentNode && !needsAnchor) ? state.parentNode : `${anchor}.parentNode`;
const parentNode = isDomNode(node.parent, generator) ? node.parent.var : `${anchor}.parentNode`;

const changeBlock = deindent`
${hasElse
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
<slot/>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default {
html: `
<div>
<p>unconditional</p>
</div>`,

test(assert, component, target) {
component.set({ foo: true });
assert.htmlEqual(target.innerHTML, `
<div>
<p>conditional</p>
<p>unconditional</p>
</div>
`);
}
};
17 changes: 17 additions & 0 deletions test/runtime/samples/component-slot-if-block-before-node/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Nested>
{{#if foo}}
<p>conditional</p>
{{/if}}

<p>unconditional</p>
</Nested>

<script>
import Nested from './Nested.html';

export default {
components: {
Nested
}
};
</script>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<slot/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default {
html: `
<p>disabled</p>
<p>unconditional</p>`,

test(assert, component, target) {
component.set({ enabled: true });
assert.htmlEqual(target.innerHTML, `
<p>enabled</p>
<p>unconditional</p>
`);
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Nested>
{{#if !enabled}}
<p>disabled</p>
{{else}}
<p>enabled</p>
{{/if}}

<p>unconditional</p>
</Nested>

<script>
import Nested from './Nested.html';

export default {
components: {
Nested
}
};
</script>

0 comments on commit 1446338

Please sign in to comment.