stateless
uses tcmts.cli.kept.holdsState, which uses tcmts.cli.kept.computedInitializer, which uses tcmts.core.ts.parse, which uses tcmts.core.ts.compiler, which uses process
Whether what a constant uses holds no state something else could change before it's computed (another module
pushing to an array it reads, say): everything it uses, through what that uses, is a function, a type, or a value
nothing can change. fixed says whether a computed constant among them has a kept value that's one.
import { holdsState } from "#codebase/tcmts/cli/kept"; import type { DefSource } from "#codebase/tcmts/loader"; export function stateless( src: DefSource, hash: string, fixed: (hash: string) => boolean | undefined, ): boolean { const seen = new Set<string>([hash]); const queue = (src.get(hash)?.deps ?? []) .filter((d) => d.pos === "value" && d.ref.startsWith("#")) .map((d) => d.ref.slice(1)); while (queue.length) { const h = queue.pop()!; if (seen.has(h)) continue; seen.add(h); const rec = src.get(h); if (!rec) return false; const holds = holdsState(rec); if (holds === "state" || (holds === "maybe" && !fixed(h))) return false; for (const d of rec.deps) if (d.pos === "value" && d.ref.startsWith("#")) queue.push(d.ref.slice(1)); } return true; }