declKey

tcmts.core.canonicalize.declKey · #2jcup2ew · term · runs anywhere

A declaration, by file and node index: what a checker's NodeHandle and a parsed node have in common.

import type { Node as ts_Node } from "typescript/ast";
import type { NodeHandle as ts_NodeHandle } from "typescript/sync";

export const declKey = (x: ts_Node | ts_NodeHandle): string =>
  "path" in x && typeof (x as ts_NodeHandle).path === "string" && !("parent" in x) ? `${(x as ts_NodeHandle).path}#${x.index}` : `${(x as ts_Node).getSourceFile().path}#${(x as { index: number }).index}`

used by