MCPcopy
hub / github.com/facebook/react / parseTrimmedStack

Function parseTrimmedStack

packages/react-debug-tools/src/ReactDebugHooks.js:936–958  ·  view source on GitHub ↗
(rootStack: ParsedStackFrame[], hook: HookLogEntry)

Source from the content-addressed store, hash-verified

934}
935
936function parseTrimmedStack(rootStack: ParsedStackFrame[], hook: HookLogEntry) {
937 // Get the stack trace between the primitive hook function and
938 // the root function call. I.e. the stack frames of custom hooks.
939 const hookStack = ErrorStackParser.parse(hook.stackError);
940 const rootIndex = findCommonAncestorIndex(rootStack, hookStack);
941 const primitiveIndex = findPrimitiveIndex(hookStack, hook);
942 if (
943 rootIndex === -1 ||
944 primitiveIndex === -1 ||
945 rootIndex - primitiveIndex < 2
946 ) {
947 if (primitiveIndex === -1) {
948 // Something went wrong. Give up.
949 return [null, null];
950 } else {
951 return [hookStack[primitiveIndex - 1], null];
952 }
953 }
954 return [
955 hookStack[primitiveIndex - 1],
956 hookStack.slice(primitiveIndex, rootIndex - 1),
957 ];
958}
959
960function parseHookName(functionName: void | string): string {
961 if (!functionName) {

Callers 1

buildTreeFunction · 0.85

Calls 2

findCommonAncestorIndexFunction · 0.85
findPrimitiveIndexFunction · 0.85

Tested by

no test coverage detected