slots

tcmts.core.canonicalize.slots · #jtmuzai4 · term · runs anywhere

A node's children as the IR labels them: slot name, and the node or list there (see slots.ts).

import { kindName } from "#codebase/tcmts/core/canonicalize";
import { SLOTS } from "#codebase/tcmts/core/slots";
import type { Node as ts_Node, NodeArray as ts_NodeArray } from "typescript/ast";

export function slots(node: ts_Node): [string, ts_Node | ts_NodeArray<ts_Node>][] {
  const out: [string, ts_Node | ts_NodeArray<ts_Node>][] = [];
  const fields = node as unknown as Record<string, ts_Node | ts_NodeArray<ts_Node> | undefined>;
  for (const slot of SLOTS[kindName[node.kind]!] ?? []) {
    const v = fields[slot];
    if (v !== undefined && v !== null) out.push([slot, v]);
  }
  return out;
}

uses

used by