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

Commit e3a2ecf

Browse files
committed
revert: refactor($compile): automatically append end comment nodes to all element-transclusion templates
This reverts commit 0d608d0. The commits caused more breaking changes at Google than initially expected and since its benefit is small, so it's not worth keeping.
1 parent 63249a0 commit e3a2ecf

File tree

5 files changed

+10
-12
lines changed

5 files changed

+10
-12
lines changed

src/ng/compile.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,9 +1305,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
13051305
compileNode = $compileNode[0];
13061306
replaceWith(jqCollection, sliceArgs($template), compileNode);
13071307

1308-
$template[$template.length++] = document.createComment(' end ' + directiveName + ': ' +
1309-
templateAttrs[directiveName] + ' ');
1310-
13111308
childTranscludeFn = compile($template, transcludeFn, terminalPriority,
13121309
replaceDirective && replaceDirective.name, {
13131310
// Don't pass in:

src/ng/directive/ngIf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ var ngIfDirective = ['$animate', function($animate) {
9292
if (!childScope) {
9393
$transclude(function (clone, newScope) {
9494
childScope = newScope;
95+
clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' ');
9596
// Note: We only need the first/last node of the cloned nodes.
9697
// However, we need to keep the reference to the jqlite wrapper as it might be changed later
9798
// by a directive with templateUrl when its template arrives.

src/ng/directive/ngRepeat.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
243243
$$tlb: true,
244244
compile: function ngRepeatCompile($element, $attr) {
245245
var expression = $attr.ngRepeat;
246+
var ngRepeatEndComment = document.createComment(' end ngRepeat: ' + expression + ' ');
247+
246248
var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);
247249

248250
if (!match) {
@@ -407,8 +409,11 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
407409
// new item which we don't know about
408410
$transclude(function ngRepeatTransclude(clone, scope) {
409411
block.scope = scope;
412+
// http://jsperf.com/clone-vs-createcomment
413+
var endNode = ngRepeatEndComment.cloneNode();
414+
clone[clone.length++] = endNode;
410415
$animate.enter(clone, null, jqLite(previousNode));
411-
previousNode = clone[clone.length - 1];
416+
previousNode = endNode;
412417
// Note: We only need the first/last node of the cloned nodes.
413418
// However, we need to keep the reference to the jqlite wrapper as it might be changed later
414419
// by a directive with templateUrl when its template arrives.

src/ng/directive/ngSwitch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ var ngSwitchDirective = ['$animate', function($animate) {
169169
selectedTransclude.transclude(function(caseElement, selectedScope) {
170170
selectedScopes.push(selectedScope);
171171
var anchor = selectedTransclude.element;
172+
caseElement[caseElement.length++] = document.createComment(' end ngSwitchWhen: ');
172173
var block = { clone: caseElement };
173174

174175
selectedElements.push(block);

test/ng/compileSpec.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4805,12 +4805,7 @@ describe('$compile', function() {
48054805
return function(scope, element, attrs, ctrl) {
48064806
log('link');
48074807
var cursor = element;
4808-
4809-
template(scope.$new(), function(clone) {
4810-
var nextCursor = clone.eq(1);
4811-
cursor.after(clone);
4812-
cursor = nextCursor;
4813-
});
4808+
template(scope.$new(), function(clone) {cursor.after(cursor = clone);});
48144809
ctrl.$transclude(function(clone) {cursor.after(clone);});
48154810
};
48164811
}
@@ -5115,10 +5110,9 @@ describe('$compile', function() {
51155110
"inner:#comment:innerAgain:"
51165111
]);
51175112
expect(child.length).toBe(1);
5118-
expect(child.contents().length).toBe(3);
5113+
expect(child.contents().length).toBe(2);
51195114
expect(lowercase(nodeName_(child.contents().eq(0)))).toBe('#comment');
51205115
expect(lowercase(nodeName_(child.contents().eq(1)))).toBe('div');
5121-
expect(lowercase(nodeName_(child.contents().eq(2)))).toBe('#comment');
51225116
});
51235117
});
51245118
});

0 commit comments

Comments
 (0)