test(compiler-vapor): slot outlets with props & fallbacks (#199)

This commit is contained in:
Lulu 2024-05-09 01:03:34 +08:00 committed by 三咲智子 Kevin Deng
parent b58d6a9ea1
commit 133d494a01
No known key found for this signature in database
2 changed files with 76 additions and 0 deletions

View File

@ -22,6 +22,21 @@ export function render(_ctx) {
}"
`;
exports[`compiler: transform <slot> outlets > default slot outlet with props & fallback 1`] = `
"import { createSlot as _createSlot, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
const n0 = _createSlot("default", [
{ foo: () => (_ctx.bar) }
], () => {
const n2 = t0()
return n2
})
return n0
}"
`;
exports[`compiler: transform <slot> outlets > default slot outlet with props 1`] = `
"import { createSlot as _createSlot } from 'vue/vapor';
@ -86,6 +101,21 @@ export function render(_ctx) {
}"
`;
exports[`compiler: transform <slot> outlets > named slot outlet with props & fallback 1`] = `
"import { createSlot as _createSlot, template as _template } from 'vue/vapor';
const t0 = _template("<div></div>")
export function render(_ctx) {
const n0 = _createSlot("foo", [
{ foo: () => (_ctx.bar) }
], () => {
const n2 = t0()
return n2
})
return n0
}"
`;
exports[`compiler: transform <slot> outlets > statically named slot outlet 1`] = `
"import { createSlot as _createSlot } from 'vue/vapor';

View File

@ -210,6 +210,52 @@ describe('compiler: transform <slot> outlets', () => {
])
})
test('default slot outlet with props & fallback', () => {
const { ir, code } = compileWithSlotsOutlet(
`<slot :foo="bar"><div/></slot>`,
)
expect(code).toMatchSnapshot()
expect(ir.template[0]).toMatchObject('<div></div>')
expect(ir.block.operation).toMatchObject([
{
type: IRNodeTypes.SLOT_OUTLET_NODE,
id: 0,
name: { content: 'default' },
props: [[{ key: { content: 'foo' }, values: [{ content: 'bar' }] }]],
fallback: {
type: IRNodeTypes.BLOCK,
dynamic: {
children: [{ template: 0, id: 2 }],
},
returns: [2],
},
},
])
})
test('named slot outlet with props & fallback', () => {
const { ir, code } = compileWithSlotsOutlet(
`<slot name="foo" :foo="bar"><div/></slot>`,
)
expect(code).toMatchSnapshot()
expect(ir.template[0]).toMatchObject('<div></div>')
expect(ir.block.operation).toMatchObject([
{
type: IRNodeTypes.SLOT_OUTLET_NODE,
id: 0,
name: { content: 'foo' },
props: [[{ key: { content: 'foo' }, values: [{ content: 'bar' }] }]],
fallback: {
type: IRNodeTypes.BLOCK,
dynamic: {
children: [{ template: 0, id: 2 }],
},
returns: [2],
},
},
])
})
test('error on unexpected custom directive on <slot>', () => {
const onError = vi.fn()
const source = `<slot v-foo />`