diff --git a/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts b/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts index 59a69395c672..95f4858fe944 100644 --- a/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts +++ b/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.test.ts @@ -268,12 +268,57 @@ describe('isStandaloneComponent', () => { expect(isStandaloneComponent(FooPipe)).toEqual(false); }); - it('should return false with Directive', () => { + it('should return true with a Directive with "standalone: true"', () => { + // TODO: `standalone` is only available in Angular v14. Remove cast to `any` once + // Angular deps are updated to v14.x.x. + @Directive({ standalone: true } as any) + class FooDirective {} + + expect(isStandaloneComponent(FooDirective)).toEqual(true); + }); + + it('should return false with a Directive with "standalone: false"', () => { + // TODO: `standalone` is only available in Angular v14. Remove cast to `any` once + // Angular deps are updated to v14.x.x. + @Directive({ standalone: false } as any) + class FooDirective {} + + expect(isStandaloneComponent(FooDirective)).toEqual(false); + }); + + it('should return false with Directive without the "standalone" property', () => { @Directive() class FooDirective {} expect(isStandaloneComponent(FooDirective)).toEqual(false); }); + + it('should return true with a Pipe with "standalone: true"', () => { + // TODO: `standalone` is only available in Angular v14. Remove cast to `any` once + // Angular deps are updated to v14.x.x. + @Pipe({ standalone: true } as any) + class FooPipe {} + + expect(isStandaloneComponent(FooPipe)).toEqual(true); + }); + + it('should return false with a Pipe with "standalone: false"', () => { + // TODO: `standalone` is only available in Angular v14. Remove cast to `any` once + // Angular deps are updated to v14.x.x. + @Pipe({ standalone: false } as any) + class FooPipe {} + + expect(isStandaloneComponent(FooPipe)).toEqual(false); + }); + + it('should return false with Pipe without the "standalone" property', () => { + @Pipe({ + name: 'fooPipe', + }) + class FooPipe {} + + expect(isStandaloneComponent(FooPipe)).toEqual(false); + }); }); describe('getComponentDecoratorMetadata', () => { diff --git a/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.ts b/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.ts index 2e5497ff8130..43219ace1f31 100644 --- a/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.ts +++ b/code/frameworks/angular/src/client/angular-beta/utils/NgComponentAnalyzer.ts @@ -116,7 +116,11 @@ export const isStandaloneComponent = (component: any): component is Type d instanceof Component && (d as any).standalone); + return (decorators || []).some( + (d) => + (d instanceof Component || d instanceof Directive || d instanceof Pipe) && + (d as any).standalone + ); }; /**