Skip to content

Commit

Permalink
Merge pull request #792 from sveltejs/gh-790
Browse files Browse the repository at this point in the history
support nested <slot> elements
  • Loading branch information
Rich-Harris authored Aug 29, 2017
2 parents 87ef5ff + 5b3e8cd commit 56677a2
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/generators/server-side-rendering/visitors/Slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function visitSlot(
const name = node.attributes.find((attribute: Node) => attribute.name);
const slotName = name && name.value[0].data || 'default';

generator.append(`\${options && options.slotted && options.slotted.${slotName} ? options.slotted.${slotName}() : '`);
generator.append(`\${options && options.slotted && options.slotted.${slotName} ? options.slotted.${slotName}() : \``);

generator.elementDepth += 1;

Expand All @@ -22,5 +22,5 @@ export default function visitSlot(

generator.elementDepth -= 1;

generator.append(`'}`);
generator.append(`\`}`);
}
7 changes: 0 additions & 7 deletions src/parse/state/tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,6 @@ export default function tag(parser: Parser) {
start
);
}

if (item.type === 'Element' && item.name === 'slot') {
parser.error(
`<slot> elements cannot be nested`,
start
);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions test/runtime/samples/component-slot-nested/Nested.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<slot name='foo'>
<slot name='bar'></slot>
</slot>
</div>
6 changes: 6 additions & 0 deletions test/runtime/samples/component-slot-nested/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
html: `
<div>
<p slot='bar'>bar</p>
</div>`
};
13 changes: 13 additions & 0 deletions test/runtime/samples/component-slot-nested/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Nested>
<p slot='bar'>bar</p>
</Nested>

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

export default {
components: {
Nested
}
};
</script>
6 changes: 2 additions & 4 deletions test/server-side-rendering/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ describe("ssr", () => {
delete require.cache[resolved];
});

const component = require(`../runtime/samples/${dir}/main.html`);
let html;

try {
html = component.render(config.data);
const component = require(`../runtime/samples/${dir}/main.html`);
const html = component.render(config.data);

if (config.html) {
assert.htmlEqual(html, config.html);
Expand Down
8 changes: 0 additions & 8 deletions test/validator/samples/component-slot-nested/errors.json

This file was deleted.

3 changes: 0 additions & 3 deletions test/validator/samples/component-slot-nested/input.html

This file was deleted.

0 comments on commit 56677a2

Please sign in to comment.