Skip to content

fix(compiler-cli): identify aliased initializer functions - #54480

Closed
crisbeto wants to merge 4 commits into
angular:mainfrom
crisbeto:aliased-init-fn
Closed

crisbeto wants to merge 4 commits into
angular:mainfrom
crisbeto:aliased-init-fn

Conversation

@crisbeto

@crisbeto crisbeto commented Feb 16, 2024 •

Copy link
Copy Markdown
Member

Fixes that initializer functions weren't being recognized if they are aliased (e.g. import {model as alias} from '@angular/core';).

To do this efficiently, I had to introduce the ImportedSymbolsTracker which scans the top-level imports of a file and allows them to be checked quickly, without having to go through the type checker. It will also be useful in the future when verifying that that initializer APIs aren't used in unexpected places.

I've also introduced tests specifically for the tryParseInitializerApiMember function so that we can test it in isolation instead of going through the various functions that call into it.

@crisbeto crisbeto 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 area: compiler Issues related to `ngc`, Angular's template compiler labels Feb 16, 2024
@ngbot ngbot Bot added this to the Backlog milestone Feb 16, 2024

@crisbeto crisbeto Feb 16, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In the future I think we'll also need methods like hasImportsFor(symbol, moduleName) and hasNamespaceImportFor(moduleName) which will allow us to skip traversing the entire file even earlier. I skipped them for now since we don't need them yet, but all the information is already there.

@crisbeto
crisbeto force-pushed the aliased-init-fn branch 3 times, most recently from 0911967 to 1132572 Compare February 16, 2024 12:37
@crisbeto
crisbeto requested a review from devversion February 16, 2024 12:57
@crisbeto
crisbeto marked this pull request as ready for review February 16, 2024 12:57

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At this point we have so many trackers 😄 local compilation, deferred etc

Fixes that initializer functions weren't being recognized if they are aliased (e.g. `import {model as alias} from '@angular/core';`).

To do this efficiently, I had to introduce the `ImportedSymbolsTracker` which scans the top-level imports of a file and allows them to be checked quickly, without having to go through the type checker. It will be useful in the future when verifying that that initializer APIs aren't used in unexpected places.

I've also introduced tests specifically for the `tryParseInitializerApiMember` function so that we can test it in isolation instead of going through the various functions that call into it.
@crisbeto crisbeto 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 22, 2024
@dylhunn

dylhunn commented Feb 23, 2024

Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit f04ecc0.

@dylhunn dylhunn closed this in f04ecc0 Feb 23, 2024
dylhunn pushed a commit that referenced this pull request Feb 23, 2024
Fixes that initializer functions weren't being recognized if they are aliased (e.g. `import {model as alias} from '@angular/core';`).

To do this efficiently, I had to introduce the `ImportedSymbolsTracker` which scans the top-level imports of a file and allows them to be checked quickly, without having to go through the type checker. It will be useful in the future when verifying that that initializer APIs aren't used in unexpected places.

I've also introduced tests specifically for the `tryParseInitializerApiMember` function so that we can test it in isolation instead of going through the various functions that call into it.

PR Close #54480
@dylhunn dylhunn mentioned this pull request Feb 23, 2024
dylhunn added a commit to dylhunn/angular that referenced this pull request Feb 23, 2024
@dylhunn

dylhunn commented Feb 23, 2024 •

Copy link
Copy Markdown
Contributor

Rolled back due to breakage in g3. In summary, namedImports is an object, making it unsafe with the following key names:

constructor
hasOwnProperty
isPrototypeOf
propertyIsEnumerable
toLocaleString
toString
valueOf
__defineGetter__
__defineSetter__
__lookupGetter__
__lookupSetter__
__proto__

dylhunn added a commit that referenced this pull request Feb 26, 2024
dylhunn added a commit that referenced this pull request Feb 26, 2024
@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 25, 2024
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 area: compiler Issues related to `ngc`, Angular's template compiler target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants