Skip to content

Commit 7b84594

Browse files
committed
transcluded linkFns should be terminal
1 parent aba5228 commit 7b84594

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/compiler/compile.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function compile (el, options, partial, transcluded) {
5050
* @return {Function|undefined}
5151
*/
5252

53-
return function link (vm, el) {
53+
function linkFn (vm, el) {
5454
var originalDirCount = vm._directives.length
5555
var parentOriginalDirCount =
5656
vm.$parent && vm.$parent._directives.length
@@ -65,6 +65,7 @@ function compile (el, options, partial, transcluded) {
6565
// passed down.
6666
var source = transcluded ? vm.$parent : vm
6767
var host = transcluded ? vm : undefined
68+
// link
6869
if (nodeLinkFn) nodeLinkFn(source, el, host)
6970
if (childLinkFn) childLinkFn(source, childNodes, host)
7071

@@ -97,6 +98,14 @@ function compile (el, options, partial, transcluded) {
9798
}
9899
}
99100
}
101+
102+
// transcluded linkFns are terminal, because it takes
103+
// over the entire sub-tree.
104+
if (transcluded) {
105+
linkFn.terminal = true
106+
}
107+
108+
return linkFn
100109
}
101110

102111
/**

test/unit/specs/compiler/compile_spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,40 @@ if (_.inBrowser) {
204204
expect(vm._bindDir.calls.count()).toBe(0)
205205
})
206206

207+
it('should handle nested transclusions', function (done) {
208+
vm = new Vue({
209+
el: el,
210+
template:
211+
'<div v-component="a">' +
212+
'<div v-component="b">' +
213+
'<div v-repeat="list">{{$value}}</div>' +
214+
'</div>' +
215+
'</div>',
216+
data: {
217+
list: [1,2]
218+
},
219+
components: {
220+
a: { template: '<content></content>' },
221+
b: { template: '<content></content>' }
222+
}
223+
})
224+
expect(el.innerHTML).toBe(
225+
'<div><div>' +
226+
'<div>1</div><div>2</div><!--v-repeat-->' +
227+
'</div><!--v-component-->' +
228+
'</div><!--v-component-->'
229+
)
230+
vm.list.push(3)
231+
_.nextTick(function () {
232+
expect(el.innerHTML).toBe(
233+
'<div><div>' +
234+
'<div>1</div><div>2</div><div>3</div><!--v-repeat-->' +
235+
'</div><!--v-component-->' +
236+
'</div><!--v-component-->'
237+
)
238+
done()
239+
})
240+
})
241+
207242
})
208243
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy