Skip to content

Commit 3216627

Browse files
committed
fix(language-core): do not resolve type of components and directives by spreading
1 parent 128e58b commit 3216627

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
lines changed

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

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,19 @@ function* generateTemplateCtx(options: ScriptCodegenOptions): Generator<Code> {
5454
}
5555

5656
function* generateTemplateComponents(options: ScriptCodegenOptions): Generator<Code> {
57-
const exps: Code[] = [];
57+
const types: Code[] = [];
5858

5959
if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
6060
const { componentsOption } = options.scriptRanges.exportDefault;
61-
exps.push([
61+
yield `const __VLS_componentsOption = `
62+
yield [
6263
options.sfc.script.content.slice(componentsOption.start, componentsOption.end),
6364
'script',
6465
componentsOption.start,
6566
codeFeatures.navigation,
66-
]);
67+
];
68+
yield endOfLine;
69+
types.push(`typeof __VLS_componentsOption`);
6770
}
6871

6972
let nameType: Code | undefined;
@@ -76,52 +79,51 @@ function* generateTemplateComponents(options: ScriptCodegenOptions): Generator<C
7679
nameType = `'${options.scriptSetupRanges?.defineOptions?.name ?? baseName.slice(0, baseName.lastIndexOf('.'))}'`;
7780
}
7881
if (nameType) {
79-
exps.push(
80-
`{} as { [K in ${nameType}]: typeof __VLS_self & (new () => { `
82+
types.push(
83+
`{ [K in ${nameType}]: typeof __VLS_self & (new () => { `
8184
+ getSlotsPropertyName(options.vueCompilerOptions.target)
8285
+ `: typeof ${options.scriptSetupRanges?.defineSlots?.name ?? `__VLS_slots`} }) }`
8386
);
8487
}
8588

86-
exps.push(`{} as NonNullable<typeof __VLS_self extends { components: infer C } ? C : {}>`);
87-
exps.push(`__VLS_ctx`);
89+
types.push(`typeof __VLS_ctx`);
8890

89-
yield `const __VLS_localComponents = {${newLine}`;
90-
for (const type of exps) {
91-
yield `...`;
91+
yield `type __VLS_LocalComponents =`;
92+
for (const type of types) {
93+
yield ` & `;
9294
yield type;
93-
yield `,${newLine}`;
9495
}
95-
yield `}${endOfLine}`;
96+
yield endOfLine;
9697

97-
yield `let __VLS_components!: typeof __VLS_localComponents & __VLS_GlobalComponents${endOfLine}`;
98+
yield `let __VLS_components!: __VLS_LocalComponents & __VLS_GlobalComponents${endOfLine}`;
9899
}
99100

100101
export function* generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code> {
101-
const exps: Code[] = [];
102+
const types: Code[] = [];
102103

103104
if (options.sfc.script && options.scriptRanges?.exportDefault?.directivesOption) {
104105
const { directivesOption } = options.scriptRanges.exportDefault;
105-
exps.push([
106+
yield `const __VLS_directivesOption = `;
107+
yield [
106108
options.sfc.script.content.slice(directivesOption.start, directivesOption.end),
107109
'script',
108110
directivesOption.start,
109111
codeFeatures.navigation,
110-
]);
112+
];
113+
yield endOfLine;
114+
types.push(`typeof __VLS_directivesOption`);
111115
}
112116

113-
exps.push(`{} as NonNullable<typeof __VLS_self extends { directives: infer D } ? D : {}>`);
114-
exps.push(`__VLS_ctx`);
117+
types.push(`typeof __VLS_ctx`);
115118

116-
yield `const __VLS_localDirectives = {${newLine}`;
117-
for (const type of exps) {
118-
yield `...`;
119+
yield `type __VLS_LocalDirectives =`;
120+
for (const type of types) {
121+
yield ` & `;
119122
yield type;
120-
yield `,${newLine}`;
121123
}
122-
yield `}${endOfLine}`;
124+
yield endOfLine;
123125

124-
yield `let __VLS_directives!: typeof __VLS_localDirectives & __VLS_GlobalDirectives${endOfLine}`;
126+
yield `let __VLS_directives!: __VLS_LocalDirectives & __VLS_GlobalDirectives${endOfLine}`;
125127
}
126128

127129
function* generateTemplateBody(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function* generatePreResolveComponents(options: TemplateCodegenOptions): Generat
139139
}
140140
components.add(node.tag);
141141
yield newLine;
142-
yield ` & __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', typeof __VLS_localComponents, `;
142+
yield ` & __VLS_WithComponent<'${getCanonicalComponentName(node.tag)}', __VLS_LocalComponents, `;
143143
yield getPossibleOriginalComponentNames(node.tag, false)
144144
.map(name => `'${name}'`)
145145
.join(', ');

0 commit comments

Comments
 (0)