function returnsJSXElementOrReactCall()

in src/utils/isStatelessComponent.ts [145:191]


function returnsJSXElementOrReactCall(
  path: NodePath,
  importer: Importer,
  seen: WeakSet<NodePath> = new WeakSet(),
): boolean {
  let visited = false;

  // early exit for ArrowFunctionExpressions
  if (
    path.node.type === 'ArrowFunctionExpression' &&
    path.get('body').node.type !== 'BlockStatement' &&
    resolvesToJSXElementOrReactCall(path.get('body'), importer, seen)
  ) {
    return true;
  }

  let scope = path.scope;
  // If we get a property we want the function scope it holds and not its outer scope
  if (path.node.type === 'Property') {
    scope = path.get('value').scope;
  }

  // @ts-ignore
  visit(path, {
    visitReturnStatement(returnPath): boolean | null | undefined {
      // Only check return statements which are part of the checked function scope
      if (returnPath.scope !== scope) return false;

      if (
        resolvesToJSXElementOrReactCall(
          returnPath.get('argument'),
          importer,
          seen,
        )
      ) {
        visited = true;
        return false;
      }

      this.traverse(returnPath);

      return;
    },
  });

  return visited;
}