import { describe, expect, it } from "vitest"; import { chunkUnits, loadTypeScript, splitSourceUnits } from "./jev-find-source.ts"; describe("TS7 source parser", () => { it("keeps UTF-16 names and CRLF line positions", async () => { const parser = await loadTypeScript(); expect(parser).toBeDefined(); const text = '// 😀 header\r\nexport const café = "😀";\r\n\r\nexport function retry() { return café; }\r\n'; expect(splitSourceUnits("sample.ts", text, parser)).toEqual([ { name: "café", start: 1, end: 2 }, { name: "retry", start: 4, end: 4 }, ]); }); it("parses TSX from the supplied text without needing a physical file", async () => { const parser = await loadTypeScript(); const text = "export function View() { return
ready
; }\n"; expect(splitSourceUnits("not-on-disk.tsx", text, parser)).toEqual([{ name: "View", start: 1, end: 1 }]); }); it("retains deterministic chunks if the optional native parser fails", () => { const text = "const x = 1;\n\nconst y = 2;\n"; expect(splitSourceUnits("sample.ts", text, { sourceUnits() { throw new Error("parser unavailable"); } })).toEqual(chunkUnits(text)); expect(splitSourceUnits("sample.ts", text, undefined)).toEqual(chunkUnits(text)); }); });