From 9ae9323c69f71fcc3dba8641781cff86263716fe Mon Sep 17 00:00:00 2001 From: johnsoncodehk Date: Tue, 29 Nov 2022 20:21:23 +0800 Subject: [PATCH] fix: cannot infer parameter type in recursive component close #2140 --- .../src/generators/script.ts | 28 +++++++++---------- .../src/generators/template.ts | 4 +-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/vue-language-tools/vue-language-core/src/generators/script.ts b/vue-language-tools/vue-language-core/src/generators/script.ts index b5763a7b3..45f8c1cf2 100644 --- a/vue-language-tools/vue-language-core/src/generators/script.ts +++ b/vue-language-tools/vue-language-core/src/generators/script.ts @@ -288,12 +288,12 @@ export function generate( if (scriptRanges?.exportDefault && scriptRanges.exportDefault.expression.start !== scriptRanges.exportDefault.args.start) { // use defineComponent() from user space code if it exist - codeGen.push(`const __VLS_Component = `); + codeGen.push(`const __VLS_publicComponent = `); addVirtualCode('script', scriptRanges.exportDefault.expression.start, scriptRanges.exportDefault.args.start); codeGen.push(`{\n`); } else { - codeGen.push(`const __VLS_Component = (await import('${vueLibName}')).defineComponent({\n`); + codeGen.push(`const __VLS_publicComponent = (await import('${vueLibName}')).defineComponent({\n`); } if (!bypassDefineComponent) { @@ -397,20 +397,20 @@ export function generate( writeTemplate(); if (vueCompilerOptions.experimentalRfc436) { - codeGen.push(`return {} as Omit & Omit, '$slots' | '$emit'>`); + codeGen.push(`return {} as Omit & Omit, '$slots' | '$emit'>`); codeGen.push(` & {\n`); if (scriptSetupRanges.propsTypeArg) { codeGen.push(`props: typeof __VLS_props,\n`); } else { - codeGen.push(`props: InstanceType['$props'],\n`); + codeGen.push(`props: InstanceType['$props'],\n`); } codeGen.push(`$emit: `); if (scriptSetupRanges.emitsTypeArg) { addVirtualCode('scriptSetup', scriptSetupRanges.emitsTypeArg.start, scriptSetupRanges.emitsTypeArg.end); } else { - codeGen.push(`InstanceType['$emit']`); + codeGen.push(`InstanceType['$emit']`); } codeGen.push(`,\n`); if (htmlGen?.slotsNum) { @@ -422,7 +422,7 @@ export function generate( codeGen.push(`};\n`); } else { - codeGen.push(`return {} as typeof __VLS_Component`); + codeGen.push(`return {} as typeof __VLS_publicComponent`); if (htmlGen?.slotsNum) { codeGen.push(` & { new (): { $slots: ReturnType } }`); } @@ -477,7 +477,7 @@ export function generate( if (sfc.scriptSetup && scriptSetupRanges) { - codeGen.push(`const __VLS_component = (await import('${vueLibName}')).defineComponent({\n`); + codeGen.push(`const __VLS_internalComponent = (await import('${vueLibName}')).defineComponent({\n`); codeGen.push(`setup() {\n`); codeGen.push(`return {\n`); // fill ctx from props @@ -556,10 +556,10 @@ export function generate( codeGen.push(`});\n`); // defineComponent({ } else if (sfc.script) { - codeGen.push(`let __VLS_component!: typeof import('./${path.basename(fileName)}')['default'];\n`); + codeGen.push(`let __VLS_internalComponent!: typeof import('./${path.basename(fileName)}')['default'];\n`); } else { - codeGen.push(`const __VLS_component = (await import('${vueLibName}')).defineComponent({});\n`); + codeGen.push(`const __VLS_internalComponent = (await import('${vueLibName}')).defineComponent({});\n`); } } function writeExportOptions() { @@ -604,9 +604,9 @@ export function generate( codeGen.push(`let __VLS_ctx!: ${useGlobalThisTypeInCtx ? 'typeof globalThis &' : ''}`); codeGen.push(`import('./__VLS_types.js').PickNotAny<__VLS_Ctx, {}> & `); if (sfc.scriptSetup) { - codeGen.push(`InstanceType {}>> & `); + codeGen.push(`InstanceType {}>> & `); } - codeGen.push(`InstanceType {}>> & {\n`); + codeGen.push(`InstanceType {}>> & {\n`); /* CSS Module */ for (const cssModule of cssModuleClasses) { @@ -626,10 +626,10 @@ export function generate( /* Components */ codeGen.push('/* Components */\n'); - codeGen.push(`let __VLS_localComponents!: NonNullable & typeof __VLS_componentsOption & typeof __VLS_ctx;\n`); + codeGen.push(`let __VLS_localComponents!: NonNullable & typeof __VLS_componentsOption & typeof __VLS_ctx;\n`); codeGen.push(`let __VLS_otherComponents!: typeof __VLS_localComponents & Omit;\n`); - codeGen.push(`let __VLS_selfComponent!: import('./__VLS_types.js').SelfComponent { ${getSlotsPropertyName(vueCompilerOptions.target ?? 3)}: typeof __VLS_slots })>;\n`); - codeGen.push(`let __VLS_components!: typeof __VLS_otherComponents & Omit;\n`); + codeGen.push(`let __VLS_own!: import('./__VLS_types.js').SelfComponent { ${getSlotsPropertyName(vueCompilerOptions.target ?? 3)}: typeof __VLS_slots })>;\n`); + codeGen.push(`let __VLS_components!: typeof __VLS_otherComponents & Omit;\n`); /* Style Scoped */ codeGen.push('/* Style Scoped */\n'); diff --git a/vue-language-tools/vue-language-core/src/generators/template.ts b/vue-language-tools/vue-language-core/src/generators/template.ts index 56195f4ea..b8beb94aa 100644 --- a/vue-language-tools/vue-language-core/src/generators/template.ts +++ b/vue-language-tools/vue-language-core/src/generators/template.ts @@ -833,10 +833,10 @@ export function generate( const _varComponentInstanceA = `__VLS_${elementIndex++}`; const _varComponentInstanceB = `__VLS_${elementIndex++}`; _varComponentInstance = `__VLS_${elementIndex++}`; - codeGen.push(`const ${_varComponentInstanceA} = new ${componentVar}({ `); + codeGen.push(`const ${_varComponentInstanceA} = new __VLS_templateComponents.${componentVar}({ `); writeProps(node, 'class', 'slots'); codeGen.push(`});\n`); - codeGen.push(`const ${_varComponentInstanceB} = ${componentVar}({ `); + codeGen.push(`const ${_varComponentInstanceB} = __VLS_templateComponents.${componentVar}({ `); writeProps(node, 'class', 'slots'); codeGen.push(`});\n`); codeGen.push(`let ${_varComponentInstance}!: import('./__VLS_types.js').PickNotAny;\n`);