Skip to content

Commit b87a507

Browse files
committed
fix(language-core): ignore hoist variables error
1 parent 32e455f commit b87a507

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

packages/language-core/lib/codegen/template/context.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,13 @@ export function createTemplateCodegenContext(options: Pick<TemplateCodegenOption
129129
},
130130
generateHoistVariables: function* () {
131131
// trick to avoid TS 4081 (#5186)
132-
for (const [originalVar, hoistVar] of hoistVars) {
133-
yield `var ${hoistVar} = ${originalVar}${endOfLine}`;
132+
if (hoistVars.size) {
133+
yield `// @ts-ignore${newLine}`;
134+
yield `var `
135+
for (const [originalVar, hoistVar] of hoistVars) {
136+
yield `${hoistVar} = ${originalVar}, `;
137+
}
138+
yield endOfLine;
134139
}
135140
},
136141
ignoreError: function* (): Generator<Code> {

packages/tsc/tests/__snapshots__/dts.spec.ts.snap

+6-12
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,11 @@ export {};
587587
588588
exports[`vue-tsc-dts > Input: template-slots/component.vue, Output: template-slots/component.vue.d.ts 1`] = `
589589
"declare const __VLS_ctx: InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>;
590-
declare var __VLS_1: {};
591-
declare var __VLS_3: {
590+
declare var __VLS_1: {}, __VLS_3: {
592591
num: number;
593-
};
594-
declare var __VLS_5: {
592+
}, __VLS_5: {
595593
str: string;
596-
};
597-
declare var __VLS_7: {
594+
}, __VLS_7: {
598595
num: number;
599596
str: string;
600597
};
@@ -664,14 +661,11 @@ type __VLS_WithSlots<T, S> = T & {
664661
665662
exports[`vue-tsc-dts > Input: template-slots/component-no-script.vue, Output: template-slots/component-no-script.vue.d.ts 1`] = `
666663
"declare const __VLS_ctx: InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>;
667-
declare var __VLS_1: {};
668-
declare var __VLS_3: {
664+
declare var __VLS_1: {}, __VLS_3: {
669665
num: number;
670-
};
671-
declare var __VLS_5: {
666+
}, __VLS_5: {
672667
str: string;
673-
};
674-
declare var __VLS_7: {
668+
}, __VLS_7: {
675669
num: number;
676670
str: string;
677671
};

0 commit comments

Comments
 (0)