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

Commit 755beb2

Browse files
shyamseshadrimhevery
authored andcommitted
fix(compiler): Allow startingTag method to handle text / comment nodes
1 parent 6d70ff5 commit 755beb2

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/Angular.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -777,9 +777,18 @@ function startingTag(element) {
777777
// are not allowed to have children. So we just ignore it.
778778
element.html('');
779779
} catch(e) {}
780-
return jqLite('<div>').append(element).html().
781-
match(/^(<[^>]+>)/)[1].
782-
replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); });
780+
// As Per DOM Standards
781+
var TEXT_NODE = 3;
782+
var elemHtml = jqLite('<div>').append(element).html();
783+
try {
784+
return element[0].nodeType === TEXT_NODE ? lowercase(elemHtml) :
785+
elemHtml.
786+
match(/^(<[^>]+>)/)[1].
787+
replace(/^<([\w\-]+)/, function(match, nodeName) { return '<' + lowercase(nodeName); });
788+
} catch(e) {
789+
return lowercase(elemHtml);
790+
}
791+
783792
}
784793

785794

test/AngularSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,13 @@ describe('angular', function() {
673673
toBe('<ng-abc x="2A">');
674674
});
675675
});
676+
677+
describe('startingTag', function() {
678+
it('should allow passing in Nodes instead of Elements', function() {
679+
var txtNode = document.createTextNode('some text');
680+
expect(startingTag(txtNode)).toBe('some text');
681+
});
682+
});
676683

677684
describe('snake_case', function(){
678685
it('should convert to snake_case', function() {

0 commit comments

Comments
 (0)