tracedModule
A generated module, exporting each of its definitions through the tracer (globalThis.__tcmTraceCall, the host's
wrapCall): its export { f as h_<hash> }; lines go, and at its end (after what marks each with its hash) each is
exported traced instead. Lines stay where they were, so its stack traces do too. One with no such line is as it was.
export function tracedModule(source: string): string { const exported: string[] = []; const kept = source.replace( /^export \{ ([\w$]+) as h_([a-z2-7]{52}) \};?[ \t]*$/gm, (_, local: string, hash: string) => { exported.push( `const __tcm_traced_${hash} = globalThis.__tcmTraceCall ? globalThis.__tcmTraceCall(${JSON.stringify(hash)}, ${local}) : ${local};\nexport { __tcm_traced_${hash} as h_${hash} };`, ); return ""; }, ); return exported.length ? `${kept}\n${exported.join("\n")}\n` : source; }