fix named slot bug

pull/6898/head
Yuichiro Yamashita 5 years ago
parent 24a338a4e8
commit ca63111498

@ -106,7 +106,7 @@ export default class InlineComponent extends Node {
if (child.type === 'SlotTemplate') { if (child.type === 'SlotTemplate') {
children.push(child); children.push(child);
info.children.splice(i, 1); info.children.splice(i, 1);
} else if ((child.type === 'Element' || child.type === 'InlineComponent' || child.type === 'Slot') && child.attributes.find(attribute => attribute.name === 'slot')) { } else if ((child.type === 'Element' || child.type === 'DynamicElement' || child.type === 'InlineComponent' || child.type === 'Slot') && child.attributes.find(attribute => attribute.name === 'slot')) {
const slot_template = { const slot_template = {
start: child.start, start: child.start,
end: child.end, end: child.end,
@ -126,17 +126,17 @@ export default class InlineComponent extends Node {
slot_template.attributes.push(attribute); slot_template.attributes.push(attribute);
} }
} }
children.push(slot_template); children.push(slot_template);
info.children.splice(i, 1); info.children.splice(i, 1);
} }
} }
if (info.children.some(node => not_whitespace_text(node))) { if (info.children.some(node => not_whitespace_text(node))) {
children.push({ children.push({
start: info.start, start: info.start,
end: info.end, end: info.end,
type: 'SlotTemplate', type: 'SlotTemplate',
name: 'svelte:fragment', name: 'svelte:fragment',
attributes: [], attributes: [],
children: info.children children: info.children

@ -0,0 +1,7 @@
<h1>Foo</h1>
<div id="default">
<slot></slot>
</div>
<div id="other">
<slot name='other'></slot>
</div>

@ -0,0 +1,29 @@
export default {
props: {
x: true
},
html: `
<h1>Foo</h1>
<div id="default">
<h1>This is default slot</h1>
</div>
<div id="other">
<h1 slot='other'>This is other slot</h1>
</div>
`,
test({ assert, component, target }) {
component.tag = 'h2';
assert.htmlEqual(target.innerHTML, `
<h1>Foo</h1>
<div id="default">
<h2>This is default slot</h2>
</div>
<div id="other">
<h2 slot='other'>This is other slot</h2>
</div>
`);
}
};

@ -0,0 +1,10 @@
<script>
import Foo from './Foo.svelte';
export let tag = "h1";
</script>
<Foo>
<svelte:element this={tag}>This is default slot</svelte:element>
<svelte:element this={tag} slot='other'>This is other slot</svelte:element>
</Foo>
Loading…
Cancel
Save