Skip to content

Commit

Permalink
fix: only export functional component type when experimentalRfc436
Browse files Browse the repository at this point in the history
…enabled
  • Loading branch information
johnsoncodehk committed Oct 11, 2022
1 parent b3e592a commit 6db4beb
Showing 1 changed file with 31 additions and 19 deletions.
50 changes: 31 additions & 19 deletions vue-language-tools/vue-language-core/src/generators/script.ts
Expand Up @@ -242,7 +242,7 @@ export function generate(
0,
{ diagnostic: true },
]);
codeGen.push('export default ');
codeGen.push('export default (');
}
if (vueCompilerOptions.experimentalRfc436 && sfc.scriptSetup.generic) {
codeGen.push(`<${sfc.scriptSetup.generic}>`);
Expand Down Expand Up @@ -373,29 +373,41 @@ export function generate(

writeTemplate();

codeGen.push(`return {} as Omit<JSX.Element, 'props' | 'children'> & Omit<InstanceType<typeof __VLS_Component>, '$slots' | '$emit'>`);
codeGen.push(` & {\n`);
if (scriptSetupRanges.propsTypeArg) {
codeGen.push(`props: typeof __VLS_props,\n`);
}
else {
codeGen.push(`props: InstanceType<typeof __VLS_Component>['$props'],\n`);
}
codeGen.push(`$emit: `);
if (scriptSetupRanges.emitsTypeArg) {
addVirtualCode('scriptSetup', scriptSetupRanges.emitsTypeArg.start, scriptSetupRanges.emitsTypeArg.end);
if (vueCompilerOptions.experimentalRfc436) {
codeGen.push(`return {} as Omit<JSX.Element, 'props' | 'children'> & Omit<InstanceType<typeof __VLS_Component>, '$slots' | '$emit'>`);
codeGen.push(` & {\n`);
if (scriptSetupRanges.propsTypeArg) {
codeGen.push(`props: typeof __VLS_props,\n`);
}
else {
codeGen.push(`props: InstanceType<typeof __VLS_Component>['$props'],\n`);
}
codeGen.push(`$emit: `);
if (scriptSetupRanges.emitsTypeArg) {
addVirtualCode('scriptSetup', scriptSetupRanges.emitsTypeArg.start, scriptSetupRanges.emitsTypeArg.end);
}
else {
codeGen.push(`InstanceType<typeof __VLS_Component>['$emit']`);
}
codeGen.push(`,\n`);
if (htmlGen?.slotsNum) {
codeGen.push(`children: ReturnType<typeof __VLS_template>,\n`);
}
codeGen.push(`};\n`);
}
else {
codeGen.push(`InstanceType<typeof __VLS_Component>['$emit']`);
}
codeGen.push(`,\n`);
if (htmlGen?.slotsNum) {
codeGen.push(`children: ReturnType<typeof __VLS_template>,\n`);
codeGen.push(`return {} as typeof __VLS_Component`);
if (htmlGen?.slotsNum) {
codeGen.push(` & new () => { $slots: ReturnType<typeof __VLS_template> }`);
}
codeGen.push(`;\n`);
}
codeGen.push(`};\n`);
codeGen.push(`};\n`);
codeGen.push(`return {} as unknown as Awaited<ReturnType<typeof __VLS_setup>>;\n`);
codeGen.push(`}`);
codeGen.push(`})`);
if (!vueCompilerOptions.experimentalRfc436) {
codeGen.push(`({} as any)`);
}
if (scriptRanges?.exportDefault && scriptRanges.exportDefault.expression.end !== scriptRanges.exportDefault.end) {
addVirtualCode('script', scriptRanges.exportDefault.expression.end, scriptRanges.exportDefault.end);
}
Expand Down

0 comments on commit 6db4beb

Please sign in to comment.