Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(material/schematics): rename references in MDC generate schematic #25773

Merged
merged 1 commit into from
Oct 10, 2022

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Oct 7, 2022

Currently the ng generate migration that migrates from the legacy symbols to the non-legacy ones renames references, but only in some specific cases (e.g. imports of an NgModule). These changes expand the migration to cover any reference within the file. I've also tried to reduce the amount of migration data that we need to maintain.

@crisbeto crisbeto added P2 The issue is important to a large percentage of users, with a workaround merge safe target: major This PR is targeted for the next major release labels Oct 7, 2022
@crisbeto crisbeto requested a review from mmalerba October 7, 2022 08:10
@crisbeto crisbeto marked this pull request as ready for review October 7, 2022 08:10
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

Awesome work!!

}

if (ts.isIdentifier(node)) {
for (const [specifier, newName] of importSpecifiers.entries()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you're looking for a way to speed things up, I think you could preprocess the importSpecifiers map before passing it to _renameReferences.

Convert it to a Map<string, Map<ts.ImportSpecifier, string>> where the first key is the import specifier's propertyName/name (whichever refers to the old name). Then you don't need to check any of the ones that are obviously not it

Copy link
Member Author

@crisbeto crisbeto Oct 7, 2022

Choose a reason for hiding this comment

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

Maybe I'm misunderstanding this, but I think that this is covered by the first early exit check inside _isReferenceToImport where it exits if the import specifier doesn't match the name of the identifier.

Copy link
Contributor

Choose a reason for hiding this comment

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

The way you have it now ensures that we just have to do minimal work for each element of the map, but we still have to iterate over the entire map for every node. With the change I'm proposing we would only have to iterate over a fraction of the map at each node

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I ended up going for a simpler Map<string, ts.ImportSpecifier> instead.

@crisbeto
Copy link
Member Author

crisbeto commented Oct 7, 2022

The feedback has been addressed.

@crisbeto crisbeto force-pushed the mdc-migration-reference-rename branch from c18ab88 to b59cb27 Compare October 10, 2022 05:25
Currently the `ng generate` migration that migrates from the legacy symbols to the non-legacy ones renames references, but only in some specific cases (e.g. `imports` of an `NgModule`). These changes expand the migration to cover any reference within the file. I've also tried to reduce the amount of migration data that we need to maintain.
@crisbeto crisbeto force-pushed the mdc-migration-reference-rename branch from b59cb27 to e4b8ac9 Compare October 10, 2022 05:41
Copy link
Contributor

@mmalerba mmalerba left a comment

Choose a reason for hiding this comment

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

LGTM

@crisbeto crisbeto added the action: merge The PR is ready for merge by the caretaker label Oct 10, 2022
@crisbeto crisbeto merged commit 65086c1 into angular:main Oct 10, 2022
@angular-automatic-lock-bot
Copy link

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 Nov 10, 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 P2 The issue is important to a large percentage of users, with a workaround target: major This PR is targeted for the next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants