Skip to content

fix(@angular-devkit/build-angular): use babel default export helper in build optimizer#24692

Merged
angular-robot[bot] merged 1 commit intoangular:mainfrom
clydin:build-optimizer/default-export-splitting
Feb 10, 2023
Merged

fix(@angular-devkit/build-angular): use babel default export helper in build optimizer#24692
angular-robot[bot] merged 1 commit intoangular:mainfrom
clydin:build-optimizer/default-export-splitting

Conversation

@clydin
Copy link
Copy Markdown
Member

@clydin clydin commented Feb 9, 2023

Within the build optimizer's static member optimization pass, a class that is directly default exported must be split into two statements: the class declaration and the default export. This is because the pass can wrap classes in a pure annotated IIFE which results in a variable declaration replacement and variable declarations can not be directly default exported. Previously, the pass did this splitting manually but this was causing later babel plugins to fail. In addition to updating the AST in this case, scoping information also needed to be updated. To support this, a babel helper package is now used that handles the details of the statement split operation.

Fixes #24688

@clydin clydin added the target: patch This PR is targeted for the next patch release label Feb 9, 2023
@clydin clydin force-pushed the build-optimizer/default-export-splitting branch 2 times, most recently from fe4de58 to 7ee7a91 Compare February 9, 2023 18:32
@clydin clydin marked this pull request as ready for review February 9, 2023 19:09
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Feb 9, 2023
@clydin clydin requested a review from alan-agius4 February 9, 2023 19:11
@clydin clydin linked an issue Feb 9, 2023 that may be closed by this pull request
1 task
Copy link
Copy Markdown
Collaborator

@alan-agius4 alan-agius4 left a comment

Choose a reason for hiding this comment

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

@babel/helper-split-export-declaration should be added as a dep

…n build optimizer

Within the build optimizer's static member optimization pass, a class that is directly
default exported must be split into two statements: the class declaration and the
default export. This is because the pass can wrap classes in a pure annotated IIFE which
results in a variable declaration replacement and variable declarations can not be directly
default exported. Previously, the pass did this splitting manually but this was causing
later babel plugins to fail. In addition to updating the AST in this case, scoping information
also needed to be updated. To support this, a babel helper package is now used that handles
the details of the statement split operation.
@clydin clydin force-pushed the build-optimizer/default-export-splitting branch from 7ee7a91 to 6b90191 Compare February 10, 2023 14:52
@clydin clydin requested a review from alan-agius4 February 10, 2023 14:52
@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 Feb 10, 2023
@angular-robot angular-robot bot merged commit 8356240 into angular:main Feb 10, 2023
@clydin clydin deleted the build-optimizer/default-export-splitting branch February 10, 2023 20:16
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build failure for default exported modules

2 participants