From 4ae66f25d01ffd603872b3df3faf5c5c555b6446 Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 14 Aug 2024 06:22:36 +0200 Subject: [PATCH] fix(migrations): account for members with doc strings and no modifiers (#57389) Fixes that the migration was duplicating the doc strings of members that don't have modifiers. PR Close #57389 --- .../ng-generate/inject-migration/migration.ts | 25 ++++++++++++++++++- .../schematics/test/inject_migration_spec.ts | 11 ++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/packages/core/schematics/ng-generate/inject-migration/migration.ts b/packages/core/schematics/ng-generate/inject-migration/migration.ts index bfb5e9e7fc2..c481bd7226b 100644 --- a/packages/core/schematics/ng-generate/inject-migration/migration.ts +++ b/packages/core/schematics/ng-generate/inject-migration/migration.ts @@ -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), property.questionToken, property.type, initializer, @@ -626,3 +626,26 @@ function cloneModifiers(modifiers: ts.ModifierLike[] | ts.NodeArray { `@Directive()`, `class MyDir {`, ` /** Value of Foo */`, - ` private value: number;`, + ` private readonly value: number;`, + ``, + ` /** ID of Foo */`, + ` id: string;`, ``, ` constructor(private foo: Foo) {`, ` this.value = this.foo.getValue();`, + ` this.id = this.foo.getId();`, ` }`, `}`, ].join('\n'), @@ -1804,7 +1808,10 @@ describe('inject migration', () => { ` private foo = inject(Foo);`, ``, ` /** Value of Foo */`, - ` private value: number = this.foo.getValue();`, + ` private readonly value: number = this.foo.getValue();`, + ``, + ` /** ID of Foo */`, + ` id: string = this.foo.getId();`, `}`, ]); });