MCPcopy
hub / github.com/vuejs/core / convertLegacySlots

Function convertLegacySlots

packages/runtime-core/src/compat/renderFn.ts:263–306  ·  view source on GitHub ↗
(vnode: VNode)

Source from the content-addressed store, hash-verified

261}
262
263function convertLegacySlots(vnode: VNode): VNode {
264 const { props, children } = vnode
265
266 let slots: Record<string, any> | undefined
267
268 if (vnode.shapeFlag & ShapeFlags.COMPONENT && isArray(children)) {
269 slots = {}
270 // check "slot" property on vnodes and turn them into v3 function slots
271 for (let i = 0; i < children.length; i++) {
272 const child = children[i]
273 const slotName =
274 (isVNode(child) && child.props && child.props.slot) || 'default'
275 const slot = slots[slotName] || (slots[slotName] = [] as any[])
276 if (isVNode(child) && child.type === 'template') {
277 slot.push(child.children)
278 } else {
279 slot.push(child)
280 }
281 }
282 if (slots) {
283 for (const key in slots) {
284 const slotChildren = slots[key]
285 slots[key] = () => slotChildren
286 slots[key]._ns = true /* non-scoped slot */
287 }
288 }
289 }
290
291 const scopedSlots = props && props.scopedSlots
292 if (scopedSlots) {
293 delete props!.scopedSlots
294 if (slots) {
295 extend(slots, scopedSlots)
296 } else {
297 slots = scopedSlots
298 }
299 }
300
301 if (slots) {
302 normalizeChildren(vnode, slots)
303 }
304
305 return vnode
306}
307
308export function defineLegacyVNodeProperties(vnode: VNode): void {
309 /* v8 ignore start */

Callers 1

compatHFunction · 0.85

Calls 3

isVNodeFunction · 0.90
normalizeChildrenFunction · 0.90
pushMethod · 0.65

Tested by

no test coverage detected