import type { Fiber } from 'react-reconciler' ; import { findChildFiberAt , findPreviousFiber } from './findFiber' ; param parent param child param index returns export function addChildFiberAt ( parent , child , index ) { if ( index === - 1 ) return appendChildFiber ( parent , child ) ; if ( index === 0 ) return prependChildFiber ( parent , child ) ; const previousSibling = findChildFiberAt ( parent , index - 1 ) ; if ( previousSibling === null ) { return prependChildFiber ( parent , child ) ; } return addSiblingFiber ( previousSibling , child ) ; } param parent param child param key returns export function addChildFiberBefore ( parent , child , key ) { const previousFiber = findPreviousFiber ( parent , key ) ; if ( previousFiber === null ) { return appendChildFiber ( parent , child ) ; } if ( previousFiber === parent ) { return prependChildFiber ( parent , child ) ; } return addSiblingFiber ( previousFiber , child ) ; } param parent param child returns export function appendChildFiber ( parent , child ) { const previousFiber = findChildFiberAt ( parent , - 1 ) ; if ( previousFiber === null ) { return prependChildFiber ( parent , child ) ; } return addSiblingFiber ( previousFiber , child ) ; } param fiber param sibling returns export function addSiblingFiber ( fiber , sibling ) { const oldSibling = fiber . sibling ; const index = fiber . index + 1 ; fiber . sibling = sibling ; sibling . return = fiber . return ; sibling . sibling = oldSibling ; return index ; } param parent param child returns export function prependChildFiber ( parent , child ) { const oldFirstChild = parent . child ; parent . child = child ; child . sibling = oldFirstChild ; child . return = parent ; return 0 ; }