Skip to content

fix(@angular/build): prevent IIFE wrapper interleaving for adjacent classes in minified files - #33700

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix/oxc-adjacent-class-iife-33699
Jul 30, 2026
Merged

fix(@angular/build): prevent IIFE wrapper interleaving for adjacent classes in minified files#33700
alan-agius4 merged 1 commit into
angular:mainfrom
alan-agius4:fix/oxc-adjacent-class-iife-33699

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

In 22.1.0, the Babel-based advancedOptimizations pass was replaced with oxc-parser + magic-string. When wrapping a class declaration in a pure IIFE, appendLeft was used for the opener and appendRight for the closer.

In minified bundles where sibling top-level class declarations are adjacent without whitespace (classA.end === classB.start), magic-string emits appendLeft content before appendRight content at a shared index. This caused class B's IIFE opener to be emitted ahead of class A's IIFE closer, interleaving the wrappers and resulting in duplicate symbol declarations in subsequent build phases.

This change swaps the insertion methods to use appendRight for the opening fragment and appendLeft for the closing fragment (and when splitting default exports), ensuring correct ordering at shared boundaries.

closes #33699

…lasses in minified files

In 22.1.0, the Babel-based advancedOptimizations pass was replaced with oxc-parser + magic-string. When wrapping a class declaration in a pure IIFE, appendLeft was used for the opener and appendRight for the closer.

In minified bundles where sibling top-level class declarations are adjacent without whitespace (classA.end === classB.start), magic-string emits appendLeft content before appendRight content at a shared index. This caused class B's IIFE opener to be emitted ahead of class A's IIFE closer, interleaving the wrappers and resulting in duplicate symbol declarations in subsequent build phases.

This change swaps the insertion methods to use appendRight for the opening fragment and appendLeft for the closing fragment (and when splitting default exports), ensuring correct ordering at shared boundaries.

closes angular#33699
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release requires: TGP This PR requires a passing TGP before merging is allowed labels Jul 30, 2026
@alan-agius4
alan-agius4 requested a review from dgp1130 July 30, 2026 12:14
@alan-agius4
alan-agius4 force-pushed the fix/oxc-adjacent-class-iife-33699 branch from 015fdbe to 2101c73 Compare July 30, 2026 12:14

@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 modifies the oxc-transform Babel plugin to prevent interleaving issues when wrapping adjacent class declarations. It swaps the usage of s.appendLeft and s.appendRight on the MagicString instance when wrapping classes in IIFEs or splitting default exports, ensuring correct output ordering. Additionally, comprehensive unit tests have been added to verify that adjacent class declarations, exported classes, and default exports are wrapped correctly without interleaving. I have no feedback to provide on these changes.

@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 Jul 30, 2026
@alan-agius4
alan-agius4 merged commit abd8ec9 into angular:main Jul 30, 2026
40 checks passed
@alan-agius4
alan-agius4 deleted the fix/oxc-adjacent-class-iife-33699 branch July 30, 2026 15:30
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

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

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 requires: TGP This PR requires a passing TGP before merging is allowed target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

advancedOptimizations emits duplicate top-level declarations for adjacent classes in minified files (regression in 22.1.0

2 participants