fix(@angular/build): prevent syntax corruption in linker and oxc transform - #33769
Conversation
…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.
|
/gemini review |
…tion in StringAstFactory
|
/gemini review |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
The linker never creates arrow functions that return object literals but this doesn't have any overhead in case that changes.
137b69b to
deec338
Compare
…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.
deec338 to
7231815
Compare
|
This PR was merged into the repository. The changes were merged into the following branches:
|
This PR fixes two sources of JavaScript syntax corruption encountered when linking and transforming Angular libraries with
@angular/build:StringAstFactory: Parenthesizes object literal expression bodies in arrow functions ((params) => ({ ... })) to prevent them from being rendered asBlockStatements where property keys are treated as statement labels.oxc-transform: Preserves parentheses when unwrapping enum IIFE argument assignments (rightCallArgument.right.type === 'AssignmentExpression') so expressions likeArea || (exports.Area = {})maintain correct operator precedence.