10000 feat(jsx-directive)!: use v-slots instead of vSlots by zhiyuanzmj · Pull Request #930 · vue-macros/vue-macros · GitHub
[go: up one dir, main page]

Skip to content

feat(jsx-directive)!: use v-slots instead of vSlots #930

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

Merged
merged 2 commits into from
Mar 13, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/jsx-directive/src/core/v-slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
16 changes: 8 additions & 8 deletions packages/jsx-directive/tests/__snapshots__/v-slot.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Comp: FunctionalComponent<
}
> = (props, { slots }) => {
return (
<Child vSlots={{...Object.fromEntries(__MACROS_renderList(slots, (Slot, slotName) => ([[__MACROS_unref(slotName)], (scope) => <>
<Child v-slots={{...Object.fromEntries(__MACROS_renderList(slots, (Slot, slotName) => ([[__MACROS_unref(slotName)], (scope) => <>
<Slot {...scope} />
</>,]))),}}

Expand All @@ -28,25 +28,25 @@ let baz = $ref('')
let show = $ref<boolean | undefined>()
defineRender(() => (
<div>
<Child vSlots={{'bottom': ({ foo }) => <>
<Child v-slots={{'bottom': ({ foo }) => <>
{foo}
<Child vSlots={{'default': () => <>default</>,}}></Child>
<Child v-slots={{'default': () => <>default</>,}}></Child>
</>,}}></Child>

<Comp vSlots={{'default': () => <>default</>,}}></Comp>
<Child vSlots={{'bottom': ({ foo }) => <>{foo}</>,}}></Child>
<Comp v-slots={{'default': () => <>default</>,}}></Comp>
<Child v-slots={{'bottom': ({ foo }) => <>{foo}</>,}}></Child>

<Child baz={baz} vSlots={{'title': ({ foo }) => <>
<Child baz={baz} v-slots={{'title': ({ foo }) => <>
{expectTypeOf<string>(foo)}
</>,}}></Child>

<Child vSlots={{...(show) ? {'bottom': ({ foo }) => <>
<Child v-slots={{...(show) ? {'bottom': ({ foo }) => <>
{foo}
</>,} : null,}}

></Child>

<Child<number> vSlots={{...(show) ? {'title': ({ foo }) => <>
<Child<number> v-slots={{...(show) ? {'title': ({ foo }) => <>
{expectTypeOf<number>(foo)}
{show}
</>,} : (show === false) ? {'center': ({ foo }) => <>
Expand Down
10 changes: 5 additions & 5 deletions packages/volar/src/jsx-directive/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export function resolveCtxMap(
): Map<import('typescript').Node, string> {
if (ctxNodeMap.size) {
options.codes.push(`
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false;
type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
// @ts-ignore
type __VLS_IsAny<T> = 0 extends 1 & T ? true : false; type __VLS_PickNotAny<A, B> = __VLS_IsAny<A> extends true ? B : A;
type __VLS_Element = globalThis.JSX.Element;
function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
declare function __VLS_asFunctionalComponent<T, K = T extends new (...args: any) => any ? InstanceType<T> : unknown>(t: T, instance?: K):
T extends new (...args: any) => any
? (props: (K extends { $props: infer Props } ? Props : any) & Record<string, unknown>, ctx?: any) => __VLS_Element & { __ctx?: {
attrs?: any,
Expand All @@ -35,7 +35,7 @@ const __VLS_nativeElements = {
...{} as SVGElementTagNameMap,
...{} as HTMLElementTagNameMap,
};
function __VLS_getFunctionalComponentCtx<T, K, const S>(
declare function __VLS_getFunctionalComponentCtx<T, K, const S>(
comp: T,
compInstance: K,
s: S,
Expand All @@ -46,7 +46,7 @@ function __VLS_getFunctionalComponentCtx<T, K, const S>(
? Ctx
: never
: T extends (props: infer P, ctx: infer Ctx) => any
? { props: P; slots: P['vSlots']; expose: P['vExpose'] } & Ctx
? { props: P } & Ctx
: {};\n`)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/volar/src/jsx-directive/v-slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
0