Skip to content

OXC incorrectly removes parentheses around arrow function object literal in Angular output #43

@tomer953

Description

@tomer953

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:

=> {identifier:

instead of

=> ({identifier:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions