diff --git a/lib/core_dom/element_binder_builder.dart b/lib/core_dom/element_binder_builder.dart index dfa070d71..c1b5e995e 100644 --- a/lib/core_dom/element_binder_builder.dart +++ b/lib/core_dom/element_binder_builder.dart @@ -67,6 +67,11 @@ class ElementBinderBuilder { var children = annotation.children; if (annotation.children == Directive.TRANSCLUDE_CHILDREN) { + if (template != null) { + throw "There could be at most one transcluding directive on a node. The node " + "'${ref.element.outerHtml}' has both '${ref.annotation.selector}' and " + "'${template.annotation.selector}'."; + } template = ref; } else if (annotation is Component) { ComponentFactory factory; diff --git a/test/core_dom/element_binder_builder_spec.dart b/test/core_dom/element_binder_builder_spec.dart index 72a45eb8e..7c3b1e30e 100644 --- a/test/core_dom/element_binder_builder_spec.dart +++ b/test/core_dom/element_binder_builder_spec.dart @@ -5,73 +5,91 @@ import 'dart:mirrors'; @Component(selector:'component') class _Component{} @Decorator(selector:'[ignore-children]', - children: Directive.IGNORE_CHILDREN) - class _IgnoreChildren{} + children: Directive.IGNORE_CHILDREN) + class _IgnoreChildren{} @Decorator(selector:'[structural]', - children: Directive.TRANSCLUDE_CHILDREN) - class _Structural{} + children: Directive.TRANSCLUDE_CHILDREN) + class _Structural{} @Decorator(selector:'[directive]') class _DirectiveAttr{} +@Decorator(selector: '[templates]', + children: Directive.TRANSCLUDE_CHILDREN) + class _Template1{} +@Decorator(selector: '[templates]', + children: Directive.TRANSCLUDE_CHILDREN) + class _Template2{} + directiveFor(i) { ClassMirror cm = reflectType(i); } -main() => describe('ElementBinderBuilder', () { - var b; - var directives; - var node = null; - - beforeEachModule((Module module) { - module - ..bind(_DirectiveAttr) - ..bind(_Component) - ..bind(_IgnoreChildren) - ..bind(_Structural); - }); +void main() { + describe('ElementBinderBuilder', () { + ElementBinderBuilder builder; + ElementBinder binder; + var directives; + var node = new DivElement(); + + beforeEachModule((Module module) { + module..bind(_DirectiveAttr) + ..bind(_Component) + ..bind(_IgnoreChildren) + ..bind(_Structural) + ..bind(_Template1) + ..bind(_Template2); - beforeEach((DirectiveMap d, ElementBinderFactory f) { - directives = d; - b = f.builder(null, null); - }); + }); - addDirective(selector) { - directives.forEach((Directive annotation, Type type) { - if (annotation.selector == selector) - b.addDirective(new DirectiveRef(node, type, annotation, new Key(type), null)); + beforeEach((DirectiveMap d, ElementBinderFactory f) { + directives = d; + builder = f.builder(null, null); }); - b = b.binder; - } - it('should add a decorator', () { - expect(b.decorators.length).toEqual(0); + addDirective(selector) { + directives.forEach((Directive annotation, Type type) { + if (annotation.selector == selector) + builder.addDirective(new DirectiveRef(node, type, annotation, new Key(type), null)); + }); + binder = builder.binder; + } - addDirective('[directive]'); + it('should add a decorator', () { + expect(builder.decorators.length).toEqual(0); - expect(b.decorators.length).toEqual(1); - expect(b.componentData).toBeNull(); - expect(b.childMode).toEqual(Directive.COMPILE_CHILDREN); + addDirective('[directive]'); - }); + expect(binder.decorators.length).toEqual(1); + expect(binder.componentData).toBeNull(); + expect(binder.childMode).toEqual(Directive.COMPILE_CHILDREN); + + }); - it('should add a component', async(() { - addDirective('component'); + it('should add a component', async(() { + addDirective('component'); - expect(b.decorators.length).toEqual(0); - expect(b.componentData).toBeNotNull(); - })); + expect(binder.decorators.length).toEqual(0); + expect(binder.componentData).toBeNotNull(); + })); - it('should add a template', () { - addDirective('[structural]'); + it('should add a template', () { + addDirective('[structural]'); - expect(b.template).toBeNotNull(); - }); + expect(binder.template).toBeNotNull(); + }); - it('should add a directive that ignores children', () { - addDirective('[ignore-children]'); + it('could have at most one template', () { + expect(() => addDirective(('[templates]'))) + .toThrowWith(message: "There could be at most one transcluding directive on a node. The " + "node '
' has both '[templates]' and '[templates]'."); + }); + + it('should add a directive that ignores children', () { + addDirective('[ignore-children]'); - expect(b.decorators.length).toEqual(1); - expect(b.componentData).toBeNull(); - expect(b.childMode).toEqual(Directive.IGNORE_CHILDREN); + expect(binder.decorators.length).toEqual(1); + expect(binder.componentData).toBeNull(); + expect(binder.childMode).toEqual(Directive.IGNORE_CHILDREN); + }); }); -}); +} \ No newline at end of file