unusedImports
uses tcmts.core.ts.parse, which uses tcmts.core.ts.compiler, which uses process
The names a file's imports bind that nothing else in it mentions.
import { importedNames } from "#codebase/tcmts/cli/mirror"; import { parse } from "#codebase/tcmts/core/ts"; import { isIdentifier as ts_isIdentifier, isImportDeclaration as ts_isImportDeclaration } from "typescript/ast"; import type { Node as ts_Node } from "typescript/ast"; export function unusedImports(file: string, text: string): Set<string> { const sf = parse(file, text); const mentioned = new Set<string>(); const visit = (n: ts_Node) => { if (ts_isIdentifier(n)) mentioned.add(n.text); n.forEachChild(visit); }; for (const st of sf.statements) if (!ts_isImportDeclaration(st)) visit(st); return new Set(importedNames(file, text).filter((n) => !mentioned.has(n))); }