function resolveName()

in src/utils/getMemberExpressionValuePath.ts [8:52]


function resolveName(path: NodePath, importer: Importer): string | undefined {
  if (t.VariableDeclaration.check(path.node)) {
    const declarations = path.get('declarations');
    if (declarations.value.length && declarations.value.length !== 1) {
      throw new TypeError(
        'Got unsupported VariableDeclaration. VariableDeclaration must only ' +
          'have a single VariableDeclarator. Got ' +
          declarations.value.length +
          ' declarations.',
      );
    }
    const value = declarations.get(0, 'id', 'name').value;
    return value;
  }

  if (t.FunctionDeclaration.check(path.node)) {
    return path.get('id', 'name').value;
  }

  if (
    t.FunctionExpression.check(path.node) ||
    t.ArrowFunctionExpression.check(path.node) ||
    t.TaggedTemplateExpression.check(path.node) ||
    t.CallExpression.check(path.node) ||
    isReactForwardRefCall(path, importer)
  ) {
    let currentPath = path;
    while (currentPath.parent) {
      if (t.VariableDeclarator.check(currentPath.parent.node)) {
        return currentPath.parent.get('id', 'name').value;
      }

      currentPath = currentPath.parent;
    }

    return;
  }

  throw new TypeError(
    'Attempted to resolveName for an unsupported path. resolveName accepts a ' +
      'VariableDeclaration, FunctionDeclaration, FunctionExpression or CallExpression. Got "' +
      path.node.type +
      '".',
  );
}