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

Commit

Permalink
fix(transcluding component factory): allow removing components that h…
Browse files Browse the repository at this point in the history
…ave no content to transclude
  • Loading branch information
chirayuk committed May 31, 2014
1 parent b7f175b commit 706f9e9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/core_dom/transcluding_component_factory.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ class ContentPort {

content(dom.Element elt) {
var hash = elt.hashCode;
var beginComment = new dom.Comment("content $hash");
var beginComment = null;

if (_childNodes.isNotEmpty) {
beginComment = new dom.Comment("content $hash");
elt.parent.insertBefore(beginComment, elt);
elt.parent.insertAllBefore(_childNodes, elt);
elt.parent.insertBefore(new dom.Comment("end-content $hash"), elt);
_childNodes = [];
}

elt.remove();
return beginComment;
}
Expand All @@ -48,6 +50,10 @@ class ContentPort {
// Search for endComment and extract everything in between.
// TODO optimize -- there may be a better way of pulling out nodes.

if (_beginComment == null) {
return;
}

var endCommentText = "end-${_beginComment.text}";

var next;
Expand Down
8 changes: 8 additions & 0 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ void main() {
expect(element).toHaveText('And jump');
}));

it('should safely remove transcluding components that transclude no content', async(() {
_.rootScope.context['flag'] = true;
_.compile('<div ng-if=flag><simple></simple></div>');
microLeap(); _.rootScope.apply();
_.rootScope.context['flag'] = false;
microLeap(); _.rootScope.apply();
}));

it('should store ElementProbe with Elements', async(() {
_.compile('<div><simple>innerText</simple></div>');
microLeap();
Expand Down

0 comments on commit 706f9e9

Please sign in to comment.