fix(compiler-core/slots): should support on-component named slots
This commit is contained in:
@@ -139,17 +139,17 @@ export function buildSlots(
|
||||
hasDynamicSlots = hasScopeRef(node, context.identifiers)
|
||||
}
|
||||
|
||||
// 1. Check for default slot with slotProps on component itself.
|
||||
// 1. Check for slot with slotProps on component itself.
|
||||
// <Comp v-slot="{ prop }"/>
|
||||
const onComponentDefaultSlot = findDir(node, 'slot', true)
|
||||
if (onComponentDefaultSlot) {
|
||||
const { arg, exp, loc } = onComponentDefaultSlot
|
||||
if (arg) {
|
||||
context.onError(
|
||||
createCompilerError(ErrorCodes.X_V_SLOT_NAMED_SLOT_ON_COMPONENT, loc)
|
||||
const onComponentSlot = findDir(node, 'slot', true)
|
||||
if (onComponentSlot) {
|
||||
const { arg, exp } = onComponentSlot
|
||||
slotsProperties.push(
|
||||
createObjectProperty(
|
||||
arg || createSimpleExpression('default', true),
|
||||
buildSlotFn(exp, children, loc)
|
||||
)
|
||||
}
|
||||
slotsProperties.push(buildDefaultSlotProperty(exp, children))
|
||||
)
|
||||
}
|
||||
|
||||
// 2. Iterate through children and check for template slots
|
||||
@@ -174,8 +174,8 @@ export function buildSlots(
|
||||
continue
|
||||
}
|
||||
|
||||
if (onComponentDefaultSlot) {
|
||||
// already has on-component default slot - this is incorrect usage.
|
||||
if (onComponentSlot) {
|
||||
// already has on-component slot - this is incorrect usage.
|
||||
context.onError(
|
||||
createCompilerError(ErrorCodes.X_V_SLOT_MIXED_SLOT_USAGE, slotDir.loc)
|
||||
)
|
||||
@@ -294,7 +294,7 @@ export function buildSlots(
|
||||
}
|
||||
}
|
||||
|
||||
if (!onComponentDefaultSlot) {
|
||||
if (!onComponentSlot) {
|
||||
if (!hasTemplateSlots) {
|
||||
// implicit default slot (on component)
|
||||
slotsProperties.push(buildDefaultSlotProperty(undefined, children))
|
||||
|
||||
Reference in New Issue
Block a user