diff --git a/packages/language-core/lib/codegen/script/template.ts b/packages/language-core/lib/codegen/script/template.ts index 3ecc891627..50113a84fb 100644 --- a/packages/language-core/lib/codegen/script/template.ts +++ b/packages/language-core/lib/codegen/script/template.ts @@ -18,18 +18,21 @@ export function* generateTemplate( if (!options.vueCompilerOptions.skipTemplateCodegen) { if (isClassComponent) { - yield `__VLS_template() {${newLine}`; + yield `__VLS_template = (() => {${newLine}`; } else { - yield `function __VLS_template() {${newLine}`; + yield `const __VLS_template = (() => {${newLine}`; } const templateCodegenCtx = createTemplateCodegenContext(new Set()); + yield `const __VLS_template_return = () => {${newLine}`; yield* generateCtx(options, isClassComponent); yield* generateTemplateContext(options, templateCodegenCtx); yield* generateExportOptions(options); yield* generateConstNameOption(options); + yield `}${endOfLine}`; yield* generateInternalComponent(options, ctx, templateCodegenCtx); - yield `}${newLine}`; + yield `return __VLS_template_return${endOfLine}`; + yield `})()${endOfLine}`; } else { yield `function __VLS_template() {${newLine}`; diff --git a/packages/tsc/tests/__snapshots__/dts.spec.ts.snap b/packages/tsc/tests/__snapshots__/dts.spec.ts.snap index 70d50901ca..fa28f7d399 100644 --- a/packages/tsc/tests/__snapshots__/dts.spec.ts.snap +++ b/packages/tsc/tests/__snapshots__/dts.spec.ts.snap @@ -656,7 +656,7 @@ export {}; `; exports[`vue-tsc-dts > Input: template-slots/component.vue, Output: template-slots/component.vue.d.ts 1`] = ` -"declare function __VLS_template(): { +"declare const __VLS_template: () => { slots: { "no-bind"?(_: {}): any; default?(_: { @@ -687,7 +687,7 @@ type __VLS_WithTemplateSlots = T & { exports[`vue-tsc-dts > Input: template-slots/component-define-slots.vue, Output: template-slots/component-define-slots.vue.d.ts 1`] = ` "import { VNode } from 'vue'; -declare function __VLS_template(): { +declare const __VLS_template: () => { slots: Readonly<{ default: (props: { num: number; @@ -729,7 +729,7 @@ type __VLS_WithTemplateSlots = T & { `; exports[`vue-tsc-dts > Input: template-slots/component-destructuring.vue, Output: template-slots/component-destructuring.vue.d.ts 1`] = ` -"declare function __VLS_template(): { +"declare const __VLS_template: () => { slots: Readonly<{ bottom: (props: { num: number; @@ -755,7 +755,7 @@ type __VLS_WithTemplateSlots = T & { `; exports[`vue-tsc-dts > Input: template-slots/component-no-script.vue, Output: template-slots/component-no-script.vue.d.ts 1`] = ` -"declare function __VLS_template(): { +"declare const __VLS_template: () => { slots: { "no-bind"?(_: {}): any; default?(_: { diff --git a/test-workspace/tsc/passedFixtures/vue3/#4391/comp.vue b/test-workspace/tsc/passedFixtures/vue3/#4391/comp.vue new file mode 100644 index 0000000000..c2e89ef85d --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3/#4391/comp.vue @@ -0,0 +1,5 @@ + diff --git a/test-workspace/tsc/passedFixtures/vue3/#4391/main.vue b/test-workspace/tsc/passedFixtures/vue3/#4391/main.vue new file mode 100644 index 0000000000..ac30a4b759 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3/#4391/main.vue @@ -0,0 +1,12 @@ + + +