Skip to content

Commit 659de0a

Browse files
committed
refactor: simplify conditional logic
1 parent 831ec04 commit 659de0a

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,23 @@ function* generateTemplateCtx(
4141
): Generator<Code> {
4242
const exps: Code[] = [];
4343

44+
if (options.vueCompilerOptions.petiteVueExtensions.some(ext => options.fileName.endsWith(ext))) {
45+
exps.push(`globalThis`);
46+
}
4447
if (options.sfc.script && options.scriptRanges?.exportDefault) {
4548
exps.push(`{} as InstanceType<__VLS_PickNotAny<typeof __VLS_self, new () => {}>>`);
4649
}
4750
else {
4851
exps.push(`{} as import('${options.vueCompilerOptions.lib}').ComponentPublicInstance`);
4952
}
50-
51-
if (options.vueCompilerOptions.petiteVueExtensions.some(ext => options.fileName.endsWith(ext))) {
52-
exps.push(`globalThis`);
53-
}
5453
if (options.sfc.styles.some(style => style.module)) {
5554
exps.push(`{} as __VLS_StyleModules`);
5655
}
5756

58-
const emitTypes: Code[] = [];
57+
const emitTypes: string[] = [];
5958
if (options.scriptSetupRanges?.defineEmits) {
60-
emitTypes.push(`typeof ${options.scriptSetupRanges.defineEmits.name ?? `__VLS_emit`}`);
59+
const { defineEmits } = options.scriptSetupRanges;
60+
emitTypes.push(`typeof ${defineEmits.name ?? `__VLS_emit`}`);
6161
}
6262
if (options.scriptSetupRanges?.defineModel.length) {
6363
emitTypes.push(`typeof __VLS_modelEmit`);
@@ -67,19 +67,19 @@ function* generateTemplateCtx(
6767
exps.push(`{} as { $emit: ${emitTypes.join(' & ')} }`);
6868
}
6969

70-
if (options.scriptSetupRanges?.defineProps || ctx.generatedPropsType || emitTypes.length) {
71-
yield `type __VLS_InternalProps =`;
72-
const { defineProps } = options.scriptSetupRanges ?? {};
73-
if (defineProps) {
74-
yield ` __VLS_SpreadMerge<__VLS_PublicProps, typeof ${defineProps.name ?? `__VLS_props`}>`;
75-
}
76-
else if (ctx.generatedPropsType) {
77-
yield ` __VLS_PublicProps`;
78-
}
79-
if (emitTypes.length) {
80-
yield ` & __VLS_EmitProps`;
81-
}
82-
yield endOfLine;
70+
const propTypes: string[] = [];
71+
if (options.scriptSetupRanges?.defineProps) {
72+
const { defineProps } = options.scriptSetupRanges;
73+
propTypes.push(`__VLS_SpreadMerge<__VLS_PublicProps, typeof ${defineProps.name ?? `__VLS_props`}>`);
74+
}
75+
else if (ctx.generatedPropsType) {
76+
propTypes.push(`__VLS_PublicProps`);
77+
}
78+
if (emitTypes.length) {
79+
propTypes.push(`__VLS_EmitProps`);
80+
}
81+
if (propTypes.length) {
82+
yield `type __VLS_InternalProps = ${propTypes.join(' & ')}${endOfLine}`;
8383
exps.push(`{} as { $props: __VLS_InternalProps }`);
8484
exps.push(`{} as __VLS_InternalProps`);
8585
}

0 commit comments

Comments
 (0)