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

Commit

Permalink
revert: refactor($compile): automatically append end comment nodes to…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
IgorMinar committed Aug 19, 2014
1 parent 63249a0 commit e3a2ecf
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
3 changes: 0 additions & 3 deletions src/ng/compile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/ng/directive/ngIf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 6 additions & 1 deletion src/ng/directive/ngRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/ng/directive/ngSwitch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 2 additions & 8 deletions test/ng/compileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);});
};
}
Expand Down Expand Up @@ -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');
});
});
});
Expand Down

0 comments on commit e3a2ecf

Please sign in to comment.