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

Function parseHookName

packages/react-debug-tools/src/ReactDebugHooks.js:960–994  ·  packages/react-debug-tools/src/ReactDebugHooks.js::parseHookName
(functionName: void | string)

Source from the content-addressed store, hash-verified

958}
959
960function parseHookName(functionName: void | string): string {
961 if (!functionName) {
962 return class="st">'';
963 }
964 let startIndex = functionName.lastIndexOf(class="st">'[as ');
965
966 if (startIndex !== -1) {
967 class="cm">// Workaround for sourcemaps in Jest and Chrome.
968 class="cm">// In `node --enable-source-maps`, we don't see class="st">"Object.useHostTransitionStatus [as useFormStatus]" but class="st">"Object.useFormStatus"
969 class="cm">// class="st">"Object.useHostTransitionStatus [as useFormStatus]" -> class="st">"useFormStatus"
970 return parseHookName(functionName.slice(startIndex + class="st">'[as '.length, -1));
971 }
972 startIndex = functionName.lastIndexOf(class="st">'.');
973 if (startIndex === -1) {
974 startIndex = 0;
975 } else {
976 startIndex += 1;
977 }
978
979 if (functionName.slice(startIndex).startsWith(class="st">'unstable_')) {
980 startIndex += class="st">'unstable_'.length;
981 }
982
983 if (functionName.slice(startIndex).startsWith(class="st">'experimental_')) {
984 startIndex += class="st">'experimental_'.length;
985 }
986
987 if (functionName.slice(startIndex, startIndex + 3) === class="st">'use') {
988 if (functionName.length - startIndex === 3) {
989 return class="st">'Use';
990 }
991 startIndex += 3;
992 }
993 return functionName.slice(startIndex);
994}
995
996function buildTree(
997 rootStack: ParsedStackFrame[],

Callers 2

isReactWrapperFunction · 0.85
buildTreeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected