kindName

tcmts.core.canonicalize.kindName · #um7hilzi · term · runs anywhere

Stable names for syntax kinds. ts.SyntaxKind numbers shift between TypeScript releases, names don't. The enum has aliases (FirstToken, LastKeyword, ...); the first declared name for each value wins.

import { SyntaxKind as ts_SyntaxKind } from "typescript/ast";

export const kindName: string[] = (() => {
  const names: string[] = [];
  for (const [name, value] of Object.entries(ts_SyntaxKind)) {
    if (typeof value === "number" && !/^(First|Last)/.test(name) && names[value] === undefined) names[value] = name;
  }
  return names;
})()

used by