refactor(ivy): use ReflectionHost to find base classes (#31544)

When analyzing components, directives, etc we capture its base class.
Previously this assumed that the code is in TS format, which is not
always the case (e.g. ngcc).
Now this code is replaced with a call to
`ReflectionHost.getBaseClassExpression()`, which abstracts the work
of finding the base class.

PR Close #31544
This commit is contained in:
Pete Bacon Darwin 2019-07-22 10:05:04 +01:00 committed by Misko Hevery
parent 8a470b9af9
commit c038992fae
1 changed files with 7 additions and 11 deletions

View File

@ -317,17 +317,13 @@ export function readBaseClass(
return reflector.hasBaseClass(node) ? 'dynamic' : null;
}
if (node.heritageClauses !== undefined) {
for (const clause of node.heritageClauses) {
if (clause.token === ts.SyntaxKind.ExtendsKeyword) {
// The class has a base class. Figure out whether it's resolvable or not.
const baseClass = evaluator.evaluate(clause.types[0].expression);
if (baseClass instanceof Reference && isNamedClassDeclaration(baseClass.node)) {
return baseClass as Reference<ClassDeclaration>;
} else {
return 'dynamic';
}
}
const baseExpression = reflector.getBaseClassExpression(node);
if (baseExpression !== null) {
const baseClass = evaluator.evaluate(baseExpression);
if (baseClass instanceof Reference && isNamedClassDeclaration(baseClass.node)) {
return baseClass as Reference<ClassDeclaration>;
} else {
return 'dynamic';
}
}