wip: exclude legacy slots from $scopedSlots

This commit is contained in:
Evan You
2021-05-05 11:06:04 -04:00
parent b14de6c3f8
commit 7f93c76b96
7 changed files with 80 additions and 28 deletions

View File

@@ -352,6 +352,11 @@ export interface FunctionExpression extends Node {
* withScopeId() wrapper
*/
isSlot: boolean
/**
* __COMPAT__ only, indicates a slot function that should be excluded from
* the legacy $scopedSlots instance property.
*/
isNonScopedSlot?: boolean
}
export interface ConditionalExpression extends Node {

View File

@@ -878,6 +878,9 @@ function genFunctionExpression(
push(`}`)
}
if (isSlot) {
if (__COMPAT__ && node.isNonScopedSlot) {
push(`, undefined, true`)
}
push(`)`)
}
}

View File

@@ -129,11 +129,6 @@ export function buildSlots(
const slotsProperties: Property[] = []
const dynamicSlots: (ConditionalExpression | CallExpression)[] = []
const buildDefaultSlotProperty = (
props: ExpressionNode | undefined,
children: TemplateChildNode[]
) => createObjectProperty(`default`, buildSlotFn(props, children, loc))
// If the slot is inside a v-for or another v-slot, force it to be dynamic
// since it likely uses a scope variable.
let hasDynamicSlots = context.scopes.vSlot > 0 || context.scopes.vFor > 0
@@ -302,6 +297,17 @@ export function buildSlots(
}
if (!onComponentSlot) {
const buildDefaultSlotProperty = (
props: ExpressionNode | undefined,
children: TemplateChildNode[]
) => {
const fn = buildSlotFn(props, children, loc)
if (__COMPAT__) {
fn.isNonScopedSlot = true
}
return createObjectProperty(`default`, fn)
}
if (!hasTemplateSlots) {
// implicit default slot (on component)
slotsProperties.push(buildDefaultSlotProperty(undefined, children))