diff --git a/packages/compiler/src/client-codegen.ts b/packages/compiler/src/client-codegen.ts index c015b529..a3094fba 100644 --- a/packages/compiler/src/client-codegen.ts +++ b/packages/compiler/src/client-codegen.ts @@ -270,8 +270,8 @@ function functionEntry( .join("\n"); const commitBinding = stateNames.length ? `const __wrnexusCommit = () => { ${copyBack} }; - ${!parameterNames.has("commit") && !declaredLocals.has("commit") ? "const commit = __wrnexusCommit;" : ""} - ${!parameterNames.has("setTimeout") && !declaredLocals.has("setTimeout") ? `const setTimeout = (callback, delay, ...args) => globalThis.setTimeout(() => { + ${!parameterNames.has("commit") && !declaredLocals.has("commit") && !functionAliases.includes("commit") ? "const commit = __wrnexusCommit;" : ""} + ${!parameterNames.has("setTimeout") && !declaredLocals.has("setTimeout") && !functionAliases.includes("setTimeout") ? `const setTimeout = (callback, delay, ...args) => globalThis.setTimeout(() => { try { return callback(...args); } finally { __wrnexusCommit(); } }, delay);` : ""}` : ""; diff --git a/packages/compiler/test/v060-targets.test.ts b/packages/compiler/test/v060-targets.test.ts index 37b2530e..18749762 100644 --- a/packages/compiler/test/v060-targets.test.ts +++ b/packages/compiler/test/v060-targets.test.ts @@ -184,3 +184,19 @@ test("deferred timer state writes commit after the client function returns", asy expect(state.value).toBe(2); expect(rendered).toBe("2"); }); + +test("the deferred commit helper does not shadow an authored commit function", () => { + const targets = generateTargets( + parse(`component AuthoredCommit { + state { value: number = 0 } + functions { + client function commit(): void { value = 1 } + client function save(): void { commit() } + } + view { } + }`), + ); + + expect(() => new Function(targets.browser.replace(/^export\s+/gm, ""))).not.toThrow(); + expect(targets.browser).not.toContain("const commit = __wrnexusCommit"); +});