Skip to content

Commit 706f9e9

Browse files
committed
fix(transcluding component factory): allow removing components that have no content to transclude
1 parent b7f175b commit 706f9e9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/core_dom/transcluding_component_factory.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,16 @@ class ContentPort {
3232

3333
content(dom.Element elt) {
3434
var hash = elt.hashCode;
35-
var beginComment = new dom.Comment("content $hash");
35+
var beginComment = null;
3636

3737
if (_childNodes.isNotEmpty) {
38+
beginComment = new dom.Comment("content $hash");
3839
elt.parent.insertBefore(beginComment, elt);
3940
elt.parent.insertAllBefore(_childNodes, elt);
4041
elt.parent.insertBefore(new dom.Comment("end-content $hash"), elt);
4142
_childNodes = [];
4243
}
44+
4345
elt.remove();
4446
return beginComment;
4547
}
@@ -48,6 +50,10 @@ class ContentPort {
4850
// Search for endComment and extract everything in between.
4951
// TODO optimize -- there may be a better way of pulling out nodes.
5052

53+
if (_beginComment == null) {
54+
return;
55+
}
56+
5157
var endCommentText = "end-${_beginComment.text}";
5258

5359
var next;

test/core_dom/compiler_spec.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,14 @@ void main() {
348348
expect(element).toHaveText('And jump');
349349
}));
350350

351+
it('should safely remove transcluding components that transclude no content', async(() {
352+
_.rootScope.context['flag'] = true;
353+
_.compile('<div ng-if=flag><simple></simple></div>');
354+
microLeap(); _.rootScope.apply();
355+
_.rootScope.context['flag'] = false;
356+
microLeap(); _.rootScope.apply();
357+
}));
358+
351359
it('should store ElementProbe with Elements', async(() {
352360
_.compile('<div><simple>innerText</simple></div>');
353361
microLeap();

0 commit comments

Comments
 (0)