@@ -1684,6 +1684,45 @@ describe('inject migration', () => {
16841684 ] ) ;
16851685 } ) ;
16861686
1687+ it ( 'should not remove decorator imports if unmigrated classes are still using them' , async ( ) => {
1688+ writeFile (
1689+ '/dir.ts' ,
1690+ [
1691+ `import { Directive, Optional } from '@angular/core';` ,
1692+ `import { Foo } from 'foo';` ,
1693+ `import { Bar } from 'bar';` ,
1694+ `` ,
1695+ `@Directive()` ,
1696+ `class WillMigrate {` ,
1697+ ` constructor(@Optional() private foo: Foo) {}` ,
1698+ `}` ,
1699+ `` ,
1700+ `@Directive()` ,
1701+ `abstract class WillNotMigrate {` ,
1702+ ` constructor(@Optional() private bar: Bar) {}` ,
1703+ `}` ,
1704+ ] . join ( '\n' ) ,
1705+ ) ;
1706+
1707+ await runMigration ( ) ;
1708+
1709+ expect ( tree . readContent ( '/dir.ts' ) . split ( '\n' ) ) . toEqual ( [
1710+ `import { Directive, Optional, inject } from '@angular/core';` ,
1711+ `import { Foo } from 'foo';` ,
1712+ `import { Bar } from 'bar';` ,
1713+ `` ,
1714+ `@Directive()` ,
1715+ `class WillMigrate {` ,
1716+ ` private foo = inject(Foo, { optional: true });` ,
1717+ `}` ,
1718+ `` ,
1719+ `@Directive()` ,
1720+ `abstract class WillNotMigrate {` ,
1721+ ` constructor(@Optional() private bar: Bar) {}` ,
1722+ `}` ,
1723+ ] ) ;
1724+ } ) ;
1725+
16871726 describe ( 'internal-only behavior' , ( ) => {
16881727 function runInternalMigration ( ) {
16891728 return runMigration ( { _internalCombineMemberInitializers : true } ) ;
0 commit comments