Home / Function/ getFunctionName() — react Function Reference

getFunctionName() — react Function Reference

Architecture documentation for the getFunctionName() function in babel-plugin-annotate-react-code.ts from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  c0984882_814d_5695_4f67_3f3356e0f3eb["getFunctionName()"]
  90fd4a4d_9742_70a7_9512_f9dd5b565200["babel-plugin-annotate-react-code.ts"]
  c0984882_814d_5695_4f67_3f3356e0f3eb -->|defined in| 90fd4a4d_9742_70a7_9512_f9dd5b565200
  40539f87_cad8_e5ab_baf5_c8916ae353cf["isComponentOrHookLike()"]
  40539f87_cad8_e5ab_baf5_c8916ae353cf -->|calls| c0984882_814d_5695_4f67_3f3356e0f3eb
  style c0984882_814d_5695_4f67_3f3356e0f3eb fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

compiler/packages/babel-plugin-react-compiler/scripts/babel-plugin-annotate-react-code.ts lines 239–293

function getFunctionName(
  path: NodePath<
    t.FunctionDeclaration | t.ArrowFunctionExpression | t.FunctionExpression
  >,
): NodePath<t.Expression> | null {
  if (path.isFunctionDeclaration()) {
    const id = path.get('id');
    if (id.isIdentifier()) {
      return id;
    }
    return null;
  }
  let id: NodePath<t.LVal | t.Expression | t.PrivateName> | null = null;
  const parent = path.parentPath;
  if (parent.isVariableDeclarator() && parent.get('init').node === path.node) {
    // const useHook = () => {};
    id = parent.get('id');
  } else if (
    parent.isAssignmentExpression() &&
    parent.get('right').node === path.node &&
    parent.get('operator') === '='
  ) {
    // useHook = () => {};
    id = parent.get('left');
  } else if (
    parent.isProperty() &&
    parent.get('value').node === path.node &&
    !parent.get('computed') &&
    parent.get('key').isLVal()
  ) {
    /*
     * {useHook: () => {}}
     * {useHook() {}}
     */
    id = parent.get('key');
  } else if (
    parent.isAssignmentPattern() &&
    parent.get('right').node === path.node &&
    !parent.get('computed')
  ) {
    /*
     * const {useHook = () => {}} = {};
     * ({useHook = () => {}} = {});
     *
     * Kinda clowny, but we'd said we'd follow spec convention for
     * `IsAnonymousFunctionDefinition()` usage.
     */
    id = parent.get('left');
  }
  if (id !== null && (id.isIdentifier() || id.isMemberExpression())) {
    return id;
  } else {
    return null;
  }
}

Subdomains

Frequently Asked Questions

What does getFunctionName() do?
getFunctionName() is a function in the react codebase, defined in compiler/packages/babel-plugin-react-compiler/scripts/babel-plugin-annotate-react-code.ts.
Where is getFunctionName() defined?
getFunctionName() is defined in compiler/packages/babel-plugin-react-compiler/scripts/babel-plugin-annotate-react-code.ts at line 239.
What calls getFunctionName()?
getFunctionName() is called by 1 function(s): isComponentOrHookLike.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free