fix(@angular/build): prevent IIFE wrapper interleaving for adjacent classes in minified files - #33700
Conversation
…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
015fdbe to
2101c73
Compare
There was a problem hiding this comment.
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.
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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