diff --git a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts index 150f9b1716..a2a6f0b9ae 100644 --- a/packages/compiler-cli/ngcc/src/host/esm2015_host.ts +++ b/packages/compiler-cli/ngcc/src/host/esm2015_host.ts @@ -638,7 +638,7 @@ export class Esm2015ReflectionHost extends TypeScriptReflectionHost implements N */ protected getStaticProperty(symbol: NgccClassSymbol, propertyName: ts.__String): ts.Symbol |undefined { - return symbol.implementation.exports && symbol.implementation.exports.get(propertyName); + return symbol.declaration.exports && symbol.declaration.exports.get(propertyName); } /** diff --git a/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts b/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts index 5db8a3fa05..b43c32d839 100644 --- a/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts +++ b/packages/compiler-cli/ngcc/test/host/esm2015_host_spec.ts @@ -132,9 +132,13 @@ runInEachFileSystem(() => { CLASS_EXPRESSION_FILE = { name: _('/class_expression.js'), contents: ` + import {Directive} from '@angular/core'; var AliasedClass_1; let EmptyClass = class EmptyClass {}; let AliasedClass = AliasedClass_1 = class AliasedClass {} + AliasedClass.decorators = [ + { type: Directive, args: [{ selector: '[someDirective]' },] } + ]; let usageOfAliasedClass = AliasedClass_1; `, }; @@ -708,6 +712,25 @@ runInEachFileSystem(() => { ]); }); + it('should find the decorators on an aliased class', () => { + loadTestFiles([CLASS_EXPRESSION_FILE]); + const {program} = makeTestBundleProgram(CLASS_EXPRESSION_FILE.name); + const host = new Esm2015ReflectionHost(new MockLogger(), false, program.getTypeChecker()); + const classNode = getDeclaration( + program, CLASS_EXPRESSION_FILE.name, 'AliasedClass', isNamedVariableDeclaration); + const decorators = host.getDecoratorsOfDeclaration(classNode) !; + + expect(decorators).toBeDefined(); + expect(decorators.length).toEqual(1); + + const decorator = decorators[0]; + expect(decorator.name).toEqual('Directive'); + expect(decorator.import).toEqual({name: 'Directive', from: '@angular/core'}); + expect(decorator.args !.map(arg => arg.getText())).toEqual([ + '{ selector: \'[someDirective]\' }', + ]); + }); + it('should return null if the symbol is not a class', () => { loadTestFiles([FOO_FUNCTION_FILE]); const {program} = makeTestBundleProgram(FOO_FUNCTION_FILE.name);