From 48b77459efced47ba99d2e567193aaa23e3f257b Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Sun, 28 Apr 2019 20:48:34 +0100 Subject: [PATCH] refactor(ivy): ngcc - abstract how module statements are found (#25445) This will be important for UMD support. PR Close #25445 --- packages/compiler-cli/ngcc/src/host/esm2015_host.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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) {