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

feat(directives): Do not crash on missing map parameters. #36

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
1 change: 1 addition & 0 deletions lib/block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ class ComponentFactory {
createAttributeMapping(Scope parentScope, Scope shadowScope, Parser parser) {
directive.$map.forEach((attrName, mapping) {
var attrValue = element.attributes[attrName];
if (attrValue == null) attrValue = '';
if (mapping == '@') {
shadowScope[attrName] = attrValue;
} else if (mapping == '=') {
Expand Down
39 changes: 39 additions & 0 deletions test/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ main() {
beforeEach(module((AngularModule module) {
module.directive(SimpleComponent);
module.directive(IoComponent);
module.directive(ParentExpressionComponent);
module.directive(PublishMeComponent);
}));

Expand All @@ -408,6 +409,35 @@ main() {
}));
}));

it('should create a component that can access parent scope', inject(() {
$rootScope.fromParent = "should not be used";
$rootScope.val = "poof";
var element = $('<parent-expression fromParent=val></parent-expression>');

$compile(element)(injector, element);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this PR, but why do we pass in injector ? that makes no sense to me...


ParentExpressionComponent.lastTemplateLoader.template.then(expectAsync1((_) {
expect(renderedText(element)).toEqual('inside poof');
}));
}));

it('should behave nicely if a mapped attribute is missing', inject(() {
var element = $('<parent-expression></parent-expression>');
$compile(element)(injector, element);
ParentExpressionComponent.lastTemplateLoader.template.then(expectAsync1((_) {
expect(renderedText(element)).toEqual('inside ');
}));
}));

it('should behave nicely if a mapped attribute evals to null', inject(() {
$rootScope.val = null;
var element = $('<parent-expression fromParent=val></parent-expression>');
$compile(element)(injector, element);
ParentExpressionComponent.lastTemplateLoader.template.then(expectAsync1((_) {
expect(renderedText(element)).toEqual('inside ');
}));
}));

it('should create a component with IO', inject(() {
var element = $(r'<div><io attr="A" expr="name" ondone="done=true"></io></div>');
$compile(element)(injector, element);
Expand Down Expand Up @@ -480,6 +510,15 @@ class IoComponent {
}
}

class ParentExpressionComponent {
static String $template = '<div>inside {{fromParent()}}</div>';
static Map $map = {"fromParent": "&"};
static TemplateLoader lastTemplateLoader;
ParentExpressionComponent(Scope shadowScope, TemplateLoader templateLoader) {
lastTemplateLoader = templateLoader;
}
}

class PublishMeComponent {
static String $template = r'<content>{{ctrlName.value}}</content>';
static String $publishAs = 'ctrlName';
Expand Down