From c0df03ad5671afa01461e9a9b58a7abfd8b14671 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Tue, 21 Jan 2025 23:58:08 +0800 Subject: [PATCH] feat: support native element --- .../language-core/lib/codegen/globalTypes.ts | 29 ++++++++++--------- .../lib/codegen/template/element.ts | 6 ++++ .../vue3/slot-children/main.vue | 4 +++ .../vue3/slot-children/parent.vue | 3 +- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/packages/language-core/lib/codegen/globalTypes.ts b/packages/language-core/lib/codegen/globalTypes.ts index d6942dc474..13ca1198c4 100644 --- a/packages/language-core/lib/codegen/globalTypes.ts +++ b/packages/language-core/lib/codegen/globalTypes.ts @@ -57,6 +57,22 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates ? K extends { __ctx?: { props?: infer P } } ? NonNullable

: never : T extends (props: infer P, ...args: any) => any ? P : {}; + type __VLS_FunctionalGeneralComponent = (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>> = R extends any[] ? { + [K in keyof R]: R[K] extends infer V + ? V extends { __ctx?: any } ? V + : V extends import('${lib}').VNode ? E + : ReturnType<__VLS_FunctionalGeneralComponent> + : never + } : R; type __VLS_IsFunction = K extends keyof T ? __VLS_IsAny extends false ? unknown extends T[K] @@ -99,19 +115,6 @@ export function generateGlobalTypes(lib: string, target: number, strictTemplates type __VLS_PrettifyGlobal = { [K in keyof T]: T[K]; } & {}; type __VLS_UseTemplateRef = Readonly>; - type __VLS_FunctionalGeneralComponent = (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>> = R extends any[] ? { - [K in keyof R]: R[K] extends { __ctx?: any } ? R[K] : ReturnType<__VLS_FunctionalGeneralComponent> - } : R; - function __VLS_getVForSourceType(source: number): [number, number, number][]; function __VLS_getVForSourceType(source: string): [string, number, number][]; function __VLS_getVForSourceType(source: T): [ diff --git a/packages/language-core/lib/codegen/template/element.ts b/packages/language-core/lib/codegen/template/element.ts index b81507671d..d7037e9b3e 100644 --- a/packages/language-core/lib/codegen/template/element.ts +++ b/packages/language-core/lib/codegen/template/element.ts @@ -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, diff --git a/test-workspace/tsc/passedFixtures/vue3/slot-children/main.vue b/test-workspace/tsc/passedFixtures/vue3/slot-children/main.vue index ced9291a8c..f5e3309405 100644 --- a/test-workspace/tsc/passedFixtures/vue3/slot-children/main.vue +++ b/test-workspace/tsc/passedFixtures/vue3/slot-children/main.vue @@ -11,5 +11,9 @@ const foo = {} as 'a' | 'b'; + + + + diff --git a/test-workspace/tsc/passedFixtures/vue3/slot-children/parent.vue b/test-workspace/tsc/passedFixtures/vue3/slot-children/parent.vue index 5f97ffb139..7b59a13bf9 100644 --- a/test-workspace/tsc/passedFixtures/vue3/slot-children/parent.vue +++ b/test-workspace/tsc/passedFixtures/vue3/slot-children/parent.vue @@ -1,10 +1,11 @@