Something went wrong. Try again.
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132// Finds fixed chunk sizes for which streaming differs from the whole-input result, and locates the divergence.// Usage: node bisect.mjs file [maxChunk]import fs from "node:fs";process.env.TYPESTRIP_ERASE_WASM ??= "build/erase.wasm";const root = new URL("../..", import.meta.url).pathname.replace(/\/$/, "");const { transformSync, engine } = await import(root + "/src/index.js");const src = fs.readFileSync(process.argv[2], "utf8");const maxChunk = Number(process.argv[3] ?? 48);const whole = transformSync(src);const d = (i) => engine().dbg?.(i); // only build/downlevel-debug.wasm has the probelet found = 0;for (let n = 1; n <= maxChunk && found < 3; n++) { let out = ""; try { function* parts() { for (let i = 0; i < src.length; i += n) yield src.slice(i, i + n); } for (const piece of transformSync(parts())) out += piece; } catch (e) { found++; const bytes = Buffer.from(src, "utf8"); const tsb = d(4); console.log(`chunk ${n}: THREW ${e.message} anch=${d(9)} wm=${d(10)} flushed=${d(11)} outLen=${d(12)} aflags=${d(13)} site=${d(7)} state=${d(0)} below=${d(8)} c=${d(1)} a=${d(2)} tt=${d(5)} at byte ${tsb}: ${JSON.stringify(bytes.subarray(Math.max(0, tsb - 80), tsb).toString() + "⟨⟩" + bytes.subarray(tsb, tsb + 60).toString())}`); continue; } if (out !== whole) { found++; let j = 0; while (whole[j] === out[j]) j++; console.log(`chunk ${n}: DIFF at ${j} (boundary ${j - (j % n)}): src ${JSON.stringify(src.slice(Math.max(0, j - 60), j + 40))}\n whole ${JSON.stringify(whole.slice(Math.max(0, j - 60), j + 40))}\n chunk ${JSON.stringify(out.slice(Math.max(0, j - 60), j + 40))}`); }}if (!found) console.log("no divergence for chunk sizes 1.." + maxChunk);