X Tutup
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions modules/angular2/src/compiler/static_reflector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export class StaticReflector {
annotations = (<any[]>classMetadata['decorators'])
.map(decorator => this.convertKnownDecorator(type.moduleId, decorator))
.filter(decorator => isPresent(decorator));
} else {
annotations = [];
}
this.annotationCache.set(type, annotations);
}
Expand All @@ -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;
Expand All @@ -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 = (<any[]>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 = (<any[]>ctorData).find(a => a['__symbolic'] === 'constructor');
parameters = this.simplify(type.moduleId, ctor['parameters']);
}
}
}
if (!isPresent(parameters)) {
parameters = [];
}
this.parameterCache.set(type, parameters);
}
return parameters;
}
Expand Down Expand Up @@ -290,7 +303,7 @@ export class StaticReflector {
});
return result;
}
return null;
return {};
}

// clang-format off
Expand Down
27 changes: 27 additions & 0 deletions modules/angular2/test/compiler/static_reflector_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
X Tutup