Skip to content

Commit

Permalink
Fix isStandaloneComponent check
Browse files Browse the repository at this point in the history
Pipes and directives can also be standalone
  • Loading branch information
stijnvn committed Dec 15, 2022
1 parent 970fc0d commit 7525cf7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,11 @@ export const isStandaloneComponent = (component: any): component is Type<unknown

// TODO: `standalone` is only available in Angular v14. Remove cast to `any` once
// Angular deps are updated to v14.x.x.
return (decorators || []).some((d) => d instanceof Component && (d as any).standalone);
return (decorators || []).some(
(d) =>
(d instanceof Component || d instanceof Directive || d instanceof Pipe) &&
(d as any).standalone
);
};

/**
Expand Down

0 comments on commit 7525cf7

Please sign in to comment.