Files
Colin McDonnell f101d8cada Preserve callsites in parse stack traces (#5910)
* fix(v4): preserve callsites in parse stack traces

* fix(v4): await the async parse wrappers so the callee stays on the chain

`Error.captureStackTrace(e, callee)` is skip-until-seen: V8 discards frames until it
meets `callee`, and if it never meets it, it discards them all. An async function that
returns its inner promise without awaiting has already left the async chain by the time
the rejection is built, so its frame is not there to be found and `err.stack` comes back
as the message line alone.

That made all four async codec paths return an empty stack where main returned a usable
one, which is the opposite of this branch's purpose. Instance `.parseAsync()` had the
same defect on main already; it is fixed here too, since it is the same one-word change
and the same invariant.

The existing coverage could not catch this. An async function body runs synchronously up
to its first `await`, so `z.string()` never suspends and its callee is always still on
the chain. The new test uses an async refinement and an async codec, and fails without
this fix.

* test(treeshake): re-measure the ceilings against the current base

The three raises were measured against a base five commits stale. Merging current
main puts `zod-mini-object` at exactly its ceiling and the other two at 18 bytes,
back in the 16-21 band this file's own comment records as having broken within a
day. Re-measured on the merged tree: 2808 / 3128 / 4301, so the ceilings move to
28 bytes of headroom each, which is what the comment claims.

* test(treeshake): attribute the ceiling raise to the right cause

The comment booked the whole 2813 / 3130 / 4288 raise to the callee threading. Measured
against the merge base, this branch costs +13 / +17 / +16; the remainder is drift on
main since those numbers were last set, and main alone had already reached 4285 against
its own 4288. A file whose job is recording what caused each raise should say which
part was which.
2026-08-19 14:23:58 -07:00

9 lines
501 B
JavaScript

import { build } from "esbuild";
import { gzipSync } from "node:zlib";
import path from "node:path";
for (const f of ["zod-mini-boolean", "zod-mini-string", "zod-mini-object"]) {
const r = await build({ entryPoints: [path.join("packages/treeshake", `${f}.ts`)], bundle: true, minify: true, format: "esm", write: false, logLevel: "silent" });
const n = gzipSync(Buffer.from(r.outputFiles[0].contents), { level: 9 }).length;
console.log(`${f.padEnd(20)} measured=${n} ceiling(+28)=${n + 28}`);
}