Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop support for Vue 3.3 slots short definition #3116

Merged
merged 1 commit into from May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.