Skip to content

Conversation

@crisbeto
Copy link
Member

Fixes a couple more issues that came up from testing the inject migration.

fix(migrations): account for members with doc strings and no modifiers

Fixes that the migration was duplicating the doc strings of members that don't have modifiers.

fix(migrations): preserve type when using inject decorator

Updates the migration so that it passes the type as a generic in the case of @Inject(SOME_TOKEN) foo: SomeType. This is done for two reasons:

  1. It's a fairly common pattern and it ensures that the code can still be compiled.
  2. It avoids leaving behind unused imports.

Fixes that the migration was duplicating the doc strings of members that don't have modifiers.
Updates the migration so that it passes the type as a generic in the case of `@Inject(SOME_TOKEN) foo: SomeType`. This is done for two reasons:
1. It's a fairly common pattern and it ensures that the code can still be compiled.
2. It avoids leaving behind unused imports.
@crisbeto crisbeto added action: review The PR is still awaiting reviews from at least one requested reviewer target: rc This PR is targeted for the next release-candidate labels Aug 14, 2024
@crisbeto crisbeto requested a review from devversion August 14, 2024 09:24
@angular-robot angular-robot bot added the area: migrations Issues related to `ng update`/`ng generate` migrations label Aug 14, 2024
@ngbot ngbot bot added this to the Backlog milestone Aug 14, 2024
const newProperty = ts.factory.createPropertyDeclaration(
cloneModifiers(property.modifiers),
property.name,
cloneName(property.name),
Copy link
Member

Choose a reason for hiding this comment

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

Is this a symptom of not using updatePropertyDeclaration?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was using updatePropertyDeclaration earlier, but it had the same issue where it was duplicating the comments. The problem is that TS attaches the comments to the first node within the property declaration. E.g. if it has modifiers, it'll be on the first modifier, otherwise it's on the name.

Copy link
Member

Choose a reason for hiding this comment

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

I see. How will the comment be preserved if there are no modifiers, and the name is "cloned" (as a synthetic 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.

The comment gets preserved because the ChangeTracker removes between Node.getStart() and Node.getEnd() which doesn't include the comment ranges.

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. I was only seeing the getFullStart below.

@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 Aug 14, 2024
@AndrewKushnir AndrewKushnir added target: patch This PR is targeted for the next patch release and removed target: rc This PR is targeted for the next release-candidate labels Aug 14, 2024
@dylhunn
Copy link
Contributor

dylhunn commented Aug 15, 2024

This PR was merged into the repository by commit 58a79b6.

The changes were merged into the following branches: main, 18.2.x

dylhunn pushed a commit that referenced this pull request Aug 15, 2024
#57389)

Fixes that the migration was duplicating the doc strings of members that don't have modifiers.

PR Close #57389
dylhunn pushed a commit that referenced this pull request Aug 15, 2024
Updates the migration so that it passes the type as a generic in the case of `@Inject(SOME_TOKEN) foo: SomeType`. This is done for two reasons:
1. It's a fairly common pattern and it ensures that the code can still be compiled.
2. It avoids leaving behind unused imports.

PR Close #57389
@dylhunn dylhunn closed this in 4ae66f2 Aug 15, 2024
dylhunn pushed a commit that referenced this pull request Aug 15, 2024
Updates the migration so that it passes the type as a generic in the case of `@Inject(SOME_TOKEN) foo: SomeType`. This is done for two reasons:
1. It's a fairly common pattern and it ensures that the code can still be compiled.
2. It avoids leaving behind unused imports.

PR Close #57389
@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 Sep 15, 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: migrations Issues related to `ng update`/`ng generate` migrations target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants