revert: refactor($compile): automatically append end comment nodes to all element-transclusion templates

This reverts commit 0d608d041f.

The commits caused more breaking changes at Google than initially expected and since its
benefit is small, so it's not worth keeping.
This commit is contained in:
Igor Minar
2014-08-19 10:56:27 -07:00
parent 63249a0aaf
commit e3a2ecf0db
5 changed files with 10 additions and 12 deletions

View File

@@ -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:

View File

@@ -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.

View File

@@ -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.

View File

@@ -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);

View File

@@ -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');
});
});
});