feat(ElementInjector): throw if multiple directives define the same host injectable
relates to #2015
This commit is contained in:
parent
309ef0f354
commit
6a6b43de07
@ -466,8 +466,14 @@ export class ProtoElementInjector {
|
|||||||
|
|
||||||
private static _createHostInjectorBindingData(bindings: List<ResolvedBinding>,
|
private static _createHostInjectorBindingData(bindings: List<ResolvedBinding>,
|
||||||
bd: List<BindingData>) {
|
bd: List<BindingData>) {
|
||||||
|
var visitedIds: Map<number, boolean> = MapWrapper.create();
|
||||||
ListWrapper.forEach(bindings, b => {
|
ListWrapper.forEach(bindings, b => {
|
||||||
ListWrapper.forEach(b.resolvedHostInjectables, b => {
|
ListWrapper.forEach(b.resolvedHostInjectables, b => {
|
||||||
|
if (MapWrapper.contains(visitedIds, b.key.id)) {
|
||||||
|
throw new BaseException(
|
||||||
|
`Multiple directives defined the same host injectable: "${stringify(b.key.token)}"`);
|
||||||
|
}
|
||||||
|
MapWrapper.set(visitedIds, b.key.id, true);
|
||||||
ListWrapper.push(bd, new BindingData(ProtoElementInjector._createBinding(b), LIGHT_DOM));
|
ListWrapper.push(bd, new BindingData(ProtoElementInjector._createBinding(b), LIGHT_DOM));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -106,7 +106,7 @@ class NeedsDirectiveFromParent {
|
|||||||
@Injectable()
|
@Injectable()
|
||||||
class NeedsDirectiveFromParentOrSelf {
|
class NeedsDirectiveFromParentOrSelf {
|
||||||
dependency: SimpleDirective;
|
dependency: SimpleDirective;
|
||||||
constructor(@Parent({self:true}) dependency: SimpleDirective) { this.dependency = dependency; }
|
constructor(@Parent({self: true}) dependency: SimpleDirective) { this.dependency = dependency; }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -478,9 +478,22 @@ export function main() {
|
|||||||
expect(pei.getBindingAtIndex(i).key.token).toBe(i);
|
expect(pei.getBindingAtIndex(i).key.token).toBe(i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw whenever multiple directives declare the same host injectable', () => {
|
||||||
|
expect(() => {
|
||||||
|
createPei(null, 0, [
|
||||||
|
DirectiveBinding.createFromType(SimpleDirective, new dirAnn.Component({
|
||||||
|
hostInjector: [bind('injectable1').toValue('injectable1')]
|
||||||
|
})),
|
||||||
|
DirectiveBinding.createFromType(SomeOtherDirective, new dirAnn.Component({
|
||||||
|
hostInjector: [bind('injectable1').toValue('injectable2')]
|
||||||
|
}))
|
||||||
|
]);
|
||||||
|
}).toThrowError('Multiple directives defined the same host injectable: "injectable1"');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("ElementInjector", () => {
|
describe("ElementInjector", () => {
|
||||||
describe("instantiate", () => {
|
describe("instantiate", () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user