@@ -60,10 +60,13 @@ function compile (el, options, partial, transcluded) {
6060 }
6161 // cache childNodes before linking parent, fix #657
6262 var childNodes = _ . toArray ( el . childNodes )
63- // if transcluded, link in parent scope
64- if ( transcluded ) vm = vm . $parent
65- if ( nodeLinkFn ) nodeLinkFn ( vm , el )
66- if ( childLinkFn ) childLinkFn ( vm , childNodes )
63+ // if this is a transcluded compile, linkers need to be
64+ // called in source scope, and the host needs to be
65+ // passed down.
66+ var source = transcluded ? vm . $parent : vm
67+ var host = transcluded ? vm : undefined
68+ if ( nodeLinkFn ) nodeLinkFn ( source , el , host )
69+ if ( childLinkFn ) childLinkFn ( source , childNodes , host )
6770
6871 /**
6972 * If this is a partial compile, the linker function
@@ -150,7 +153,7 @@ function compileElement (el, options) {
150153 if ( ! linkFn ) {
151154 var dirs = collectDirectives ( el , options )
152155 linkFn = dirs . length
153- ? makeDirectivesLinkFn ( dirs )
156+ ? makeNodeLinkFn ( dirs )
154157 : null
155158 }
156159 }
@@ -168,14 +171,14 @@ function compileElement (el, options) {
168171}
169172
170173/**
171- * Build a multi-directive link function.
174+ * Build a link function for all directives on a single node .
172175 *
173176 * @param {Array } directives
174177 * @return {Function } directivesLinkFn
175178 */
176179
177- function makeDirectivesLinkFn ( directives ) {
178- return function directivesLinkFn ( vm , el ) {
180+ function makeNodeLinkFn ( directives ) {
181+ return function nodeLinkFn ( vm , el , host ) {
179182 // reverse apply because it's sorted low to high
180183 var i = directives . length
181184 var dir , j , k , target
@@ -193,7 +196,7 @@ function makeDirectivesLinkFn (directives) {
193196 k = dir . descriptors . length
194197 for ( j = 0 ; j < k ; j ++ ) {
195198 target . _bindDir ( dir . name , el ,
196- dir . descriptors [ j ] , dir . def )
199+ dir . descriptors [ j ] , dir . def , host )
197200 }
198201 }
199202 }
@@ -465,13 +468,16 @@ function checkTerminalDirectives (el, options) {
465468 for ( var i = 0 ; i < 3 ; i ++ ) {
466469 dirName = terminalDirectives [ i ]
467470 if ( value = _ . attr ( el , dirName ) ) {
468- return makeTeriminalLinkFn ( el , dirName , value , options )
471+ return makeTerminalNodeLinkFn ( el , dirName , value , options )
469472 }
470473 }
471474}
472475
473476/**
474- * Build a link function for a terminal directive.
477+ * Build a node link function for a terminal directive.
478+ * A terminal link function terminates the current
479+ * compilation recursion and handles compilation of the
480+ * subtree in the directive.
475481 *
476482 * @param {Element } el
477483 * @param {String } dirName
@@ -480,14 +486,14 @@ function checkTerminalDirectives (el, options) {
480486 * @return {Function } terminalLinkFn
481487 */
482488
483- function makeTeriminalLinkFn ( el , dirName , value , options ) {
489+ function makeTerminalNodeLinkFn ( el , dirName , value , options ) {
484490 var descriptor = dirParser . parse ( value ) [ 0 ]
485491 var def = options . directives [ dirName ]
486- var terminalLinkFn = function ( vm , el ) {
487- vm . _bindDir ( dirName , el , descriptor , def )
492+ var fn = function terminalNodeLinkFn ( vm , el , host ) {
493+ vm . _bindDir ( dirName , el , descriptor , def , host )
488494 }
489- terminalLinkFn . terminal = true
490- return terminalLinkFn
495+ fn . terminal = true
496+ return fn
491497}
492498
493499/**
0 commit comments