Skip to content

fix(@angular/build): prevent syntax corruption in linker and oxc transform - #33769

Merged
alan-agius4 merged 4 commits into
angular:mainfrom
alan-agius4:fix-oxc-linker-transform-syntax
Aug 5, 2026
Merged

fix(@angular/build): prevent syntax corruption in linker and oxc transform#33769
alan-agius4 merged 4 commits into
angular:mainfrom
alan-agius4:fix-oxc-linker-transform-syntax

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

This PR fixes two sources of JavaScript syntax corruption encountered when linking and transforming Angular libraries with @angular/build:

  1. StringAstFactory: Parenthesizes object literal expression bodies in arrow functions ((params) => ({ ... })) to prevent them from being rendered as BlockStatements where property keys are treated as statement labels.
  2. oxc-transform: Preserves parentheses when unwrapping enum IIFE argument assignments (rightCallArgument.right.type === 'AssignmentExpression') so expressions like Area || (exports.Area = {}) maintain correct operator precedence.

…sform

This commit addresses two sources of JavaScript syntax corruption:

1. StringAstFactory: Parenthesize object literal expression bodies in arrow functions to prevent them from being parsed as BlockStatements where property keys are treated as statement labels.
2. oxc-transform: Preserve parentheses when unwrapping enum IIFE argument assignments so expressions like Area || (exports.Area = {}) maintain correct operator precedence.
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Aug 5, 2026
@alan-agius4
alan-agius4 requested a review from clydin August 5, 2026 10:08
gemini-code-assist[bot]

This comment was marked as outdated.

@alan-agius4

Copy link
Copy Markdown
Collaborator Author

/gemini review

gemini-code-assist[bot]

This comment was marked as outdated.

@alan-agius4

Copy link
Copy Markdown
Collaborator Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a mechanism in StringAstFactory to identify object literals using a special prefix (\0obj_) so that they can be correctly wrapped in parentheses when used as arrow function expression bodies. It also updates the corresponding tests. Additionally, the OXC transformer is updated to correctly wrap assignment expressions in parentheses when removing simple identifier assignments in arguments, with an added test case for TypeScript enums with chained exports. There are no review comments, so I have no feedback to provide.

@clydin clydin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The linker never creates arrow functions that return object literals but this doesn't have any overhead in case that changes.

Comment thread packages/angular/build/src/tools/angular/linker/oxc-linker.ts Outdated
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 5, 2026
@alan-agius4
alan-agius4 force-pushed the fix-oxc-linker-transform-syntax branch from 137b69b to deec338 Compare August 5, 2026 13:11
…nker

The OXC linker handles source maps externally via MagicString and remapping. Disabling the linker's internal sourceMapping option prevents the LinkerEnvironment from attempting to read source files through the noopFileSystem.
@alan-agius4
alan-agius4 force-pushed the fix-oxc-linker-transform-syntax branch from deec338 to 7231815 Compare August 5, 2026 13:33
@alan-agius4
alan-agius4 merged commit 7e5510e into angular:main Aug 5, 2026
15 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

@alan-agius4
alan-agius4 deleted the fix-oxc-linker-transform-syntax branch August 5, 2026 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants