Skip to content
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

fix(compiler-core): dedupe renderSlot's default props #4557

Merged
merged 1 commit into from Sep 21, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -346,6 +346,26 @@ describe('compiler: transform <slot> outlets', () => {
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>`, () => {
Expand Down
24 changes: 11 additions & 13 deletions packages/compiler-core/src/transforms/transformSlotOutlet.ts
Expand Up @@ -20,29 +20,27 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {

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),
Expand Down