// THIS FILE WAS AUTO-GENERATED
// Source: lib/templates/backends/typescriptGenerator/forkBlockSetup.mustache
// Any manual changes will be lost.
import { apply } from "typestache";
export const template = `{{#isNested}}
// Capture the parent fork-block's args via closure BEFORE the inner
// block scope opens; otherwise the inner \`const __bstack = ...\` would
// put __bstack in TDZ for this entire arrow function's body.
const __parentForkArgs = __bstack.args;
{
{{/isNested}}
const __bstack = __forkBranchStack.getNewState();
const __self = __bstack.locals;
// \`__stateStack\` is read from ALS via the \`__stateStack()\` accessor.
// The branch ALS frame seeded by \`runBatch.runInBranchAlsFrame\`
// (lib/runtime/runBatch.ts) already carries \`stack: __forkBranchStack\`,
// so accessor calls inside the branch body resolve to the branch
// stack automatically — no local rebind needed. The earlier
// \`const __stateStack = __forkBranchStack\` line was removed because
// it shadowed the runtime import and made \`__stateStack()\` calls
// (emitted by interrupt/checkpoint templates) crash with
// "__stateStack2 is not a function".
const {{{paramName:string}}} = __forkItem;
{{#isNested}}
Object.assign(__bstack.args, __parentForkArgs);
{{/isNested}}
__bstack.args[{{{paramNameQuoted}}}] = __forkItem;
const runner = new Runner(__ctx, __bstack, { state: __bstack, moduleId: {{{moduleId}}}, scopeName: {{{scopeName}}} });
try {
{{{body}}}
return runner.halted ? runner.haltResult : undefined;
} finally {
__forkBranchStack.pop();
}
{{#isNested}}
}
{{/isNested}}
`;
const render = (args) => {
    return apply(template, args);
};
export default render;
