callee: RENDER_SLOT,
arguments: [`$slots`, `"default"`, `{}`, `undefined`, `true`]
})
+ const fallback = parseWithSlots(`<slot>fallback</slot>`, {
+ slotted: false,
+ scopeId: 'foo'
+ })
+
+ const child = {
+ type: NodeTypes.JS_FUNCTION_EXPRESSION,
+ params: [],
+ returns: [
+ {
+ type: NodeTypes.TEXT,
+ content: `fallback`
+ }
+ ]
+ }
+ expect((fallback.children[0] as ElementNode).codegenNode).toMatchObject({
+ type: NodeTypes.JS_CALL_EXPRESSION,
+ callee: RENDER_SLOT,
+ arguments: [`$slots`, `"default"`, `{}`, child, `true`]
+ })
})
test(`error on unexpected custom directive on <slot>`, () => {
const slotArgs: CallExpression['arguments'] = [
context.prefixIdentifiers ? `_ctx.$slots` : `$slots`,
- slotName
+ slotName,
+ '{}',
+ 'undefined',
+ 'true'
]
+ let expectedLen = 2
if (slotProps) {
- slotArgs.push(slotProps)
+ slotArgs[2] = slotProps
+ expectedLen = 3
}
if (children.length) {
- if (!slotProps) {
- slotArgs.push(`{}`)
- }
- slotArgs.push(createFunctionExpression([], children, false, false, loc))
+ slotArgs[3] = createFunctionExpression([], children, false, false, loc)
+ expectedLen = 4
}
if (context.scopeId && !context.slotted) {
- if (!slotProps) {
- slotArgs.push(`{}`)
- }
- if (!children.length) {
- slotArgs.push(`undefined`)
- }
- slotArgs.push(`true`)
+ expectedLen = 5
}
+ slotArgs.splice(expectedLen) // remove unused arguments
node.codegenNode = createCallExpression(
context.helper(RENDER_SLOT),