This avoids it being collected as dynamic children when it's not used.
fix #1021
`$slots`,
`"default"`,
`{}`,
- [
- {
- type: NodeTypes.ELEMENT,
- tag: `div`
- }
- ]
+ {
+ type: NodeTypes.JS_FUNCTION_EXPRESSION,
+ params: [],
+ returns: [
+ {
+ type: NodeTypes.ELEMENT,
+ tag: `div`
+ }
+ ]
+ }
]
})
})
`$slots`,
`"foo"`,
`{}`,
- [
- {
- type: NodeTypes.ELEMENT,
- tag: `div`
- }
- ]
+ {
+ type: NodeTypes.JS_FUNCTION_EXPRESSION,
+ params: [],
+ returns: [
+ {
+ type: NodeTypes.ELEMENT,
+ tag: `div`
+ }
+ ]
+ }
]
})
})
}
]
},
- [
- {
- type: NodeTypes.ELEMENT,
- tag: `div`
- }
- ]
+ {
+ type: NodeTypes.JS_FUNCTION_EXPRESSION,
+ params: [],
+ returns: [
+ {
+ type: NodeTypes.ELEMENT,
+ tag: `div`
+ }
+ ]
+ }
]
})
})
}
]
},
- [
- {
- type: NodeTypes.ELEMENT,
- tag: `div`
- }
- ]
+ {
+ type: NodeTypes.JS_FUNCTION_EXPRESSION,
+ params: [],
+ returns: [
+ {
+ type: NodeTypes.ELEMENT,
+ tag: `div`
+ }
+ ]
+ }
]
})
})
CallExpression,
createCallExpression,
ExpressionNode,
- SlotOutletNode
+ SlotOutletNode,
+ createFunctionExpression
} from '../ast'
import { isSlotOutlet, findProp } from '../utils'
import { buildProps, PropsExpression } from './transformElement'
if (!slotProps) {
slotArgs.push(`{}`)
}
- slotArgs.push(children)
+ slotArgs.push(createFunctionExpression([], children, false, false, loc))
}
node.codegenNode = createCallExpression(
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]
createBlock(
Fragment,
{ key: props.key },
- slot ? slot(props) : fallback || [],
+ slot ? slot(props) : fallback ? fallback() : [],
slots._ ? PatchFlags.STABLE_FRAGMENT : PatchFlags.BAIL
)
)