linkedCode

tcmts.cli.files.linkedCode · #n2o2uscg · term · runs anywhere

The definition a page's @link tag in ns names: by that name, or within ns or a namespace above it.

import type { CodebaseCore } from "#codebase/tcmts/cli/codebase";

export function linkedCode(cb: CodebaseCore, ns: string, name: string): string | undefined {
  const value = (p: string) =>
    cb.store.hashesAt(p).find((h) => cb.store.getDef(h)?.kind !== "file");
  for (let n = ns; ; n = n.slice(0, Math.max(0, n.lastIndexOf(".")))) {
    const h = value(n ? `${n}.${name}` : name);
    if (h) return h;
    if (!n) return undefined;
  }
}

uses

used by