SSR :Switch components

pull/971/head
Rich Harris 7 years ago
parent dba32df84e
commit 57af1539d9

@ -189,6 +189,14 @@ export default function ssr(
}
`
}
${
/__missingComponent/.test(generator.renderCode) && deindent`
var __missingComponent = {
render: () => ''
};
`
}
`.replace(/(@+|#+|%+)(\w*(?:-\w*)?)/g, (match: string, sigil: string, name: string) => {
if (sigil === '@') return generator.alias(name);
if (sigil === '%') return generator.templateVars.get(name);

@ -71,7 +71,14 @@ export default function visitComponent(
)
.join(', ');
const expression = node.name === ':Self' ? generator.name : `%components-${node.name}`;
const isSwitch = node.name === ':Switch';
if (isSwitch) block.contextualise(node.expression);
const expression = (
node.name === ':Self' ? generator.name :
isSwitch ? `((${node.metadata.snippet}) || __missingComponent)` :
`%components-${node.name}`
);
bindings.forEach(binding => {
block.addBinding(binding, expression);

@ -40,7 +40,7 @@ export default function visitElement(
return;
}
if (generator.components.has(node.name) || node.name === ':Self') {
if (generator.components.has(node.name) || node.name === ':Self' || node.name === ':Switch') {
visitComponent(generator, block, node);
return;
}

Loading…
Cancel
Save