refactor(compiler-cli): delegate `hasBaseClass()` to `getBaseClassExpression()` (#36989)

The previous implementations of `hasBaseClass()` are almost
identical to the implementation of `getBaseClassExpression()`.
There is little benefit in duplicating this code so this refactoring
changes `hasBaseClass()` to just call `getBaseClassExpression()`.
This allows the various hosts that implement this to be simplified.

PR Close #36989
This commit is contained in:
Pete Bacon Darwin 2020-05-12 08:19:59 +01:00 committed by Kara Erickson
parent 0066a1ae70
commit dbcaf22805
3 changed files with 1 additions and 39 deletions

View File

@ -318,20 +318,6 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
return null; return null;
} }
hasBaseClass(clazz: ClassDeclaration): boolean {
const superHasBaseClass = super.hasBaseClass(clazz);
if (superHasBaseClass) {
return superHasBaseClass;
}
const innerClassDeclaration = getInnerClassDeclaration(clazz);
if (innerClassDeclaration === null) {
return false;
}
return super.hasBaseClass(innerClassDeclaration);
}
getBaseClassExpression(clazz: ClassDeclaration): ts.Expression|null { getBaseClassExpression(clazz: ClassDeclaration): ts.Expression|null {
// First try getting the base class from the "outer" declaration // First try getting the base class from the "outer" declaration
const superBaseClassIdentifier = super.getBaseClassExpression(clazz); const superBaseClassIdentifier = super.getBaseClassExpression(clazz);

View File

@ -33,28 +33,6 @@ import {NgccClassSymbol} from './ngcc_host';
* *
*/ */
export class Esm5ReflectionHost extends Esm2015ReflectionHost { export class Esm5ReflectionHost extends Esm2015ReflectionHost {
/**
* Determines whether the given declaration, which should be a "class", has a base "class".
*
* In ES5 code, we need to determine if the IIFE wrapper takes a `_super` parameter .
*
* @param clazz a `ClassDeclaration` representing the class over which to reflect.
*/
hasBaseClass(clazz: ClassDeclaration): boolean {
const classSymbol = this.getClassSymbol(clazz);
if (classSymbol === undefined) {
return false;
}
const iifeBody = getIifeBody(classSymbol.declaration.valueDeclaration);
if (!iifeBody) return false;
const iife = iifeBody.parent;
if (!iife || !ts.isFunctionExpression(iife)) return false;
return iife.parameters.length === 1 && isSuperIdentifier(iife.parameters[0].name);
}
getBaseClassExpression(clazz: ClassDeclaration): ts.Expression|null { getBaseClassExpression(clazz: ClassDeclaration): ts.Expression|null {
const classSymbol = this.getClassSymbol(clazz); const classSymbol = this.getClassSymbol(clazz);
if (classSymbol === undefined) { if (classSymbol === undefined) {

View File

@ -128,9 +128,7 @@ export class TypeScriptReflectionHost implements ReflectionHost {
} }
hasBaseClass(clazz: ClassDeclaration): boolean { hasBaseClass(clazz: ClassDeclaration): boolean {
return (ts.isClassDeclaration(clazz) || ts.isClassExpression(clazz)) && return this.getBaseClassExpression(clazz) !== null;
clazz.heritageClauses !== undefined &&
clazz.heritageClauses.some(clause => clause.token === ts.SyntaxKind.ExtendsKeyword);
} }
getBaseClassExpression(clazz: ClassDeclaration): ts.Expression|null { getBaseClassExpression(clazz: ClassDeclaration): ts.Expression|null {