From 5158b497cd102904b8c5cd1cdfd536e61e5cc8d4 Mon Sep 17 00:00:00 2001 From: zhiyuanzmj <260480378@qq.com> Date: Thu, 13 Mar 2025 23:31:39 +0800 Subject: [PATCH 1/2] feat(jsx-directive)!: use v-slots instead of vSlots --- packages/jsx-directive/src/core/v-slot.ts | 2 +- packages/volar/src/jsx-directive/context.ts | 10 +++++----- packages/volar/src/jsx-directive/v-slot.ts | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/jsx-directive/src/core/v-slot.ts b/packages/jsx-directive/src/core/v-slot.ts index 863867f68..5fa157db5 100644 --- a/packages/jsx-directive/src/core/v-slot.ts +++ b/packages/jsx-directive/src/core/v-slot.ts @@ -27,7 +27,7 @@ export function transformVSlot( Array.from(nodeMap) .reverse() .forEach(([node, { attributeMap, vSlotAttribute }]) => { - const result = [` vSlots={{`] + const result = [` v-slots={{`] const attributes = Array.from(attributeMap) attributes.forEach( ([attribute, { children, vIfAttribute, vForAttribute }], index) => { diff --git a/packages/volar/src/jsx-directive/context.ts b/packages/volar/src/jsx-directive/context.ts index 3c24a444d..f0e8ea428 100644 --- a/packages/volar/src/jsx-directive/context.ts +++ b/packages/volar/src/jsx-directive/context.ts @@ -18,10 +18,10 @@ export function resolveCtxMap( ): Map { if (ctxNodeMap.size) { options.codes.push(` -type __VLS_IsAny = 0 extends 1 & T ? true : false; -type __VLS_PickNotAny = __VLS_IsAny extends true ? B : A; +// @ts-ignore +type __VLS_IsAny = 0 extends 1 & T ? true : false; type __VLS_PickNotAny = __VLS_IsAny extends true ? B : A; type __VLS_Element = globalThis.JSX.Element; -function __VLS_asFunctionalComponent any ? InstanceType : unknown>(t: T, instance?: K): +declare function __VLS_asFunctionalComponent any ? InstanceType : unknown>(t: T, instance?: K): T extends new (...args: any) => any ? (props: (K extends { $props: infer Props } ? Props : any) & Record, ctx?: any) => __VLS_Element & { __ctx?: { attrs?: any, @@ -35,7 +35,7 @@ const __VLS_nativeElements = { ...{} as SVGElementTagNameMap, ...{} as HTMLElementTagNameMap, }; -function __VLS_getFunctionalComponentCtx( +declare function __VLS_getFunctionalComponentCtx( comp: T, compInstance: K, s: S, @@ -46,7 +46,7 @@ function __VLS_getFunctionalComponentCtx( ? Ctx : never : T extends (props: infer P, ctx: infer Ctx) => any - ? { props: P; slots: P['vSlots']; expose: P['vExpose'] } & Ctx + ? { props: P } & Ctx : {};\n`) } diff --git a/packages/volar/src/jsx-directive/v-slot.ts b/packages/volar/src/jsx-directive/v-slot.ts index 17df544bc..3b634d452 100644 --- a/packages/volar/src/jsx-directive/v-slot.ts +++ b/packages/volar/src/jsx-directive/v-slot.ts @@ -28,7 +28,7 @@ export function transformVSlot( const { codes, ts, ast, source, prefix } = options nodeMap.forEach(({ attributeMap, vSlotAttribute }, node) => { - const result: Code[] = [' vSlots={{'] + const result: Code[] = [' v-slots={{'] const attributes = Array.from(attributeMap) attributes.forEach( ([attribute, { children, vIfAttribute, vForAttribute }], index) => { From 3da9f3a7726e62905d2cad7b3e2a290059df07d4 Mon Sep 17 00:00:00 2001 From: zhiyuanzmj <260480378@qq.com> Date: Thu, 13 Mar 2025 23:35:59 +0800 Subject: [PATCH 2/2] fix: test --- .../tests/__snapshots__/v-slot.test.ts.snap | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/jsx-directive/tests/__snapshots__/v-slot.test.ts.snap b/packages/jsx-directive/tests/__snapshots__/v-slot.test.ts.snap index 07b649283..a957ecd6a 100644 --- a/packages/jsx-directive/tests/__snapshots__/v-slot.test.ts.snap +++ b/packages/jsx-directive/tests/__snapshots__/v-slot.test.ts.snap @@ -16,7 +16,7 @@ const Comp: FunctionalComponent< } > = (props, { slots }) => { return ( - ([[__MACROS_unref(slotName)], (scope) => <> + ([[__MACROS_unref(slotName)], (scope) => <> ,]))),}} @@ -28,25 +28,25 @@ let baz = $ref('') let show = $ref() defineRender(() => (
- <> + <> {foo} - <>default,}}> + <>default,}}> ,}}> - <>default,}}> - <>{foo},}}> + <>default,}}> + <>{foo},}}> - <> + <> {expectTypeOf(foo)} ,}}> - <> + <> {foo} ,} : null,}} > - vSlots={{...(show) ? {'title': ({ foo }) => <> + v-slots={{...(show) ? {'title': ({ foo }) => <> {expectTypeOf(foo)} {show} ,} : (show === false) ? {'center': ({ foo }) => <>