bound

tcmts.cli.npm.bound · #ed7rhxpi · term · runs anywhere

The names a binding (a variable, a parameter, a destructuring pattern) declares.

import { isBindingElement, isIdentifier } from "typescript/ast";
import type { BindingName, Node } from "typescript/ast";

export function bound(name: BindingName): string[] {
  if (isIdentifier(name)) return [name.text];
  const out: string[] = [];
  for (const e of (name as unknown as { elements: readonly Node[] }).elements)
    if (isBindingElement(e) && e.name) out.push(...bound(e.name));
  return out;
}

used by