export function compareDocumentPositionForEmptyFragment<TPublicInstance>(
fragmentFiber: Fiber,
parentHostInstance: TPublicInstance,
otherNode: TPublicInstance,
getPublicInstance: (fiber: Fiber) => TPublicInstance,
): number {
let result;
const parentResult = parentHostInstance.compareDocumentPosition(otherNode);
result = parentResult;
if (parentHostInstance === otherNode) {
result = Node.DOCUMENT_POSITION_CONTAINS;
} else {
if (parentResult & Node.DOCUMENT_POSITION_CONTAINED_BY) {
const nextSiblingFiber = getNextSiblingHostFiber(fragmentFiber);
if (nextSiblingFiber === null) {
result = Node.DOCUMENT_POSITION_PRECEDING;
} else {
const nextSiblingInstance = getPublicInstance(nextSiblingFiber);
const nextSiblingResult =
nextSiblingInstance.compareDocumentPosition(otherNode);
if (
nextSiblingResult === 0 ||
nextSiblingResult & Node.DOCUMENT_POSITION_FOLLOWING
) {
result = Node.DOCUMENT_POSITION_FOLLOWING;
} else {
result = Node.DOCUMENT_POSITION_PRECEDING;
}
}
}
}
result |= Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC;
return result;
}