diff --git a/modules/angular2/src/compiler/static_reflector.ts b/modules/angular2/src/compiler/static_reflector.ts index 925466e4ee..9b5a73612f 100644 --- a/modules/angular2/src/compiler/static_reflector.ts +++ b/modules/angular2/src/compiler/static_reflector.ts @@ -90,6 +90,8 @@ export class StaticReflector { annotations = (classMetadata['decorators']) .map(decorator => this.convertKnownDecorator(type.moduleId, decorator)) .filter(decorator => isPresent(decorator)); + } else { + annotations = []; } this.annotationCache.set(type, annotations); } @@ -101,6 +103,9 @@ export class StaticReflector { if (!isPresent(propMetadata)) { let classMetadata = this.getTypeMetadata(type); propMetadata = this.getPropertyMetadata(type.moduleId, classMetadata['members']); + if (!isPresent(propMetadata)) { + propMetadata = {}; + } this.propertyCache.set(type, propMetadata); } return propMetadata; @@ -110,12 +115,20 @@ export class StaticReflector { let parameters = this.parameterCache.get(type); if (!isPresent(parameters)) { let classMetadata = this.getTypeMetadata(type); - let ctorData = classMetadata['members']['__ctor__']; - if (isPresent(ctorData)) { - let ctor = (ctorData).find(a => a['__symbolic'] === 'constructor'); - parameters = this.simplify(type.moduleId, ctor['parameters']); - this.parameterCache.set(type, parameters); + if (isPresent(classMetadata)) { + let members = classMetadata['members']; + if (isPresent(members)) { + let ctorData = members['__ctor__']; + if (isPresent(ctorData)) { + let ctor = (ctorData).find(a => a['__symbolic'] === 'constructor'); + parameters = this.simplify(type.moduleId, ctor['parameters']); + } + } } + if (!isPresent(parameters)) { + parameters = []; + } + this.parameterCache.set(type, parameters); } return parameters; } @@ -290,7 +303,7 @@ export class StaticReflector { }); return result; } - return null; + return {}; } // clang-format off diff --git a/modules/angular2/test/compiler/static_reflector_spec.ts b/modules/angular2/test/compiler/static_reflector_spec.ts index fcb361a551..e9ce0868f9 100644 --- a/modules/angular2/test/compiler/static_reflector_spec.ts +++ b/modules/angular2/test/compiler/static_reflector_spec.ts @@ -60,6 +60,15 @@ export function main() { expect(annotation.selector).toEqual('my-hero-detail'); }); + it('should get and empty annotation list for an unknown class', () => { + let host = new MockReflectorHost(); + let reflector = new StaticReflector(host); + + let UnknownClass = reflector.getStaticType('./app/app.component', 'UnknownClass'); + let annotations = reflector.annotations(UnknownClass); + expect(annotations).toEqual([]); + }); + it('should get propMetadata for HeroDetailComponent', () => { let host = new MockReflectorHost(); let reflector = new StaticReflector(host); @@ -70,6 +79,24 @@ export function main() { expect(props['hero']).toBeTruthy(); }); + it('should get an empty object from propMetadata for an unknown class', () => { + let host = new MockReflectorHost(); + let reflector = new StaticReflector(host); + + let UnknownClass = reflector.getStaticType('./app/app.component', 'UnknownClass'); + let properties = reflector.propMetadata(UnknownClass); + expect(properties).toEqual({}); + }); + + it('should get empty parameters list for an unknown class ', () => { + let host = new MockReflectorHost(); + let reflector = new StaticReflector(host); + + let UnknownClass = reflector.getStaticType('./app/app.component', 'UnknownClass'); + let parameters = reflector.parameters(UnknownClass); + expect(parameters).toEqual([]); + }); + it('should simplify primitive into itself', () => { let host = new MockReflectorHost(); let reflector = new StaticReflector(host);