From c038992fae5be10f5369d8ddb8d9e15eb70b6bd5 Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Mon, 22 Jul 2019 10:05:04 +0100 Subject: [PATCH] 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 --- .../src/ngtsc/annotations/src/util.ts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/annotations/src/util.ts b/packages/compiler-cli/src/ngtsc/annotations/src/util.ts index 7340722af2..0615382607 100644 --- a/packages/compiler-cli/src/ngtsc/annotations/src/util.ts +++ b/packages/compiler-cli/src/ngtsc/annotations/src/util.ts @@ -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; - } 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; + } else { + return 'dynamic'; } }