From e3a2ecf0dbd05c797b4fa8003ef851669c19692c Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 19 Aug 2014 10:56:27 -0700 Subject: [PATCH] revert: refactor($compile): automatically append end comment nodes to all element-transclusion templates This reverts commit 0d608d041f37a659d8d8ba7a9b688e132587035d. The commits caused more breaking changes at Google than initially expected and since its benefit is small, so it's not worth keeping. --- src/ng/compile.js | 3 --- src/ng/directive/ngIf.js | 1 + src/ng/directive/ngRepeat.js | 7 ++++++- src/ng/directive/ngSwitch.js | 1 + test/ng/compileSpec.js | 10 ++-------- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/ng/compile.js b/src/ng/compile.js index 48294abb..51fa507b 100644 --- a/src/ng/compile.js +++ b/src/ng/compile.js @@ -1305,9 +1305,6 @@ function $CompileProvider($provide, $$sanitizeUriProvider) { compileNode = $compileNode[0]; replaceWith(jqCollection, sliceArgs($template), compileNode); - $template[$template.length++] = document.createComment(' end ' + directiveName + ': ' + - templateAttrs[directiveName] + ' '); - childTranscludeFn = compile($template, transcludeFn, terminalPriority, replaceDirective && replaceDirective.name, { // Don't pass in: diff --git a/src/ng/directive/ngIf.js b/src/ng/directive/ngIf.js index 281435d0..104423b4 100644 --- a/src/ng/directive/ngIf.js +++ b/src/ng/directive/ngIf.js @@ -92,6 +92,7 @@ var ngIfDirective = ['$animate', function($animate) { if (!childScope) { $transclude(function (clone, newScope) { childScope = newScope; + clone[clone.length++] = document.createComment(' end ngIf: ' + $attr.ngIf + ' '); // Note: We only need the first/last node of the cloned nodes. // However, we need to keep the reference to the jqlite wrapper as it might be changed later // by a directive with templateUrl when its template arrives. diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index 10ec9f57..1d7d516f 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -243,6 +243,8 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { $$tlb: true, compile: function ngRepeatCompile($element, $attr) { var expression = $attr.ngRepeat; + var ngRepeatEndComment = document.createComment(' end ngRepeat: ' + expression + ' '); + 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*$/); if (!match) { @@ -407,8 +409,11 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { // new item which we don't know about $transclude(function ngRepeatTransclude(clone, scope) { block.scope = scope; + // http://jsperf.com/clone-vs-createcomment + var endNode = ngRepeatEndComment.cloneNode(); + clone[clone.length++] = endNode; $animate.enter(clone, null, jqLite(previousNode)); - previousNode = clone[clone.length - 1]; + previousNode = endNode; // Note: We only need the first/last node of the cloned nodes. // However, we need to keep the reference to the jqlite wrapper as it might be changed later // by a directive with templateUrl when its template arrives. diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index 55c4512a..93e5bfe7 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -169,6 +169,7 @@ var ngSwitchDirective = ['$animate', function($animate) { selectedTransclude.transclude(function(caseElement, selectedScope) { selectedScopes.push(selectedScope); var anchor = selectedTransclude.element; + caseElement[caseElement.length++] = document.createComment(' end ngSwitchWhen: '); var block = { clone: caseElement }; selectedElements.push(block); diff --git a/test/ng/compileSpec.js b/test/ng/compileSpec.js index 2e703999..a416592d 100755 --- a/test/ng/compileSpec.js +++ b/test/ng/compileSpec.js @@ -4805,12 +4805,7 @@ describe('$compile', function() { return function(scope, element, attrs, ctrl) { log('link'); var cursor = element; - - template(scope.$new(), function(clone) { - var nextCursor = clone.eq(1); - cursor.after(clone); - cursor = nextCursor; - }); + template(scope.$new(), function(clone) {cursor.after(cursor = clone);}); ctrl.$transclude(function(clone) {cursor.after(clone);}); }; } @@ -5115,10 +5110,9 @@ describe('$compile', function() { "inner:#comment:innerAgain:" ]); expect(child.length).toBe(1); - expect(child.contents().length).toBe(3); + expect(child.contents().length).toBe(2); expect(lowercase(nodeName_(child.contents().eq(0)))).toBe('#comment'); expect(lowercase(nodeName_(child.contents().eq(1)))).toBe('div'); - expect(lowercase(nodeName_(child.contents().eq(2)))).toBe('#comment'); }); }); });