refactor(core): undecorated classes migration should not decorate classes if not needed (#32319)
Currently the undecorated classes migration decorates base classes if no explicit constructor is defined on all classes in the inheritance chain. We only want to decorate base classes which define a constructor that is inherited. Additionally for best practice, all classes in between the class that inherits the constructor and the one that defines it are also decorated. PR Close #32319
This commit is contained in:

committed by
Miško Hevery

parent
543631f2b3
commit
60a056d5dc
@ -209,6 +209,39 @@ describe('Undecorated classes with DI migration', () => {
|
||||
export class MyPipe extends PipeTransform {}`);
|
||||
});
|
||||
|
||||
it('should not decorate base class if no constructor is inherited', () => {
|
||||
writeFile('/index.ts', dedent `
|
||||
import {Component, NgModule, Directive} from '@angular/core';
|
||||
|
||||
export class BaseClassWithoutCtor {
|
||||
someUnrelatedProp = true;
|
||||
}
|
||||
|
||||
@Directive({selector: 'my-dir'})
|
||||
export class MyDirective extends BaseClassWithoutCtor {}
|
||||
|
||||
@Pipe()
|
||||
export class MyPipe extends BaseClassWithoutCtor {}
|
||||
|
||||
@NgModule({declarations: [MyDirective, MyPipe]})
|
||||
export class AppModule {}
|
||||
`);
|
||||
|
||||
runMigration();
|
||||
|
||||
expect(tree.readContent('/index.ts')).toContain(dedent `
|
||||
|
||||
export class BaseClassWithoutCtor {
|
||||
someUnrelatedProp = true;
|
||||
}
|
||||
|
||||
@Directive({selector: 'my-dir'})
|
||||
export class MyDirective extends BaseClassWithoutCtor {}
|
||||
|
||||
@Pipe()
|
||||
export class MyPipe extends BaseClassWithoutCtor {}`);
|
||||
});
|
||||
|
||||
it('should not decorate base class if directive/component/provider defines a constructor', () => {
|
||||
writeFile('/index.ts', dedent `
|
||||
import {Component, Injectable, NgModule, NgZone} from '@angular/core';
|
||||
|
Reference in New Issue
Block a user