Skip to content

Commit

Permalink
Drop support for Vue 3.3 slots short definition (#3116)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed May 3, 2023
1 parent 4f7f872 commit c5c025c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 38 deletions.
24 changes: 8 additions & 16 deletions packages/vue-language-core/src/generators/script.ts
Expand Up @@ -78,7 +78,6 @@ export function generate(
mergePropDefaults: false,
ConstructorOverloads: false,
WithTemplateSlots: false,
ToTemplateSlots: false,
PropsChildren: false,
};

Expand Down Expand Up @@ -156,9 +155,6 @@ export function generate(
`} };\n`,
);
}
if (usedHelperTypes.ToTemplateSlots) {
codes.push(`type __VLS_ToTemplateSlots<T> = { [K in keyof T]?: NonNullable<T[K]> extends (...args: any[]) => any ? T[K] : (props: T[K]) => any };\n`);
}
if (usedHelperTypes.PropsChildren) {
codes.push(`type __VLS_PropsChildren<S> = { [K in keyof (boolean extends (JSX.ElementChildrenAttribute extends never ? true : false) ? never : JSX.ElementChildrenAttribute)]?: S; };\n`);
}
Expand Down Expand Up @@ -385,22 +381,20 @@ export function generate(
codes.push(`};\n`);
}
if (scriptSetupRanges.slotsTypeArg && vueCompilerOptions.jsxSlots) {
usedHelperTypes.ToTemplateSlots = true;
usedHelperTypes.PropsChildren = true;
codes.push(` & __VLS_PropsChildren<__VLS_ToTemplateSlots<`);
codes.push(` & __VLS_PropsChildren<`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
codes.push(`>>`);
codes.push(`>`);
}
codes.push(`;\n`);
}
else {
codes.push(`const __VLS_props: {}`);
if (scriptSetupRanges.slotsTypeArg && vueCompilerOptions.jsxSlots) {
usedHelperTypes.ToTemplateSlots = true;
usedHelperTypes.PropsChildren = true;
codes.push(` & __VLS_PropsChildren<__VLS_ToTemplateSlots<`);
codes.push(` & __VLS_PropsChildren<`);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
codes.push(`>>`);
codes.push(`>`);
}
if (scriptSetupRanges.propsTypeArg) {
codes.push(' & ');
Expand Down Expand Up @@ -685,10 +679,9 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
generateConstNameOption();

if (scriptSetupRanges?.slotsTypeArg && sfc.scriptSetup) {
usedHelperTypes.ToTemplateSlots = true;
codes.push(`var __VLS_slots!: __VLS_ToTemplateSlots<`);
codes.push(`var __VLS_slots!: `);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
codes.push('>;\n');
codes.push(';\n');
};

codes.push(`function __VLS_template() {\n`);
Expand Down Expand Up @@ -875,10 +868,9 @@ declare function defineProp<T>(value?: T | (() => T), required?: boolean, rest?:
if (!htmlGen) {
codes.push(`// no template\n`);
if (scriptSetupRanges?.slotsTypeArg && sfc.scriptSetup) {
usedHelperTypes.ToTemplateSlots = true;
codes.push(`let __VLS_slots!: __VLS_ToTemplateSlots<`);
codes.push(`let __VLS_slots!: `);
addExtraReferenceVirtualCode('scriptSetup', scriptSetupRanges.slotsTypeArg.start, scriptSetupRanges.slotsTypeArg.end);
codes.push(`>;\n`);
codes.push(`;\n`);
}
else {
codes.push(`const __VLS_slots = {};\n`);
Expand Down
4 changes: 2 additions & 2 deletions packages/vue-test-workspace/vue-tsc/#2726/main.vue
Expand Up @@ -6,10 +6,10 @@ import { ref } from 'vue';
const foo = ref('bar');
defineSlots<{
default: {
default: (_: {
foo: string;
buz?: number;
};
}) => any;
}>();
</script>

Expand Down
4 changes: 2 additions & 2 deletions packages/vue-test-workspace/vue-tsc/#2758/main.vue
Expand Up @@ -12,9 +12,9 @@
<script lang="ts" setup generic="T extends Record<string, string>">
defineSlots<
{
[K in `cell:${string}`]: { value: T[keyof T] };
[K in `cell:${string}`]?: (_: { value: T[keyof T] }) => any;
} & {
default: Record<string, any>;
default?: (_: Record<string, any>) => any;
}
>();
</script>
7 changes: 0 additions & 7 deletions packages/vue-test-workspace/vue-tsc/components/main.vue
Expand Up @@ -6,7 +6,6 @@ import ScriptSetupExpose from './script-setup-expose.vue';
import ScriptSetupTypeOnly from './script-setup-type-only.vue';
import ScriptSetupDefaultProps from './script-setup-default-props.vue';
import ScriptSetupGeneric from './script-setup-generic.vue';
import ShortDefineSlots from './short-define-slots.vue';
// https://vuejs.org/api/sfc-script-setup.html#defineprops-defineemits
const ScriptSetupExact = defineComponent({
Expand Down Expand Up @@ -80,10 +79,4 @@ exactType(ScriptSetupExpose, ScriptSetupExposeExact);
exactType(ScriptSetupTypeOnly, ScriptSetupTypeOnlyExact);
exactType(ScriptSetupDefaultProps, ScriptSetupDefaultPropsExact);
exactType(ScriptSetupGeneric, ScriptSetupGenericExact);
exactType((new ShortDefineSlots()).$slots.foo, {} as ((props: {
id: string;
} | undefined) => any) | undefined);
exactType((new ShortDefineSlots()).$slots.bar, {} as ((props: {
id: number;
}) => any) | undefined);
</script>
Expand Up @@ -2,7 +2,7 @@
defineProps<{ foo: T }>();
defineEmits<{ (e: 'bar', data: T): void }>();
defineExpose({ baz: {} as T });
defineSlots<{ default(data: T): any }>();
defineSlots<{ default?(data: T): any }>();
</script>

<script lang="ts">
Expand Down

This file was deleted.

0 comments on commit c5c025c

Please sign in to comment.