The TS emit cache removes an existing key/value before allocating the replacement. A failed allocation therefore destroys the previous cached output, and both replacement and first insertion leak intermediate key/value allocations.
Reproduced on pinned Zig 0.17 with a new public fault-injection test root: before the fix, the unchanged test run had 19/20 passes, one failed replacement assertion, and four allocator-reported leaks. In particular, failing the replacement JS dupe after the old entry is removed makes a subsequent get return null.
Acceptance:
- Allocate replacement key/value and reserve the map slot before retiring any previous value.
- Preserve old output and diagnostic metadata on all tested replacement allocation failures; leave failed first insertions empty and leak-free.
- Compile the shipped static library and run existing plus fault-injection tests on pinned Zig 0.17 and CI Zig 0.18 in Debug and ReleaseFast.
- Re-run real TS driver/Program cache consumers. Do not claim broader compiler or Bun parity.
Related: #884 (dual-toolchain source coverage), #905 (cache-key correctness), #66.