function name_from_ast()

in src/consumers/name_from_ast.hack [15:37]


function name_from_ast(HHAST\Node $node): string {
  if ($node is HHAST\Token) {
    return $node->getText();
  }
  if ($node is HHAST\QualifiedName) {
    // Join with `\` as the `\` is an item separator, not an actual item in the
    // lists.
    //
    // If there's a leading `\` in the name, the first item is empty.
    return $node->getParts()->getChildrenOfItems()
      |> Vec\map($$, $x ==> $x?->getText() ?? '')
      |> Str\join($$, '\\');
  }

  if ($node is HHAST\SimpleTypeSpecifier) {
    return name_from_ast($node->getSpecifier());
  }

  invariant_violation(
    'Expected Token or QualifiedName, got %s',
    \get_class($node),
  );
}