@@ -901,6 +901,37 @@ describe('inject migration', () => {
901901 ] ) ;
902902 } ) ;
903903
904+ it ( 'should remove the constructor if it only has a super() call after the migration' , async ( ) => {
905+ writeFile (
906+ '/dir.ts' ,
907+ [
908+ `import { Directive } from '@angular/core';` ,
909+ `import { Parent } from './parent';` ,
910+ `import { SomeService } from './service';` ,
911+ `` ,
912+ `@Directive()` ,
913+ `class MyDir extends Parent {` ,
914+ ` constructor(private service: SomeService) {` ,
915+ ` super();` ,
916+ ` }` ,
917+ `}` ,
918+ ] . join ( '\n' ) ,
919+ ) ;
920+
921+ await runMigration ( ) ;
922+
923+ expect ( tree . readContent ( '/dir.ts' ) . split ( '\n' ) ) . toEqual ( [
924+ `import { Directive, inject } from '@angular/core';` ,
925+ `import { Parent } from './parent';` ,
926+ `import { SomeService } from './service';` ,
927+ `` ,
928+ `@Directive()` ,
929+ `class MyDir extends Parent {` ,
930+ ` private service = inject(SomeService);` ,
931+ `}` ,
932+ ] ) ;
933+ } ) ;
934+
904935 it ( 'should be able to opt into generating backwards-compatible constructors for a class with existing members' , async ( ) => {
905936 writeFile (
906937 '/dir.ts' ,
@@ -987,6 +1018,44 @@ describe('inject migration', () => {
9871018 ] ) ;
9881019 } ) ;
9891020
1021+ it ( 'should not remove the constructor, even if it only has a super call, if backwards compatible constructors are enabled' , async ( ) => {
1022+ writeFile (
1023+ '/dir.ts' ,
1024+ [
1025+ `import { Directive } from '@angular/core';` ,
1026+ `import { Parent } from './parent';` ,
1027+ `import { SomeService } from './service';` ,
1028+ `` ,
1029+ `@Directive()` ,
1030+ `class MyDir extends Parent {` ,
1031+ ` constructor(private service: SomeService) {` ,
1032+ ` super();` ,
1033+ ` }` ,
1034+ `}` ,
1035+ ] . join ( '\n' ) ,
1036+ ) ;
1037+
1038+ await runMigration ( { backwardsCompatibleConstructors : true } ) ;
1039+
1040+ expect ( tree . readContent ( '/dir.ts' ) . split ( '\n' ) ) . toEqual ( [
1041+ `import { Directive, inject } from '@angular/core';` ,
1042+ `import { Parent } from './parent';` ,
1043+ `import { SomeService } from './service';` ,
1044+ `` ,
1045+ `@Directive()` ,
1046+ `class MyDir extends Parent {` ,
1047+ ` private service = inject(SomeService);` ,
1048+ `` ,
1049+ ` /** Inserted by Angular inject() migration for backwards compatibility */` ,
1050+ ` constructor(...args: unknown[]);` ,
1051+ `` ,
1052+ ` constructor() {` ,
1053+ ` super();` ,
1054+ ` }` ,
1055+ `}` ,
1056+ ] ) ;
1057+ } ) ;
1058+
9901059 it ( 'should not migrate abstract classes by default' , async ( ) => {
9911060 const initialContent = [
9921061 `import { Directive } from '@angular/core';` ,
0 commit comments