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

Commit 6fe02a0

Browse files
committed
feat(tagging compiler): Support comments
1 parent 7c5bdb0 commit 6fe02a0

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

lib/core_dom/tagging_compiler.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ class TaggingCompiler implements Compiler {
6868
} else if (node.nodeType == 3 || node.nodeType == 8) {
6969
elementBinder = node.nodeType == 3 ? directives.selector.matchText(node) : elementBinder;
7070

71-
if (elementBinder.hasDirectives && (node.parentNode != null && templateCursor.current.parentNode != null)) {
71+
if (elementBinder != null &&
72+
elementBinder.hasDirectives &&
73+
(node.parentNode != null && templateCursor.current.parentNode != null)) {
7274
if (directParentElementBinder == null) {
7375

7476
directParentElementBinder = new TaggedElementBinder(null, parentElementBinderOffset);
@@ -84,10 +86,8 @@ class TaggingCompiler implements Compiler {
8486
} else if(!(node.parentNode != null && templateCursor.current.parentNode != null)) { // Always add an elementBinder for top-level text.
8587
elementBinders.add(new TaggedElementBinder(elementBinder, parentElementBinderOffset));
8688
}
87-
// } else if (node.nodeType == 8) { // comment
88-
8989
} else {
90-
throw "wtf";
90+
throw "Unsupported node type for $node: [${node.nodeType}]";
9191
}
9292
} while (templateCursor.moveNext() && domCursor.moveNext());
9393

test/core_dom/compiler_spec.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,18 @@ void main() {
6767
$compile([], directives);
6868
}));
6969

70+
it('should compile a comment with no directives around', inject(() {
71+
var element = $('<div><!-- comment --></div>');
72+
$compile(element, directives);
73+
expect(element.html()).toEqual('<!-- comment -->');
74+
}));
75+
76+
it('should compile a comment when the parent has a directive', inject(() {
77+
var element = $('<div ng-show="true"><!-- comment --></div>');
78+
$compile(element, directives);
79+
expect(element.html()).toEqual('<!-- comment -->');
80+
}));
81+
7082
it('should compile a directive in a child', inject(() {
7183
var element = $('<div><div ng-bind="name"></div></div>');
7284
var template = $compile(element, directives);

0 commit comments

Comments
 (0)