blockNames
The let, const, class and function declarations directly in a block's statements.
import { bound } from "#codebase/tcmts/cli/npm"; import { isClassDeclaration, isFunctionDeclaration, isVariableStatement, NodeFlags } from "typescript/ast"; import type { Statement } from "typescript/ast"; export function blockNames(statements: readonly Statement[], into: Set<string>) { for (const s of statements) { if (isVariableStatement(s) && s.declarationList.flags & (NodeFlags.Let | NodeFlags.Const)) for (const d of s.declarationList.declarations) for (const b of bound(d.name)) into.add(b); if ((isClassDeclaration(s) || isFunctionDeclaration(s)) && s.name) into.add(s.name.text); } }