Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix(compiler): Allow startingTag method to handle text / comment nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
shyamseshadri authored and mhevery committed Feb 14, 2013
1 parent 6d70ff5 commit 755beb2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,9 +777,18 @@ function startingTag(element) {
// are not allowed to have children. So we just ignore it.
element.html('');
} catch(e) {}
return jqLite('<div>').append(element).html().
match(/^(<[^>]+>)/)[1].
replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); });
// As Per DOM Standards
var TEXT_NODE = 3;
var elemHtml = jqLite('<div>').append(element).html();
try {
return element[0].nodeType === TEXT_NODE ? lowercase(elemHtml) :
elemHtml.
match(/^(<[^>]+>)/)[1].
replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); });
} catch(e) {
return lowercase(elemHtml);
}

}


Expand Down
7 changes: 7 additions & 0 deletions test/AngularSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@ describe('angular', function() {
toBe('<ng-abc x="2A">');
});
});

describe('startingTag', function() {
it('should allow passing in Nodes instead of Elements', function() {
var txtNode = document.createTextNode('some text');
expect(startingTag(txtNode)).toBe('some text');
});
});

describe('snake_case', function(){
it('should convert to snake_case', function() {
Expand Down

0 comments on commit 755beb2

Please sign in to comment.