Skip to content

Commit

Permalink
fixup! feat(angular): use ɵReflectionCapabilities to find component &…
Browse files Browse the repository at this point in the history
… module metadata
  • Loading branch information
ThibaudAV committed Jan 7, 2022
1 parent f5b884b commit 1af9353
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Expand Up @@ -237,10 +237,27 @@ describe('isComponent', () => {

describe('getComponentDecoratorMetadata', () => {
it('should return Component with a Component', () => {
@Component({})
@Component({ selector: 'foo' })
class FooComponent {}

expect(getComponentDecoratorMetadata(FooComponent)).toBeInstanceOf(Component);
expect(getComponentDecoratorMetadata(FooComponent)).toEqual({
changeDetection: 1,
selector: 'foo',
});
});

it('should return Component with a Component', () => {
@Component({ selector: 'bar' })
class BarComponent {}
@Component({ selector: 'foo' })
class FooComponent extends BarComponent {}

expect(getComponentDecoratorMetadata(FooComponent)).toBeInstanceOf(Component);
expect(getComponentDecoratorMetadata(FooComponent)).toEqual({
changeDetection: 1,
selector: 'foo',
});
});
});

Expand Down
Expand Up @@ -6,6 +6,7 @@ import {
Pipe,
Type,
ɵReflectionCapabilities as ReflectionCapabilities,
ɵCodegenComponentFactoryResolver,
} from '@angular/core';

const reflectionCapabilities = new ReflectionCapabilities();
Expand Down Expand Up @@ -119,6 +120,7 @@ export const getComponentPropsDecoratorMetadata = (component: any) => {
* Returns component decorator `@Component`
*/
export const getComponentDecoratorMetadata = (component: any): Component | undefined => {
const decorators: any[] = reflectionCapabilities.annotations(component);
return decorators.find((d) => d instanceof Component);
const decorators = reflectionCapabilities.annotations(component);

return decorators.reverse().find((d) => d instanceof Component);
};

0 comments on commit 1af9353

Please sign in to comment.