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();`, `}`, ]); });