Skip to content

Commit 84ff786

Browse files
committed
WIP: squash
1 parent 3be21e1 commit 84ff786

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/ng/compile.js

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -956,12 +956,14 @@ function $CompileProvider($provide) {
956956

957957
function createBoundTranscludeFn(scope, transcludeFn) {
958958
return function boundTranscludeFn(transcludedScope, cloneFn, controllers) {
959-
var scopeCreated;
959+
var scopeCreated = false;
960+
960961
if (!transcludedScope) {
961962
transcludedScope = scope.$new();
962963
transcludedScope.$$transcluded = true;
963964
scopeCreated = true;
964965
}
966+
965967
var clone = transcludeFn(transcludedScope, cloneFn, controllers);
966968
if (scopeCreated) {
967969
clone.on('$destroy', bind(transcludedScope, transcludedScope.$destroy));
@@ -1381,7 +1383,7 @@ function $CompileProvider($provide) {
13811383

13821384

13831385
function nodeLinkFn(childLinkFn, scope, linkNode, $rootElement, boundTranscludeFn) {
1384-
var attrs, $element, i, ii, linkFn, controller, isolateScope, elementControllers = {}, $transclude;
1386+
var attrs, $element, i, ii, linkFn, controller, isolateScope, elementControllers = {}, transcludeFn;
13851387

13861388
if (compileNode === linkNode) {
13871389
attrs = templateAttrs;
@@ -1475,14 +1477,14 @@ function $CompileProvider($provide) {
14751477
}
14761478
});
14771479
}
1478-
$transclude = boundTranscludeFn && controllerBoundTransclude;
1480+
transcludeFn = boundTranscludeFn && controllersBoundTransclude;
14791481
if (controllerDirectives) {
14801482
forEach(controllerDirectives, function(directive) {
14811483
var locals = {
14821484
$scope: directive === newIsolateScopeDirective || directive.$$isolateScope ? isolateScope : scope,
14831485
$element: $element,
14841486
$attrs: attrs,
1485-
$transclude: $transclude
1487+
$transclude: transcludeFn
14861488
}, controllerInstance;
14871489

14881490
controller = directive.controller;
@@ -1492,9 +1494,10 @@ function $CompileProvider($provide) {
14921494

14931495
controllerInstance = $controller(controller, locals);
14941496
// For directives with element transclusion the element is a comment,
1495-
// but jQuery .data doesn't support
1496-
// attaching data to comment nodes as it's hard to clean up (http://bugs.jquery.com/ticket/8335)
1497-
// so instead we save the direct controllers for the element in a local hash.
1497+
// but jQuery .data doesn't support attaching data to comment nodes as it's hard to
1498+
// clean up (http://bugs.jquery.com/ticket/8335).
1499+
// Instead, we save the controllers for the element in a local hash and attach to .data
1500+
// later, once we have the actual element.
14981501
elementControllers[directive.name] = controllerInstance;
14991502
if (!hasElementTranscludeDirective) {
15001503
$element.data('$' + directive.name + 'Controller', controllerInstance);
@@ -1511,7 +1514,7 @@ function $CompileProvider($provide) {
15111514
try {
15121515
linkFn = preLinkFns[i];
15131516
linkFn(linkFn.isolateScope ? isolateScope : scope, $element, attrs,
1514-
linkFn.require && getControllers(linkFn.require, $element, elementControllers), $transclude);
1517+
linkFn.require && getControllers(linkFn.require, $element, elementControllers), transcludeFn);
15151518
} catch (e) {
15161519
$exceptionHandler(e, startingTag($element));
15171520
}
@@ -1531,28 +1534,26 @@ function $CompileProvider($provide) {
15311534
try {
15321535
linkFn = postLinkFns[i];
15331536
linkFn(linkFn.isolateScope ? isolateScope : scope, $element, attrs,
1534-
linkFn.require && getControllers(linkFn.require, $element, elementControllers), $transclude);
1537+
linkFn.require && getControllers(linkFn.require, $element, elementControllers), transcludeFn);
15351538
} catch (e) {
15361539
$exceptionHandler(e, startingTag($element));
15371540
}
15381541
}
15391542

1540-
function controllerBoundTransclude() {
1541-
var scope, cloneAttachFn, transcludeControllers;
1542-
if (!boundTranscludeFn) {
1543-
return;
1544-
}
1543+
// This is the function that is injected as `$transclude`.
1544+
function controllersBoundTransclude(scope, cloneAttachFn) {
1545+
var transcludeControllers;
1546+
1547+
// no scope passed
15451548
if (arguments.length < 2) {
1546-
// no scope but cloneAttachFn
1547-
cloneAttachFn = arguments[0];
1548-
} else {
1549-
// scope and cloneAttachFn (e.g. for ngIf)
1550-
scope = arguments[0];
1551-
cloneAttachFn = arguments[1];
1549+
cloneAttachFn = scope;
1550+
scope = undefined;
15521551
}
1552+
15531553
if (hasElementTranscludeDirective) {
15541554
transcludeControllers = elementControllers;
15551555
}
1556+
15561557
return boundTranscludeFn(scope, cloneAttachFn, transcludeControllers);
15571558
}
15581559
}

0 commit comments

Comments
 (0)