Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support nested <slot> elements #792

Merged
merged 1 commit into from
Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.