Skip to content

Commit 9c45702

Browse files
committed
fix: compile container directives in correct context (fix #1442)
1 parent d0f8579 commit 9c45702

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/compiler/compile.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,11 @@ exports.compileAndLinkProps = function (vm, el, props, scope) {
179179
* @param {Vue} vm
180180
* @param {Element} el
181181
* @param {Object} options
182+
* @param {Object} contextOptions
182183
* @return {Function}
183184
*/
184185

185-
exports.compileRoot = function (el, options) {
186+
exports.compileRoot = function (el, options, contextOptions) {
186187
var containerAttrs = options._containerAttrs
187188
var replacerAttrs = options._replacerAttrs
188189
var contextLinkFn, replacerLinkFn
@@ -194,8 +195,8 @@ exports.compileRoot = function (el, options) {
194195
// compiled separately and linked in different scopes.
195196
if (options._asComponent) {
196197
// 2. container attributes
197-
if (containerAttrs) {
198-
contextLinkFn = compileDirectives(containerAttrs, options)
198+
if (containerAttrs && contextOptions) {
199+
contextLinkFn = compileDirectives(containerAttrs, contextOptions)
199200
}
200201
if (replacerAttrs) {
201202
// 3. replacer attributes

src/instance/lifecycle.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ exports._compile = function (el) {
2929

3030
// root is always compiled per-instance, because
3131
// container attrs and props can be different every time.
32-
var rootLinker = compiler.compileRoot(el, options)
32+
var contextOptions = this._context && this._context.$options
33+
var rootLinker = compiler.compileRoot(el, options, contextOptions)
3334

3435
// compile and link the rest
3536
var contentLinkFn

test/unit/specs/compiler/compile_spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,5 +528,22 @@ if (_.inBrowser) {
528528
expect(hasWarned(_, 'v-show is ignored on component <test>')).toBe(true)
529529
})
530530

531+
it('should compile component container directives using correct context', function () {
532+
new Vue({
533+
el: el,
534+
directives: {
535+
test: {
536+
bind: function () {
537+
this.el.textContent = 'worked!'
538+
}
539+
}
540+
},
541+
template: '<comp v-test></comp>',
542+
components: { comp: { template: '<div></div>'}}
543+
})
544+
expect(el.textContent).toBe('worked!')
545+
expect(_.warn).not.toHaveBeenCalled()
546+
})
547+
531548
})
532549
}

0 commit comments

Comments
 (0)