Bug: Arrow function returning object literal loses parentheses
OXC sometimes drops the parentheses around arrow functions that return object literals.
Input
useFactory: () => ({ showMenu: signal(true) })
Output
useFactory: () => { showMenu: signal(true) }
That changes the meaning of the code. The braces become a block with a label instead of an object literal, so the function returns undefined.
Expected
useFactory: () => ({ showMenu: signal(true) })
Where we see it
Angular compiled output that goes through the OXC pipeline. This ends up breaking DI factories.
Quick pattern
Looks like transforms that produce something like:
instead of
Temporary workaround
We currently patch the output before esbuild runs:
const ARROW_OBJ_REGEX = /=>\s*\{(\w+)\s*:/g;
and wrap the object.
Summary
OXC removes required parentheses for arrow functions returning object literals, which changes semantics.
Bug: Arrow function returning object literal loses parentheses
OXC sometimes drops the parentheses around arrow functions that return object literals.
Input
Output
That changes the meaning of the code. The braces become a block with a label instead of an object literal, so the function returns
undefined.Expected
Where we see it
Angular compiled output that goes through the OXC pipeline. This ends up breaking DI factories.
Quick pattern
Looks like transforms that produce something like:
instead of
Temporary workaround
We currently patch the output before esbuild runs:
and wrap the object.
Summary
OXC removes required parentheses for arrow functions returning object literals, which changes semantics.