improve error message if this attribute of <svelte:component> is not SvelteComponent

pull/7551/head
Yuichiro Yamashita 4 years ago
parent 038e7b092a
commit 6bf77a6451

@ -416,6 +416,7 @@ export default class InlineComponentWrapper extends Wrapper {
} }
if (${switch_value}) { if (${switch_value}) {
${component.compile_options.dev && b`@validate_svelte_component(${switch_value});`}
${name} = new ${switch_value}(${switch_props}(#ctx)); ${name} = new ${switch_value}(${switch_props}(#ctx));
${munged_bindings} ${munged_bindings}
@ -460,6 +461,7 @@ export default class InlineComponentWrapper extends Wrapper {
} }
if (${switch_value}) { if (${switch_value}) {
${component.compile_options.dev && b`@validate_svelte_component(${switch_value});`}
${name} = new ${switch_value}(${switch_props}(#ctx)); ${name} = new ${switch_value}(${switch_props}(#ctx));
${munged_bindings} ${munged_bindings}

@ -121,6 +121,12 @@ export function validate_void_dynamic_element(tag: undefined | string) {
} }
} }
export function validate_svelte_component(component: any) {
if (!(component.prototype instanceof SvelteComponent)) {
throw new Error('this={...} of <svelte:component> should specify a Svelte component.');
}
}
type Props = Record<string, any>; type Props = Record<string, any>;
export interface SvelteComponentDev { export interface SvelteComponentDev {
$set(props?: Props): void; $set(props?: Props): void;

@ -122,7 +122,7 @@ export const missing_component = {
export function validate_component(component, name) { export function validate_component(component, name) {
if (!component || !component.$$render) { if (!component || !component.$$render) {
if (name === 'svelte:component') name += ' this={...}'; if (name === 'svelte:component') name += ' this={...}';
throw new Error(`<${name}> is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules`); throw new Error(`<${name}> is not a valid SSR component. You may need to review your build config to ensure that dependencies are compiled, rather than imported as pre-compiled modules. Otherwise you may need to fix a <${name}>.`);
} }
return component; return component;

Loading…
Cancel
Save