feat(core): undecorated-classes migration should handle derived abstract classes (#35339)
In version 10, undecorated base classes that use Angular features need to be decorated explicitly with `@Directive()`. Additionally, derived classes of abstract directives need to be decorated. The migration already handles this for undecorated classes that are not explicitly decorated, but since in V9, abstract directives can be used, we also need to handle this for explicitly decorated abstract directives. e.g. ``` @Directive() export class Base {...} // needs to be decorated by migration when updating from v9 to v10 export class Wrapped extends Base {} @Component(...) export class Cmp extends Wrapped {} ``` PR Close #35339
This commit is contained in:

committed by
Kara Erickson

parent
3d2db5c5f0
commit
c24ad560fa
@ -259,6 +259,39 @@ describe('Undecorated classes with decorated fields migration', () => {
|
||||
expect(fileContent).toMatch(/}\s+export class MyCompWrapped/);
|
||||
});
|
||||
|
||||
it('should add @Directive to derived undecorated classes of abstract directives', async() => {
|
||||
writeFile('/index.ts', `
|
||||
import { Input, Directive, NgModule } from '@angular/core';
|
||||
|
||||
@Directive()
|
||||
export class Base {
|
||||
// ...
|
||||
}
|
||||
|
||||
export class DerivedA extends Base {}
|
||||
export class DerivedB extends DerivedA {}
|
||||
export class DerivedC extends DerivedB {}
|
||||
|
||||
@Directive({selector: 'my-comp'})
|
||||
export class MyComp extends DerivedC {}
|
||||
|
||||
export class MyCompWrapped extends MyComp {}
|
||||
|
||||
@NgModule({declarations: [MyComp, MyCompWrapped]})
|
||||
export class AppModule {}
|
||||
`);
|
||||
|
||||
await runMigration();
|
||||
const fileContent = tree.readContent('/index.ts');
|
||||
expect(fileContent).toContain(`import { Input, Directive, NgModule } from '@angular/core';`);
|
||||
expect(fileContent).toMatch(/core';\s+@Directive\(\)\s+export class Base/);
|
||||
expect(fileContent).toMatch(/@Directive\(\)\s+export class DerivedA/);
|
||||
expect(fileContent).toMatch(/@Directive\(\)\s+export class DerivedB/);
|
||||
expect(fileContent).toMatch(/@Directive\(\)\s+export class DerivedC/);
|
||||
expect(fileContent).toMatch(/}\s+@Directive\(\{selector: 'my-comp'}\)\s+export class MyComp/);
|
||||
expect(fileContent).toMatch(/}\s+export class MyCompWrapped/);
|
||||
});
|
||||
|
||||
function writeFile(filePath: string, contents: string) {
|
||||
host.sync.write(normalize(filePath), virtualFs.stringToFileBuffer(contents));
|
||||
}
|
||||
|
Reference in New Issue
Block a user