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: slotOutlet fallback should include an function #1030

Merged
merged 4 commits into from
Apr 22, 2020
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
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,16 @@ describe('compiler: transform <slot> outlets', () => {
`$slots`,
`"default"`,
`{}`,
[
{
type: NodeTypes.ELEMENT,
tag: `div`
}
]
{
type: NodeTypes.JS_FUNCTION_EXPRESSION,
params: [],
returns: [
{
type: NodeTypes.ELEMENT,
tag: `div`
}
]
}
]
})
})
Expand All @@ -235,12 +239,16 @@ describe('compiler: transform <slot> outlets', () => {
`$slots`,
`"foo"`,
`{}`,
[
{
type: NodeTypes.ELEMENT,
tag: `div`
}
]
{
type: NodeTypes.JS_FUNCTION_EXPRESSION,
params: [],
returns: [
{
type: NodeTypes.ELEMENT,
tag: `div`
}
]
}
]
})
})
Expand Down Expand Up @@ -268,12 +276,16 @@ describe('compiler: transform <slot> outlets', () => {
}
]
},
[
{
type: NodeTypes.ELEMENT,
tag: `div`
}
]
{
type: NodeTypes.JS_FUNCTION_EXPRESSION,
params: [],
returns: [
{
type: NodeTypes.ELEMENT,
tag: `div`
}
]
}
]
})
})
Expand Down Expand Up @@ -301,12 +313,16 @@ describe('compiler: transform <slot> outlets', () => {
}
]
},
[
{
type: NodeTypes.ELEMENT,
tag: `div`
}
]
{
type: NodeTypes.JS_FUNCTION_EXPRESSION,
params: [],
returns: [
{
type: NodeTypes.ELEMENT,
tag: `div`
}
]
}
]
})
})
Expand Down
5 changes: 3 additions & 2 deletions packages/compiler-core/src/transforms/transformSlotOutlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import {
CallExpression,
createCallExpression,
ExpressionNode,
SlotOutletNode
SlotOutletNode,
createFunctionExpression
} from '../ast'
import { isSlotOutlet, findProp } from '../utils'
import { buildProps, PropsExpression } from './transformElement'
Expand All @@ -29,7 +30,7 @@ export const transformSlotOutlet: NodeTransform = (node, context) => {
if (!slotProps) {
slotArgs.push(`{}`)
}
slotArgs.push(children)
slotArgs.push(createFunctionExpression([], children, false, false, loc))
}

node.codegenNode = createCallExpression(
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-core/src/helpers/renderSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function renderSlot(
name: string,
props: Data = {},
// this is not a user-facing function, so the fallback is always generated by
// the compiler and guaranteed to be an array
fallback?: VNodeArrayChildren
// the compiler and guaranteed to be a function returning an array
fallback?: () => VNodeArrayChildren
): VNode {
let slot = slots[name]

Expand All @@ -34,7 +34,7 @@ export function renderSlot(
createBlock(
Fragment,
{ key: props.key },
slot ? slot(props) : fallback || [],
slot ? slot(props) : fallback ? fallback() : [],
slots._ ? PatchFlags.STABLE_FRAGMENT : PatchFlags.BAIL
)
)
Expand Down