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

fix(ElementBinderBuilder): throw if more than one transcluding directive... #1325

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/core_dom/element_binder_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
114 changes: 66 additions & 48 deletions test/core_dom/element_binder_builder_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div></div>' 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);
});
});
});
}