Skip to content

Commit

Permalink
fix(language-core): do not wrap slots with Readonly
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Feb 12, 2025
1 parent 3d5e4e4 commit ef38d68
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 36 deletions.
52 changes: 24 additions & 28 deletions packages/language-core/lib/codegen/template/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,36 +70,32 @@ function* generateSlots(
const name = getSlotsPropertyName(options.vueCompilerOptions.target);
if (!options.hasDefineSlots) {
yield `var __VLS_slots!: __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.${name}>`;
if (ctx.dynamicSlots.length || ctx.slots.length) {
yield ` & Readonly<`;
for (const { expVar, propsVar } of ctx.dynamicSlots) {
ctx.hasSlot = true;
yield `${newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
for (const { expVar, propsVar } of ctx.dynamicSlots) {
ctx.hasSlot = true;
yield `${newLine}& { [K in NonNullable<typeof ${expVar}>]?: (props: typeof ${propsVar}) => any }`;
}
for (const slot of ctx.slots) {
yield `${newLine}& { `;
ctx.hasSlot = true;
if (slot.name && slot.offset !== undefined) {
yield* generateObjectProperty(
options,
ctx,
slot.name,
slot.offset,
ctx.codeFeatures.withoutHighlightAndCompletion,
slot.nodeLoc
);
}
for (const slot of ctx.slots) {
yield `${newLine}& { `;
ctx.hasSlot = true;
if (slot.name && slot.offset !== undefined) {
yield* generateObjectProperty(
options,
ctx,
slot.name,
slot.offset,
ctx.codeFeatures.withoutHighlightAndCompletion,
slot.nodeLoc
);
}
else {
yield* wrapWith(
slot.tagRange[0],
slot.tagRange[1],
ctx.codeFeatures.withoutHighlightAndCompletion,
`default`
);
}
yield `?: (props: typeof ${slot.propsVar}) => any }`;
else {
yield* wrapWith(
slot.tagRange[0],
slot.tagRange[1],
ctx.codeFeatures.withoutHighlightAndCompletion,
`default`
);
}
yield `${newLine}>`;
yield `?: (props: typeof ${slot.propsVar}) => any }`;
}
yield `>${endOfLine}`;
}
Expand Down
10 changes: 5 additions & 5 deletions packages/tsc/tests/__snapshots__/dts.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ declare const _default: <Row extends BaseRow>(__VLS_props: NonNullable<Awaited<t
expose(exposed: import("vue").ShallowUnwrapRef<{}>): void;
attrs: any;
slots: {
readonly default?: (props: {
default?: (props: {
row: Row;
}) => any;
};
Expand Down Expand Up @@ -606,15 +606,15 @@ declare var __VLS_3: {
num: number;
str: string;
};
declare var __VLS_slots: __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$slots> & Readonly<{
declare var __VLS_slots: __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$slots> & {
'no-bind'?: (props: typeof __VLS_0) => any;
} & {
default?: (props: typeof __VLS_1) => any;
} & {
'named-slot'?: (props: typeof __VLS_2) => any;
} & {
vbind?: (props: typeof __VLS_3) => any;
}>>;
}>;
type __VLS_TemplateSlots = typeof __VLS_slots;
declare const __VLS_self: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
Expand Down Expand Up @@ -702,15 +702,15 @@ declare var __VLS_3: {
num: number;
str: string;
};
declare var __VLS_slots: __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$slots> & Readonly<{
declare var __VLS_slots: __VLS_PrettifyGlobal<__VLS_OmitStringIndex<typeof __VLS_ctx.$slots> & {
'no-bind'?: (props: typeof __VLS_0) => any;
} & {
default?: (props: typeof __VLS_1) => any;
} & {
'named-slot'?: (props: typeof __VLS_2) => any;
} & {
vbind?: (props: typeof __VLS_3) => any;
}>>;
}>;
type __VLS_TemplateSlots = typeof __VLS_slots;
declare const __VLS_self: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
Expand Down
6 changes: 3 additions & 3 deletions test-workspace/tsc/passedFixtures/vue3/slots/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ import { exactType } from '../../shared';
const baz = ref('baz' as const);
const slots = useSlots();
exactType(slots, {} as Readonly<{
foo?: (props: any) => any;
exactType(slots, {} as {
readonly foo?: (props: any) => any;
bar?: (props: { str: string; num: number; }) => any;
baz?: (props: { str: string; num: number; }) => any;
}>);
});
</script>

0 comments on commit ef38d68

Please sign in to comment.