(vnode: VNode, children: unknown)
| 816 | } |
| 817 | |
| 818 | export function normalizeChildren(vnode: VNode, children: unknown): void { |
| 819 | let type = 0 |
| 820 | const { shapeFlag } = vnode |
| 821 | if (children == null) { |
| 822 | children = null |
| 823 | } else if (isArray(children)) { |
| 824 | type = ShapeFlags.ARRAY_CHILDREN |
| 825 | } else if (typeof children === 'object') { |
| 826 | if (shapeFlag & (ShapeFlags.ELEMENT | ShapeFlags.TELEPORT)) { |
| 827 | // Normalize slot to plain children for plain element and Teleport |
| 828 | const slot = (children as any).default |
| 829 | if (slot) { |
| 830 | // _c marker is added by withCtx() indicating this is a compiled slot |
| 831 | slot._c && (slot._d = false) |
| 832 | normalizeChildren(vnode, slot()) |
| 833 | slot._c && (slot._d = true) |
| 834 | } |
| 835 | return |
| 836 | } else { |
| 837 | type = ShapeFlags.SLOTS_CHILDREN |
| 838 | const slotFlag = (children as RawSlots)._ |
| 839 | if (!slotFlag && !isInternalObject(children)) { |
| 840 | // if slots are not normalized, attach context instance |
| 841 | // (compiled / normalized slots already have context) |
| 842 | ;(children as RawSlots)._ctx = currentRenderingInstance |
| 843 | } else if (slotFlag === SlotFlags.FORWARDED && currentRenderingInstance) { |
| 844 | // a child component receives forwarded slots from the parent. |
| 845 | // its slot type is determined by its parent's slot type. |
| 846 | if ( |
| 847 | (currentRenderingInstance.slots as RawSlots)._ === SlotFlags.STABLE |
| 848 | ) { |
| 849 | ;(children as RawSlots)._ = SlotFlags.STABLE |
| 850 | } else { |
| 851 | ;(children as RawSlots)._ = SlotFlags.DYNAMIC |
| 852 | vnode.patchFlag |= PatchFlags.DYNAMIC_SLOTS |
| 853 | } |
| 854 | } |
| 855 | } |
| 856 | } else if (isFunction(children)) { |
| 857 | if (shapeFlag & (ShapeFlags.ELEMENT | ShapeFlags.TELEPORT)) { |
| 858 | normalizeChildren(vnode, { default: children }) |
| 859 | return |
| 860 | } |
| 861 | children = { default: children, _ctx: currentRenderingInstance } |
| 862 | type = ShapeFlags.SLOTS_CHILDREN |
| 863 | } else { |
| 864 | children = String(children) |
| 865 | // force teleport children to array so it can be moved around |
| 866 | if (shapeFlag & ShapeFlags.TELEPORT) { |
| 867 | type = ShapeFlags.ARRAY_CHILDREN |
| 868 | children = [createTextVNode(children as string)] |
| 869 | } else { |
| 870 | type = ShapeFlags.TEXT_CHILDREN |
| 871 | } |
| 872 | } |
| 873 | vnode.children = children as VNodeNormalizedChildren |
| 874 | vnode.shapeFlag |= type |
| 875 | } |
no test coverage detected