testBlankImportsKeepsTheListWhole
Blanking imports leaves a list that still parses, whichever of its names go: the last few (with a trailing comma), one in the middle, all of the braces' beside a default; and nothing else moves
import { blankImports } from "#codebase/tcmts/cli/main"; import { parse } from "#codebase/tcmts/core/ts"; import assert from "node:assert/strict"; export const testBlankImportsKeepsTheListWhole = () => { const cases: [string, string[], string][] = [ ['import { A, B, isText, W, X, } from "m";', ["W", "X"], 'import { A, B, isText , } from "m";'], ['import { A, B, C } from "m";', ["B"], 'import { A, C } from "m";'], ['import { A, B, C } from "m";', ["C"], 'import { A, B } from "m";'], ['import D, { a, b } from "m";', ["a", "b"], 'import D from "m";'], ['import { a } from "m";', ["a"], ""], ]; for (const [text, names, want] of cases) { const out = blankImports("a.ts", `${text}\nconst y = 1;\n`, new Set(names)); assert.equal(out.length, text.length + "\nconst y = 1;\n".length, "nothing else moves"); assert.equal(out.split("\n")[0]!.replace(/\s+/g, " ").trim(), want, text); assert.equal(parse("a.ts", out).statements.length, want ? 2 : 1, `${out} parses`); } }