fix(7877): StaticReflector returns empty results instead of undefined.
Reflector always returns either an empty object or an empty list if no metadata is recorded for the class. StaticReflector matches this behavior. Closes #7986
This commit is contained in:

committed by
Robert Messerle

parent
2abb414cfb
commit
fc496813e2
@ -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);
|
||||
}
|
||||
@ -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 = (<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;
|
||||
}
|
||||
@ -290,7 +303,7 @@ export class StaticReflector {
|
||||
});
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
return {};
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
|
Reference in New Issue
Block a user