Skip to content

Commit be7504d

Browse files
committed
fix(decorators): fixes decorator reflection.
The bug appears when there are only type annotations without parameter annotations.
1 parent 169e4e8 commit be7504d

File tree

2 files changed

+38
-13
lines changed

2 files changed

+38
-13
lines changed

modules/angular2/src/reflection/reflection_capabilities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class ReflectionCapabilities {
5656
} else {
5757
result[i] = [];
5858
}
59-
if (isPresent(paramAnnotations[i])) {
59+
if (isPresent(paramAnnotations) && isPresent(paramAnnotations[i])) {
6060
result[i] = result[i].concat(paramAnnotations[i]);
6161
}
6262
}

modules/angular2/test/core/compiler/reflection_capabilities_spec.js

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ export function main() {
2525
}
2626

2727
function assertTestClassParameters(parameters) {
28+
expect(parameters.length).toBe(4);
29+
2830
expect(parameters[0].length).toBe(2);
2931
expect(parameters[0][0]).toEqual(P1);
3032
expect(parameters[0][1]).toBeAnInstanceOf(ParamDec);
@@ -48,20 +50,30 @@ export function main() {
4850
assertTestClassParameters(rc.parameters(TestClass));
4951
});
5052

51-
// Mocking in the tests below is needed because the test runs through Traceur.
52-
// After the switch to TS the setup will have to change, where the direct key
53-
// access will be mocked, and the tests below will be direct.
54-
it('can read out class annotations though Reflect APIs', () => {
55-
if (IS_DARTIUM) return;
56-
mockReflect(mockDataForTestClassDec, TestClassDec);
57-
assertTestClassAnnotations(rc.annotations(TestClassDec));
53+
it('can read out parameter annotations through parameters key for types only class', () => {
54+
expect(rc.parameters(TestClassTypesOnly)).toEqual([[P1], [P2]]);
5855
});
5956

60-
it('can read out parameter annotations though Reflect APIs', () => {
61-
if (IS_DARTIUM) return;
62-
mockReflect(mockDataForTestClassDec, TestClassDec);
63-
assertTestClassParameters(rc.parameters(TestClassDec));
64-
});
57+
58+
if (!IS_DARTIUM) {
59+
// Mocking in the tests below is needed because the test runs through Traceur.
60+
// After the switch to TS the setup will have to change, where the direct key
61+
// access will be mocked, and the tests below will be direct.
62+
it('can read out class annotations though Reflect APIs', () => {
63+
mockReflect(mockDataForTestClassDec, TestClassDec);
64+
assertTestClassAnnotations(rc.annotations(TestClassDec));
65+
});
66+
67+
it('can read out parameter annotations though Reflect APIs', () => {
68+
mockReflect(mockDataForTestClassDec, TestClassDec);
69+
assertTestClassParameters(rc.parameters(TestClassDec));
70+
});
71+
72+
it('can read out parameter annotations though Reflect APIs for types only class', () => {
73+
mockReflect(mockDataForTestClassTypesOnly, TestClassTypesOnlyDec);
74+
expect(rc.parameters(TestClassTypesOnlyDec)).toEqual([[P1], [P2]]);
75+
});
76+
}
6577
});
6678
}
6779

@@ -97,3 +109,16 @@ var mockDataForTestClassDec = {
97109
'design:paramtypes': [P1, P2, Object, Object]
98110
};
99111
class TestClassDec {}
112+
113+
114+
class TestClassTypesOnly {
115+
constructor(a: P1, b: P2) {}
116+
}
117+
118+
// Mocking the data stored in global.Reflect as if TS was compiling TestClass above.
119+
var mockDataForTestClassTypesOnly = {
120+
'annotations': null,
121+
'parameters': null,
122+
'design:paramtypes': [P1, P2]
123+
};
124+
class TestClassTypesOnlyDec {}

0 commit comments

Comments
 (0)