Skip to content

Commit

Permalink
feat: support native element
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Jan 21, 2025
1 parent 6e97d23 commit 6201b84
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
27 changes: 14 additions & 13 deletions packages/language-core/lib/codegen/globalTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
? K extends { __ctx?: { props?: infer P } } ? NonNullable<P> : never
: T extends (props: infer P, ...args: any) => any ? P
: {};
type __VLS_FunctionalGeneralComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
__ctx?: {
attrs?: any,
slots?: T extends { ${getSlotsPropertyName(target)}: infer Slots } ? Slots : any,
emit?: T extends { $emit: infer Emit } ? Emit : any,
props?: ${fnPropsType},
expose?(exposed: T): void,
}
};
type __VLS_NormalizeSlotReturns<S, R = ReturnType<NonNullable<S>>> = R extends any[] ? {
[K in keyof R]: R[K] extends { __ctx?: any } | Element
? R[K]
: ReturnType<__VLS_FunctionalGeneralComponent<R[K]>>
} : R;
type __VLS_IsFunction<T, K> = K extends keyof T
? __VLS_IsAny<T[K]> extends false
? unknown extends T[K]
Expand Down Expand Up @@ -99,19 +113,6 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates
type __VLS_PrettifyGlobal<T> = { [K in keyof T]: T[K]; } & {};
type __VLS_UseTemplateRef<T> = Readonly<import('${lib}').ShallowRef<T | null>>;
type __VLS_FunctionalGeneralComponent<T> = (props: ${fnPropsType}, ctx?: any) => __VLS_Element & {
__ctx?: {
attrs?: any,
slots?: T extends { ${getSlotsPropertyName(target)}: infer Slots } ? Slots : any,
emit?: T extends { $emit: infer Emit } ? Emit : any,
props?: ${fnPropsType},
expose?(exposed: T): void,
}
};
type __VLS_NormalizeSlotReturns<S, R = ReturnType<NonNullable<S>>> = R extends any[] ? {
[K in keyof R]: R[K] extends { __ctx?: any } ? R[K] : ReturnType<__VLS_FunctionalGeneralComponent<R[K]>>
} : R;
function __VLS_getVForSourceType(source: number): [number, number, number][];
function __VLS_getVForSourceType(source: string): [string, number, number][];
function __VLS_getVForSourceType<T extends any[]>(source: T): [
Expand Down
6 changes: 6 additions & 0 deletions packages/language-core/lib/codegen/template/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,12 @@ export function* generateElement(
: undefined;
const failedPropExps: FailedPropExpression[] = [];

ctx.currentComponent?.childNodes.push({
name: `__VLS_nativeElements.${node.tag}`,
start: node.loc.start.offset,
end: node.loc.end.offset
});

yield `__VLS_asFunctionalElement(__VLS_intrinsicElements`;
yield* generatePropertyAccess(
options,
Expand Down
4 changes: 4 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/slot-children/main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ const foo = {} as 'a' | 'b';
<Child :foo="(`b` as const)" />
<!-- @vue-expect-error -->
<Child :foo="(`c` as const)" />

<a></a>
<!-- @vue-expect-error -->
<img />
</Parent>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ defineProps<{
foo: T;
}>();
defineSlots<{
default?(): ReturnType<typeof Child<T>>[];
default?(): (ReturnType<typeof Child<T>> | HTMLAnchorElement)[];
}>();
</script>

0 comments on commit 6201b84

Please sign in to comment.