Lint and format src/compiler/compile/render_ssr/handlers/SlotTemplate.js

pull/8569/head
Simon Holthausen 3 years ago
parent e6bd422c33
commit b753f26909

@ -11,39 +11,43 @@ import { get_const_tags } from './shared/get_const_tags';
* }} options * }} options
*/ */
export default function (node, renderer, options) { export default function (node, renderer, options) {
const parent_inline_component = /** @type {import('../../nodes/InlineComponent.js').default} */ (node.parent); const parent_inline_component = /** @type {import('../../nodes/InlineComponent.js').default} */ (
const children = remove_whitespace_children(node instanceof SlotTemplate ? node.children : [node], node.next); node.parent
renderer.push(); );
renderer.render(children, options); const children = remove_whitespace_children(
const lets = node.lets; node instanceof SlotTemplate ? node.children : [node],
const seen = new Set(lets.map((l) => l.name.name)); node.next
parent_inline_component.lets.forEach((l) => { );
if (!seen.has(l.name.name)) renderer.push();
lets.push(l); renderer.render(children, options);
}); const lets = node.lets;
const slot_fragment_content = renderer.pop(); const seen = new Set(lets.map((l) => l.name.name));
if (!is_empty_template_literal(slot_fragment_content)) { parent_inline_component.lets.forEach((l) => {
if (options.slot_scopes.has(node.slot_template_name)) { if (!seen.has(l.name.name)) lets.push(l);
if (node.slot_template_name === 'default') { });
throw new Error('Found elements without slot attribute when using slot="default"'); const slot_fragment_content = renderer.pop();
} if (!is_empty_template_literal(slot_fragment_content)) {
throw new Error(`Duplicate slot name "${node.slot_template_name}" in <${parent_inline_component.name}>`); if (options.slot_scopes.has(node.slot_template_name)) {
} if (node.slot_template_name === 'default') {
options.slot_scopes.set(node.slot_template_name, { throw new Error('Found elements without slot attribute when using slot="default"');
input: get_slot_scope(node.lets), }
output: slot_fragment_content, throw new Error(
statements: get_const_tags(node.const_tags) `Duplicate slot name "${node.slot_template_name}" in <${parent_inline_component.name}>`
}); );
} }
options.slot_scopes.set(node.slot_template_name, {
input: get_slot_scope(node.lets),
output: slot_fragment_content,
statements: get_const_tags(node.const_tags)
});
}
} }
/** @param {any} template_literal */ /** @param {any} template_literal */
function is_empty_template_literal(template_literal) { function is_empty_template_literal(template_literal) {
return (template_literal.expressions.length === 0 && return (
template_literal.quasis.length === 1 && template_literal.expressions.length === 0 &&
template_literal.quasis[0].value.raw === ''); template_literal.quasis.length === 1 &&
template_literal.quasis[0].value.raw === ''
);
} }

Loading…
Cancel
Save