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

Commit

Permalink
feat(tagging compiler): Support comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jbdeboer committed Mar 12, 2014
1 parent 7c5bdb0 commit 6fe02a0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/core_dom/tagging_compiler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ class TaggingCompiler implements Compiler {
} else if (node.nodeType == 3 || node.nodeType == 8) {
elementBinder = node.nodeType == 3 ? directives.selector.matchText(node) : elementBinder;

if (elementBinder.hasDirectives && (node.parentNode != null && templateCursor.current.parentNode != null)) {
if (elementBinder != null &&
elementBinder.hasDirectives &&
(node.parentNode != null && templateCursor.current.parentNode != null)) {
if (directParentElementBinder == null) {

directParentElementBinder = new TaggedElementBinder(null, parentElementBinderOffset);
Expand All @@ -84,10 +86,8 @@ class TaggingCompiler implements Compiler {
} else if(!(node.parentNode != null && templateCursor.current.parentNode != null)) { // Always add an elementBinder for top-level text.
elementBinders.add(new TaggedElementBinder(elementBinder, parentElementBinderOffset));
}
// } else if (node.nodeType == 8) { // comment

} else {
throw "wtf";
throw "Unsupported node type for $node: [${node.nodeType}]";
}
} while (templateCursor.moveNext() && domCursor.moveNext());

Expand Down
12 changes: 12 additions & 0 deletions test/core_dom/compiler_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ void main() {
$compile([], directives);
}));

it('should compile a comment with no directives around', inject(() {
var element = $('<div><!-- comment --></div>');
$compile(element, directives);
expect(element.html()).toEqual('<!-- comment -->');
}));

it('should compile a comment when the parent has a directive', inject(() {
var element = $('<div ng-show="true"><!-- comment --></div>');
$compile(element, directives);
expect(element.html()).toEqual('<!-- comment -->');
}));

it('should compile a directive in a child', inject(() {
var element = $('<div><div ng-bind="name"></div></div>');
var template = $compile(element, directives);
Expand Down

0 comments on commit 6fe02a0

Please sign in to comment.