diff --git a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts index e2d666773e..d65a6f32d6 100644 --- a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts +++ b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts @@ -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) {