refactor(ivy): ngcc - abstract how module statements are found (#25445)

This will be important for UMD support.

PR Close #25445
This commit is contained in:
Pete Bacon Darwin 2019-04-28 20:48:34 +01:00 committed by Jason Aden
parent 989bfd2e97
commit 48b77459ef
1 changed files with 11 additions and 1 deletions

View File

@ -312,7 +312,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
*/
findDecoratedClasses(sourceFile: ts.SourceFile): DecoratedClass[] {
const classes: DecoratedClass[] = [];
sourceFile.statements.map(statement => {
this.getModuleStatements(sourceFile).forEach(statement => {
if (ts.isVariableStatement(statement)) {
statement.declarationList.declarations.forEach(declaration => {
const decoratedClass = this.getDecoratedClassFromSymbol(this.getClassSymbol(declaration));
@ -474,6 +474,16 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N
this.aliasedClassDeclarations.set(aliasedDeclaration.node, declaration.name);
}
/** Get the top level statements for a module.
*
* In ES5 and ES2015 this is just the top level statements of the file.
* @param sourceFile The module whose statements we want.
* @returns An array of top level statements for the given module.
*/
protected getModuleStatements(sourceFile: ts.SourceFile): ts.Statement[] {
return Array.from(sourceFile.statements);
}
protected getDecoratorsOfSymbol(symbol: ClassSymbol): Decorator[]|null {
const decoratorsProperty = this.getStaticProperty(symbol, DECORATORS);
if (decoratorsProperty) {