feat(ivy): add getBaseClassIdentifier() to ReflectionHost (#31544)

This method will be useful for writing ngcc `Migrations` that
need to be able to find base classes.

PR Close #31544
This commit is contained in:
Pete Bacon Darwin
2019-07-18 21:05:31 +01:00
committed by Misko Hevery
parent 399935c32b
commit 8a470b9af9
8 changed files with 408 additions and 4 deletions

View File

@ -190,9 +190,21 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
return false;
}
return innerClassDeclaration.heritageClauses !== undefined &&
innerClassDeclaration.heritageClauses.some(
clause => clause.token === ts.SyntaxKind.ExtendsKeyword);
return super.hasBaseClass(innerClassDeclaration);
}
getBaseClassExpression(clazz: ClassDeclaration): ts.Expression|null {
// First try getting the base class from the "outer" declaration
const superBaseClassIdentifier = super.getBaseClassExpression(clazz);
if (superBaseClassIdentifier) {
return superBaseClassIdentifier;
}
// That didn't work so now try getting it from the "inner" declaration.
const innerClassDeclaration = getInnerClassDeclaration(clazz);
if (innerClassDeclaration === null) {
return null;
}
return super.getBaseClassExpression(innerClassDeclaration);
}
/**

View File

@ -56,6 +56,32 @@ export class Esm5ReflectionHost extends Esm2015ReflectionHost {
return iife.parameters.length === 1 && isSuperIdentifier(iife.parameters[0].name);
}
getBaseClassExpression(clazz: ClassDeclaration): ts.Expression|null {
const superBaseClassIdentifier = super.getBaseClassExpression(clazz);
if (superBaseClassIdentifier) {
return superBaseClassIdentifier;
}
const classDeclaration = this.getClassDeclaration(clazz);
if (!classDeclaration) return null;
const iifeBody = getIifeBody(classDeclaration);
if (!iifeBody) return null;
const iife = iifeBody.parent;
if (!iife || !ts.isFunctionExpression(iife)) return null;
if (iife.parameters.length !== 1 || !isSuperIdentifier(iife.parameters[0].name)) {
return null;
}
if (!ts.isCallExpression(iife.parent)) {
return null;
}
return iife.parent.arguments[0];
}
/**
* Find the declaration of a class given a node that we think represents the class.
*