Skip to content

Commit 15164a8

Browse files
committed
fix(reflector): merge prop metadata from getters and setters
Closes #4006
1 parent 4ec4dca commit 15164a8

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

modules/angular2/src/core/reflection/reflection_capabilities.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,8 @@ class ReflectionCapabilities implements PlatformReflectionCapabilities {
259259
final res = {};
260260
reflectClass(typeOrFunc).declarations.forEach((k,v) {
261261
var name = _normalizeName(MirrorSystem.getName(k));
262-
res[name] = v.metadata.map((fm) => fm.reflectee).toList();
262+
if (res[name] == null) res[name] = [];
263+
res[name].addAll(v.metadata.map((fm) => fm.reflectee));
263264
});
264265
return res;
265266
}

modules/angular2/test/core/reflection/reflector_common.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ ParamDecorator paramDecorator(value) {
2727
PropDecorator propDecorator(value) {
2828
return new PropDecorator(value);
2929
}
30+
31+
class HasGetterAndSetterDecorators {
32+
@PropDecorator("get") get a {}
33+
@PropDecorator("set") set a(v) {}
34+
}

modules/angular2/test/core/reflection/reflector_common.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@ export function propDecorator(value) {
3131
export var ClassDecorator = makeDecorator(ClassDecoratorMeta);
3232
export var ParamDecorator = makeParamDecorator(ParamDecoratorMeta);
3333
export var PropDecorator = makePropDecorator(PropDecoratorMeta);
34+
35+
// used only in Dart
36+
export class HasGetterAndSetterDecorators {}

modules/angular2/test/core/reflection/reflector_spec.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {
77
PropDecorator,
88
classDecorator,
99
paramDecorator,
10-
propDecorator
10+
propDecorator,
11+
HasGetterAndSetterDecorators
1112
} from './reflector_common';
1213
import {IS_DART} from '../../platform';
1314

@@ -160,6 +161,13 @@ export function main() {
160161
reflector.registerType(TestObj, new ReflectionInfo(null, null, null, null, {"a": [1, 2]}));
161162
expect(reflector.propMetadata(TestObj)).toEqual({"a": [1, 2]});
162163
});
164+
165+
if (IS_DART) {
166+
it("should merge metadata from getters and setters", () => {
167+
var p = reflector.propMetadata(HasGetterAndSetterDecorators);
168+
expect(p["a"]).toEqual([propDecorator("get"), propDecorator("set")]);
169+
});
170+
}
163171
});
164172

165173
describe("annotations", () => {

0 commit comments

Comments
 (0)