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

Function parseHookName

packages/react-debug-tools/src/ReactDebugHooks.js:960–994  ·  view source on GitHub ↗
(functionName: void | string)

Source from the content-addressed store, hash-verified

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