fix(ivy): proper component resolution in case of inheritance (#28439)

Ivy allows Components to extend Directives (but not the other way around) and as a result we may have Component and Directive annotations present at the same time. The logic that resolves annotations to pick the necessary one didn't take this into account and as a result Components were recognized as Directives (and vice versa) in case of inheritance. This change updates the resolution logic by picking known annotation that is the nearest one (in inheritance tree) and compares it with expected type. That should help avoid mis-classification of Components/Directives during resolution.

PR Close #28439
This commit is contained in:
Andrew Kushnir
2019-01-29 17:13:02 -08:00
committed by Matias Niemelä
parent ed0cf7e2cb
commit 5a2c3ff8b5
5 changed files with 180 additions and 36 deletions

View File

@ -345,9 +345,12 @@ function setScopeOnDeclaredComponents(moduleType: Type<any>, ngModule: NgModule)
*/
export function patchComponentDefWithScope<C>(
componentDef: ComponentDef<C>, transitiveScopes: NgModuleTransitiveScopes) {
componentDef.directiveDefs = () => Array.from(transitiveScopes.compilation.directives)
.map(dir => getDirectiveDef(dir) || getComponentDef(dir) !)
.filter(def => !!def);
componentDef.directiveDefs = () =>
Array.from(transitiveScopes.compilation.directives)
.map(
dir => dir.hasOwnProperty(NG_COMPONENT_DEF) ? getComponentDef(dir) ! :
getDirectiveDef(dir) !)
.filter(def => !!def);
componentDef.pipeDefs = () =>
Array.from(transitiveScopes.compilation.pipes).map(pipe => getPipeDef(pipe) !);
}