Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162// Debug harness: node try.mjs '<snippet>' | node try.mjs -f file.ts [chunkSize]import fs from "node:fs";const root = new URL("../..", import.meta.url).pathname.replace(/\/$/, "");import { createRequire } from "node:module";const ts = createRequire(root + "/package.json")("typescript");process.env.TYPESTRIP_ERASE_WASM ??= "build/erase.wasm";const { blankSourceFile } = await import(root + "/vendor/ts-blank-space/out/index.js");const { transformSync } = await import(root + "/src/index.js");
let src = process.argv[2];if (src === "-f") src = fs.readFileSync(process.argv[3], "utf8");const chunk = Number(process.argv[4] ?? (process.argv[2] === "-f" ? 0 : process.argv[3] ?? 0));
const sf = ts.createSourceFile("input.ts", src, ts.ScriptTarget.ESNext, false, ts.ScriptKind.TS);const wantErrors = [];const want = blankSourceFile(sf, (n) => wantErrors.push(n.getStart(sf)));const gotErrors = [];let got;try { got = transformSync(src, { onError: (e) => gotErrors.push(e.start) });} catch (e) { console.log("THREW:", e.message);}if (got !== undefined) { let i = 0; while (i < want.length && got[i] === want[i]) i++; console.log(i === want.length && got.length === want.length ? "OUTPUT MATCHES oracle byte-for-byte" : `first diff at ${i}`); if (src.length < 2000) { console.log("want:", JSON.stringify(want)); console.log("got :", JSON.stringify(got)); } else if (i < want.length) { console.log("want:", JSON.stringify(want.slice(Math.max(0, i - 60), i + 60))); console.log("got :", JSON.stringify(got.slice(Math.max(0, i - 60), i + 60))); } console.log("errors want", JSON.stringify(wantErrors), "got", JSON.stringify(gotErrors));}if (chunk > 0 || got !== undefined) { const n = chunk || 7; let out = ""; let seed = src.length; try { function* parts() { for (let i = 0; i < src.length; ) { let k = n; if (chunk === -1) { seed = (seed * 1103515245 + 12345) & 0x7fffffff; k = 1 + (seed % 4096); } yield src.slice(i, i + k); i += k; } } for (const piece of transformSync(parts())) out += piece; if (got !== undefined) { let j = 0; while (j < got.length && got[j] === out[j]) j++; console.log(out === got ? `chunked(${n}) matches whole` : `chunked(${n}) DIFFERS at ${j}: ${JSON.stringify(out.slice(Math.max(0, j - 40), j + 40))}`); } } catch (e) { const { engine } = await import(root + "/src/index.js"); const d = (i) => engine().dbg?.(i); console.log(`chunked(${n}) THREW:`, e.message, "after", JSON.stringify(out.slice(-60)), `state=${d(0)} c=${d(1)} a=${d(2)} sp=${d(3)} ts=${d(4)} tt=${d(5)} emitPos=${d(6)}`); }}