Skip to content

[LTS backport] fix(ngcc): support element accesses for export declarations - #44824

Closed
JoostK wants to merge 1 commit into
angular:12.2.xfrom
JoostK:ngcc/element-accesses-lts
Closed

JoostK wants to merge 1 commit into
angular:12.2.xfrom
JoostK:ngcc/element-accesses-lts

Conversation

@JoostK

@JoostK JoostK commented Jan 25, 2022

Copy link
Copy Markdown
Member

Bundlers like Rollup may use an element access expression for an export
declaration, which causes ngcc to ignore those export declarations possibly
resulting in incomplete processing of packages.

Element access syntax may be used when the declared name is not considered
as valid JS identifier, but bundlers may be conservative in determining whether
an identifier can be used (to emit a property access) and opt for a string
literal in an element access instead.

The element access syntax introduces a problem for ngcc, where it wouldn't
consider such export as class declaration, causing them to be skipped. The
ngtsc compiler is implemented with the assumption that all class declarations
use a ts.Identifier as name, whereas the element access is using a string
literal for the declared name. This makes it troublesome for ngcc to support
this syntax form in UMD bundles.

To work around the problem, this function transforms these access expressions
into regular property accesses. The source text is parsed to an AST to allow
finding the element accesses in a robust way, after which the affected text
ranges are replaced with property accesses in the original source text.

@JoostK JoostK added target: lts This PR is targeting a version currently in long-term support PullApprove: disable labels Jan 25, 2022
@JoostK JoostK changed the title fix(ngcc): support element accesses for export declarations [LTS backport] fix(ngcc): support element accesses for export declarations Jan 25, 2022
@JoostK

JoostK commented Jan 25, 2022

Copy link
Copy Markdown
Member Author

This is an LTS backport of #44669.

Bundlers like Rollup may use an element access expression for an export
declaration, which causes ngcc to ignore those export declarations possibly
resulting in incomplete processing of packages.

Element access syntax may be used when the declared name is not considered
as valid JS identifier, but bundlers may be conservative in determining whether
an identifier can be used (to emit a property access) and opt for a string
literal in an element access instead.

The element access syntax introduces a problem for ngcc, where it wouldn't
consider such export as class declaration, causing them to be skipped. The
ngtsc compiler is implemented with the assumption that all class declarations
use a `ts.Identifier` as name, whereas the element access is using a string
literal for the declared name. This makes it troublesome for ngcc to support
this syntax form in UMD bundles.

To work around the problem, this function transforms these access expressions
into regular property accesses. The source text is parsed to an AST to allow
finding the element accesses in a robust way, after which the affected text
ranges are replaced with property accesses in the original source text.

Closes angular#44037
@JoostK
JoostK force-pushed the ngcc/element-accesses-lts branch from b84ba51 to 1cfb9b5 Compare January 25, 2022 18:52
@JoostK
JoostK marked this pull request as ready for review January 25, 2022 21:30
@JoostK JoostK added action: merge The PR is ready for merge by the caretaker merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note labels Jan 25, 2022
@JoostK

JoostK commented Jan 25, 2022

Copy link
Copy Markdown
Member Author

Merge assistance: this is an LTS backport for 12.2, after discussion with @alxhub. We'd have to do an LTS release of 12 during the next batch of releases.

@AndrewKushnir

Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit 460befd.

AndrewKushnir pushed a commit that referenced this pull request Jan 25, 2022
Bundlers like Rollup may use an element access expression for an export
declaration, which causes ngcc to ignore those export declarations possibly
resulting in incomplete processing of packages.

Element access syntax may be used when the declared name is not considered
as valid JS identifier, but bundlers may be conservative in determining whether
an identifier can be used (to emit a property access) and opt for a string
literal in an element access instead.

The element access syntax introduces a problem for ngcc, where it wouldn't
consider such export as class declaration, causing them to be skipped. The
ngtsc compiler is implemented with the assumption that all class declarations
use a `ts.Identifier` as name, whereas the element access is using a string
literal for the declared name. This makes it troublesome for ngcc to support
this syntax form in UMD bundles.

To work around the problem, this function transforms these access expressions
into regular property accesses. The source text is parsed to an AST to allow
finding the element accesses in a robust way, after which the affected text
ranges are replaced with property accesses in the original source text.

Closes #44037

PR Close #44824
@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 Feb 25, 2022
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 merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note PullApprove: disable target: lts This PR is targeting a version currently in long-term support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants