export default function componentMethodsHandler()

in src/handlers/componentMethodsHandler.ts [75:133]


export default function componentMethodsHandler(
  documentation: Documentation,
  path: NodePath,
  importer: Importer,
): void {
  // Extract all methods from the class or object.
  let methodPaths: NodePath[] = [];
  if (isReactComponentClass(path, importer)) {
    methodPaths = path
      .get('body', 'body')
      .filter((body: NodePath) => isMethod(body, importer));
  } else if (t.ObjectExpression.check(path.node)) {
    methodPaths = path
      .get('properties')
      .filter((props: NodePath) => isMethod(props, importer));

    // Add the statics object properties.
    const statics = getMemberValuePath(path, 'statics', importer);
    if (statics) {
      statics.get('properties').each((p: NodePath) => {
        if (isMethod(p, importer)) {
          p.node.static = true;
          methodPaths.push(p);
        }
      });
    }
  } else if (
    t.VariableDeclarator.check(path.parent.node) &&
    path.parent.node.init === path.node &&
    t.Identifier.check(path.parent.node.id)
  ) {
    methodPaths = findAssignedMethods(
      path.parent.scope,
      path.parent.get('id'),
      importer,
    );
  } else if (
    t.AssignmentExpression.check(path.parent.node) &&
    path.parent.node.right === path.node &&
    t.Identifier.check(path.parent.node.left)
  ) {
    methodPaths = findAssignedMethods(
      path.parent.scope,
      path.parent.get('left'),
      importer,
    );
  } else if (t.FunctionDeclaration.check(path.node)) {
    methodPaths = findAssignedMethods(
      path.parent.scope,
      path.get('id'),
      importer,
    );
  }

  documentation.set(
    'methods',
    methodPaths.map(p => getMethodDocumentation(p, importer)).filter(Boolean),
  );
}