angular.js/test/ng
Vojta Jina 742271ffa3 fix($compile): link parents before traversing
How did compiling a templateUrl (async) directive with `replace:true` work before this commit?
1/ apply all directives with higher priority than the templateUrl directive
2/ partially apply the templateUrl directive (create `beforeTemplateNodeLinkFn`)
3/ fetch the template
4/ apply second part of the templateUrl directive on the fetched template
(`afterTemplateNodeLinkFn`)

That is, the templateUrl directive is basically split into two parts (two `nodeLinkFn` functions),
which has to be both applied.

Normally we compose linking functions (`nodeLinkFn`) using continuation - calling the linking
function of a parent element, passing the linking function of the child elements as an argument. The
parent linking function then does:
1/ execute its pre-link functions
2/ call the child elements linking function (traverse)
3/ execute its post-link functions

Now, we have two linking functions for the same DOM element level (because the templateUrl directive
has been split).

There has been multiple issues because of the order of these two linking functions (creating
controller before setting up scope locals, running linking functions before instantiating
controller, etc.). It is easy to fix one use case, but it breaks some other use case. It is hard to
decide what is the "correct" order of these two linking functions as they are essentially on the
same level.

Running them side-by-side screws up pre/post linking functions for the high priority directives
(those executed before the templateUrl directive). It runs post-linking functions before traversing:
```js
beforeTemplateNodeLinkFn(null); // do not travers
afterTemplateNodeLinkFn(afterTemplateChildLinkFn);
```

Composing them (in any order) screws up the order of post-linking functions. We could fix this by
having post-linking functions to execute in reverse order (from the lowest priority to the highest)
which might actually make a sense.

**My solution is to remove this splitting.** This commit removes the `beforeTemplateNodeLinkFn`. The
first run (before we have the template) only schedules fetching the template. The rest (creating
scope locals, instantiating a controller, linking functions, etc) is done when processing the
directive again (in the context of the already fetched template; this is the cloned
`derivedSyncDirective`).

We still need to pass-through the linking functions of the higher priority directives (those
executed before the templateUrl directive), that's why I added `preLinkFns` and `postLinkFns`
arguments to `applyDirectivesToNode`.

This also changes the "$compile transclude should make the result of a transclusion available to the
parent directive in post- linking phase (templateUrl)" unit test. It was testing that a parent
directive can see the content of transclusion in its pre-link function. That is IMHO wrong (as the
`ngTransclude` directive inserts the translusion in its linking function). This test was only passing because of
c173ca4128, which changed the behavior of the compiler to traverse
before executing the parent linking function. That was wrong and also caused the #3792 issue, which
this change fixes.

Closes #3792
Closes #3923
Closes #3935
Closes #3927
2013-09-30 15:30:29 -07:00
..
directive fix(ngRepeat): correctly track elements even when the collection is initially undefined 2013-09-25 09:42:01 -07:00
filter fix(filter): filter on false properties 2013-08-15 15:50:34 -07:00
anchorScrollSpec.js fix($sniffer): report history false on Android < 4 2012-05-14 15:12:51 -07:00
animateSpec.js fix(jqLite): use get/setAttribute so that jqLite works on SVG nodes 2013-09-27 12:38:27 -07:00
browserSpecs.js fix($browser): should use first value for a cookie. 2013-05-11 09:28:14 -07:00
cacheFactorySpec.js feat(minerr): log minerr doc url in development 2013-08-15 13:23:18 -07:00
compileSpec.js fix($compile): link parents before traversing 2013-09-30 15:30:29 -07:00
controllerSpec.js feat(minerr): log minerr doc url in development 2013-08-15 13:23:18 -07:00
documentSpec.js chore(module): move files around in preparation for more modules 2012-03-28 11:16:35 -07:00
exceptionHandlerSpec.js chore(module): move files around in preparation for more modules 2012-03-28 11:16:35 -07:00
httpBackendSpec.js test: rename / remove duplicate unit tests 2013-08-23 12:43:42 -07:00
httpSpec.js fix($http): allow empty responses to be cached 2013-09-02 11:47:51 +02:00
interpolateSpec.js feat(minerr): log minerr doc url in development 2013-08-15 13:23:18 -07:00
localeSpec.js chore(module): move files around in preparation for more modules 2012-03-28 11:16:35 -07:00
locationSpec.js feat(minerr): log minerr doc url in development 2013-08-15 13:23:18 -07:00
logSpec.js fix(log): prevent logging undefined for $log in IE 2013-09-27 16:44:21 -07:00
parseSpec.js fix($parse): disallow access to window and dom in expressions 2013-09-17 18:15:49 -07:00
qSpec.js fix($q): reject should catch & forward exceptions thrown in errback 2013-08-24 12:49:46 -07:00
rootElementSpec.js feat($rootElement): added application root element 2012-06-02 14:50:58 -07:00
rootScopeSpec.js chore($rootScope): provide support to execute a function after the digest cycle is complete 2013-09-03 17:06:49 -07:00
sceSpecs.js test: rename / remove duplicate unit tests 2013-08-23 12:43:42 -07:00
snifferSpec.js fix(core): parse IE11 UA string correctly 2013-08-29 16:07:49 -07:00
timeoutSpec.js revert: feat(mocks): make $timeout#flush throw an exception when empty 2013-08-27 17:23:36 -07:00
urlUtilsSpec.js feat($sce): new $sce service for Strict Contextual Escaping. 2013-07-25 13:00:35 -07:00
windowSpec.js chore(module): move files around in preparation for more modules 2012-03-28 11:16:35 -07:00