Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit 8f00a78

Browse files
committed
feat(annotations): read stacked @Inject annotations
1 parent d9c0f03 commit 8f00a78

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

src/annotations.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,12 @@ function readAnnotations(fn) {
102102
if (fn.annotations && fn.annotations.length) {
103103
for (var annotation of fn.annotations) {
104104
if (annotation instanceof Inject) {
105-
collectedAnnotations.params = annotation.tokens.map((token) => {
106-
return {token: token, isPromise: annotation.isPromise, isLazy: annotation.isLazy};
105+
annotation.tokens.forEach((token) => {
106+
collectedAnnotations.params.push({
107+
token: token,
108+
isPromise: annotation.isPromise,
109+
isLazy: annotation.isLazy
110+
});
107111
});
108112
}
109113

test/annotations.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,29 @@ describe('readAnnotations', function() {
158158
expect(annotations.params[1].isPromise).toBe(false);
159159
expect(annotations.params[1].isLazy).toBe(false);
160160
});
161+
162+
it('should read stacked @Inject{Lazy, Promise} annotations', function() {
163+
class One {}
164+
class Two {}
165+
class Three {}
166+
167+
@Inject(One)
168+
@InjectLazy(Two)
169+
@InjectPromise(Three)
170+
class Foo {}
171+
172+
var annotations = readAnnotations(Foo);
173+
174+
expect(annotations.params[0].token).toBe(One);
175+
expect(annotations.params[0].isPromise).toBe(false);
176+
expect(annotations.params[0].isLazy).toBe(false);
177+
178+
expect(annotations.params[1].token).toBe(Two);
179+
expect(annotations.params[1].isPromise).toBe(false);
180+
expect(annotations.params[1].isLazy).toBe(true);
181+
182+
expect(annotations.params[2].token).toBe(Three);
183+
expect(annotations.params[2].isPromise).toBe(true);
184+
expect(annotations.params[2].isLazy).toBe(false);
185+
});
161186
});

0 commit comments

Comments
 (0)