substRefs

tcmts.cli.diff.substRefs · #hs6rnu6c · term · runs anywhere

import type { IR } from "#codebase/tcmts/core/hash";

export function substRefs(ir: IR, map: Map<string, string>, hit: Set<string>): IR {
  if (typeof ir === "string") return ir;
  if (ir[0] === "Ref" && ir.length === 2 && typeof ir[1] === "string" && map.has(ir[1])) {
    hit.add(ir[1]);
    return ["Ref", map.get(ir[1])!];
  }
  return ir.map((c) => substRefs(c, map, hit));
}

uses

used by