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

More inject follow-up fixes #57389

Closed
wants to merge 2 commits into from

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
@angular-robot angular-robot bot added the area: migrations Issues related to `ng update` migrations label Aug 14, 2024
@ngbot ngbot bot added this to the Backlog milestone Aug 14, 2024
@@ -95,7 +95,7 @@ export function migrateFile(sourceFile: ts.SourceFile, options: MigrationOptions

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: merge The PR is ready for merge by the caretaker area: migrations Issues related to `ng update` 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.

None yet

4 participants