{"version":3,"sources":["../src/findCurrentFiberUsingSlowPath.js"],"names":["findCurrentFiberUsingSlowPath","fiber","alternate","a","b","parentA","parentB","child","sibling","Error","didFindChild","stateNode","current","module","exports"],"mappings":";;AAAA;AACA,SAASA,6BAAT,CAAuCC,KAAvC,EAA8C;AAAA,MACpCC,SADoC,GACtBD,KADsB,CACpCC,SADoC;;AAE5C,MAAI,CAACA,SAAL,EAAgB;AACd,WAAOD,KAAP;AACD;AACD;AACA;AACA;AACA,MAAIE,IAAIF,KAAR;AACA,MAAIG,IAAIF,SAAR;AACA,SAAO,IAAP,EAAa;AAAE;AACb,QAAMG,UAAUF,WAAhB;AACA,QAAMG,UAAUD,UAAUA,QAAQH,SAAlB,GAA8B,IAA9C;AACA,QAAI,CAACG,OAAD,IAAY,CAACC,OAAjB,EAA0B;AACxB;AACA;AACD;;AAED;AACA;AACA;AACA,QAAID,QAAQE,KAAR,KAAkBD,QAAQC,KAA9B,EAAqC;AAAA,UAC7BA,KAD6B,GACnBF,OADmB,CAC7BE,KAD6B;;AAEnC,aAAOA,KAAP,EAAc;AACZ,YAAIA,UAAUJ,CAAd,EAAiB;AACf;AACA,iBAAOF,KAAP;AACD;AACD,YAAIM,UAAUH,CAAd,EAAiB;AACf;AACA,iBAAOF,SAAP;AACD;AACDK,gBAAQA,MAAMC,OAAd;AACD;AACD;AACA;AACA,YAAM,IAAIC,KAAJ,CAAU,gDAAV,CAAN;AACD;;AAED,QAAIN,gBAAaC,WAAjB,EAA2B;AACzB;AACA;AACA;AACA;AACAD,UAAIE,OAAJ;AACAD,UAAIE,OAAJ;AACD,KAPD,MAOO;AACL;AACA;AACA;AACA;AACA;AACA,UAAII,eAAe,KAAnB;AANK,UAOCH,MAPD,GAOWF,OAPX,CAOCE,KAPD;;AAQL,aAAOA,MAAP,EAAc;AACZ,YAAIA,WAAUJ,CAAd,EAAiB;AACfO,yBAAe,IAAf;AACAP,cAAIE,OAAJ;AACAD,cAAIE,OAAJ;AACA;AACD;AACD,YAAIC,WAAUH,CAAd,EAAiB;AACfM,yBAAe,IAAf;AACAN,cAAIC,OAAJ;AACAF,cAAIG,OAAJ;AACA;AACD;AACDC,iBAAQA,OAAMC,OAAd;AACD;AACD,UAAI,CAACE,YAAL,EAAmB;AAEdH,cAFc,GAEJD,OAFI,CAEdC,KAFc;AACjB;;AAEA,eAAOA,MAAP,EAAc;AACZ,cAAIA,WAAUJ,CAAd,EAAiB;AACfO,2BAAe,IAAf;AACAP,gBAAIG,OAAJ;AACAF,gBAAIC,OAAJ;AACA;AACD;AACD,cAAIE,WAAUH,CAAd,EAAiB;AACfM,2BAAe,IAAf;AACAN,gBAAIE,OAAJ;AACAH,gBAAIE,OAAJ;AACA;AACD;AACDE,mBAAQA,OAAMC,OAAd;AACD;AACD,YAAI,CAACE,YAAL,EAAmB;AACjB,gBAAM,IAAID,KAAJ,CAAU,oEACZ,+DADE,CAAN;AAED;AACF;AACF;AACF;AACD,MAAIN,EAAEQ,SAAF,CAAYC,OAAZ,KAAwBT,CAA5B,EAA+B;AAC7B;AACA,WAAOF,KAAP;AACD;AACD;AACA,SAAOC,SAAP;AACD;;AAEDW,OAAOC,OAAP,GAAiBd,6BAAjB","file":"findCurrentFiberUsingSlowPath.js","sourcesContent":["// Extracted from https://github.com/facebook/react/blob/7bdf93b17a35a5d8fcf0ceae0bf48ed5e6b16688/src/renderers/shared/fiber/ReactFiberTreeReflection.js#L104-L228\nfunction findCurrentFiberUsingSlowPath(fiber) {\n const { alternate } = fiber;\n if (!alternate) {\n return fiber;\n }\n // If we have two possible branches, we'll walk backwards up to the root\n // to see what path the root points to. On the way we may hit one of the\n // special cases and we'll deal with them.\n let a = fiber;\n let b = alternate;\n while (true) { // eslint-disable-line\n const parentA = a.return;\n const parentB = parentA ? parentA.alternate : null;\n if (!parentA || !parentB) {\n // We're at the root.\n break;\n }\n\n // If both copies of the parent fiber point to the same child, we can\n // assume that the child is current. This happens when we bailout on low\n // priority: the bailed out fiber's child reuses the current child.\n if (parentA.child === parentB.child) {\n let { child } = parentA;\n while (child) {\n if (child === a) {\n // We've determined that A is the current branch.\n return fiber;\n }\n if (child === b) {\n // We've determined that B is the current branch.\n return alternate;\n }\n child = child.sibling;\n }\n // We should never have an alternate for any mounting node. So the only\n // way this could possibly happen is if this was unmounted, if at all.\n throw new Error('Unable to find node on an unmounted component.');\n }\n\n if (a.return !== b.return) {\n // The return pointer of A and the return pointer of B point to different\n // fibers. We assume that return pointers never criss-cross, so A must\n // belong to the child set of A.return, and B must belong to the child\n // set of B.return.\n a = parentA;\n b = parentB;\n } else {\n // The return pointers point to the same fiber. We'll have to use the\n // default, slow path: scan the child sets of each parent alternate to see\n // which child belongs to which set.\n //\n // Search parent A's child set\n let didFindChild = false;\n let { child } = parentA;\n while (child) {\n if (child === a) {\n didFindChild = true;\n a = parentA;\n b = parentB;\n break;\n }\n if (child === b) {\n didFindChild = true;\n b = parentA;\n a = parentB;\n break;\n }\n child = child.sibling;\n }\n if (!didFindChild) {\n // Search parent B's child set\n ({ child } = parentB);\n while (child) {\n if (child === a) {\n didFindChild = true;\n a = parentB;\n b = parentA;\n break;\n }\n if (child === b) {\n didFindChild = true;\n b = parentB;\n a = parentA;\n break;\n }\n child = child.sibling;\n }\n if (!didFindChild) {\n throw new Error('Child was not found in either parent set. This indicates a bug '\n + 'in React related to the return pointer. Please file an issue.');\n }\n }\n }\n }\n if (a.stateNode.current === a) {\n // We've determined that A is the current branch.\n return fiber;\n }\n // Otherwise B has to be current branch.\n return alternate;\n}\n\nmodule.exports = findCurrentFiberUsingSlowPath;\n"]}