importsAt

tcmts.cli.mirror.importsAt · #uyadcyqh · term · runs on the server

uses tcmts.core.ts.parse, which uses tcmts.core.ts.compiler, which uses process

Where new imports go: after the file's last import, or at its top.

import { parse } from "#codebase/tcmts/core/ts";
import { isImportDeclaration as ts_isImportDeclaration } from "typescript/ast";

export function importsAt(file: string, text: string): number {
  const sf = parse(file, text);
  const last = sf.statements.filter((s) => ts_isImportDeclaration(s)).at(-1);
  return last ? last.end : 0;
}

uses

used by