MCPcopy Create free account
hub / github.com/reactjs/react-docgen / getNameOrValue

Function getNameOrValue

packages/react-docgen/src/utils/getNameOrValue.ts:8–30  ·  view source on GitHub ↗
(
  path: NodePath,
)

Source from the content-addressed store, hash-verified

6 * its value.
7 */
8export default function getNameOrValue(
9 path: NodePath,
10): boolean | number | string | null {
11 if (path.isIdentifier()) {
12 return path.node.name;
13 } else if (path.isQualifiedTypeIdentifier() || path.isTSQualifiedName()) {
14 return printValue(path);
15 } else if (
16 path.isStringLiteral() ||
17 path.isNumericLiteral() ||
18 path.isBooleanLiteral()
19 ) {
20 return path.node.value;
21 } else if (path.isRegExpLiteral()) {
22 return path.node.pattern;
23 } else if (path.isNullLiteral()) {
24 return null;
25 }
26
27 throw new TypeError(
28 `Argument must be Identifier, Literal, QualifiedTypeIdentifier or TSQualifiedName. Received '${path.node.type}'`,
29 );
30}

Callers 6

getPropertyNameFunction · 0.85
resolveToValueFunction · 0.85
getClassMemberValuePathFunction · 0.85
displayNameHandlerFunction · 0.85

Calls 1

printValueFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…