Skip to content

Commit 7107d0a

Browse files
committed
fix(language-core): handle directives option correctly
fix #5292
1 parent 81a5b61 commit 7107d0a

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

packages/language-core/lib/codegen/globalTypes.ts

+3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ export function generateGlobalTypes({
138138
TypeEmits = ${target >= 3.6 ? `Comp extends { __typeEmits?: infer T } ? unknown extends T ? {} : import('${lib}').ShortEmitsToObject<T> : {}` : `{}`},
139139
NormalizedEmits = __VLS_NormalizeEmits<Emits> extends infer E ? string extends keyof E ? {} : E : never,
140140
> = __VLS_SpreadMerge<NormalizedEmits, TypeEmits>;
141+
type __VLS_ResolveDirectives<T> = {
142+
[K in Exclude<keyof T, keyof __VLS_GlobalDirectives> & string as \`v\${Capitalize<K>}\`]: T[K];
143+
};
141144
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
142145
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
143146

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

+3-7
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function* generateTemplateElements(): Generator<Code> {
6060
}
6161

6262
function* generateTemplateComponents(options: ScriptCodegenOptions): Generator<Code> {
63-
const types: Code[] = [];
63+
const types: Code[] = [`typeof __VLS_ctx`];
6464

6565
if (options.sfc.script && options.scriptRanges?.exportDefault?.componentsOption) {
6666
const { componentsOption } = options.scriptRanges.exportDefault;
@@ -75,8 +75,6 @@ function* generateTemplateComponents(options: ScriptCodegenOptions): Generator<C
7575
types.push(`typeof __VLS_componentsOption`);
7676
}
7777

78-
types.push(`typeof __VLS_ctx`);
79-
8078
yield `type __VLS_LocalComponents =`;
8179
for (const type of types) {
8280
yield ` & `;
@@ -88,7 +86,7 @@ function* generateTemplateComponents(options: ScriptCodegenOptions): Generator<C
8886
}
8987

9088
export function* generateTemplateDirectives(options: ScriptCodegenOptions): Generator<Code> {
91-
const types: Code[] = [];
89+
const types: Code[] = [`typeof __VLS_ctx`];
9290

9391
if (options.sfc.script && options.scriptRanges?.exportDefault?.directivesOption) {
9492
const { directivesOption } = options.scriptRanges.exportDefault;
@@ -100,11 +98,9 @@ export function* generateTemplateDirectives(options: ScriptCodegenOptions): Gene
10098
codeFeatures.navigation,
10199
];
102100
yield endOfLine;
103-
types.push(`typeof __VLS_directivesOption`);
101+
types.push(`__VLS_ResolveDirectives<typeof __VLS_directivesOption>`);
104102
}
105103

106-
types.push(`typeof __VLS_ctx`);
107-
108104
yield `type __VLS_LocalDirectives =`;
109105
for (const type of types) {
110106
yield ` & `;

test-workspace/tsc/passedFixtures/vue3/directives/option.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
import type { FunctionDirective } from 'vue';
33
import { exactType } from '../../shared';
44
5-
let Comp!: (_: { foo?: string; }) => void;
6-
75
export default {
86
directives: {
9-
vFoo: {} as FunctionDirective<typeof Comp, (_: string) => void>
7+
foo: {} as FunctionDirective<typeof Comp, (_: string) => void>
108
}
119
};
1210
</script>
1311

1412
<script setup lang="ts">
13+
let Comp!: (_: { foo?: string; }) => void;
1514
</script>
1615

1716
<template>

0 commit comments

Comments
 (0)