Skip to content

Commit e1603b6

Browse files
committed
fix: compile container directives in correct context (fix vuejs#1442)
1 parent 245986d commit e1603b6

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
@@ -180,10 +180,11 @@ exports.compileAndLinkProps = function (vm, el, props, scope) {
180180
* @param {Vue} vm
181181
* @param {Element} el
182182
* @param {Object} options
183+
* @param {Object} contextOptions
183184
* @return {Function}
184185
*/
185186

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

src/instance/lifecycle.js

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

3434
// root is always compiled per-instance, because
3535
// container attrs and props can be different every time.
36-
var rootLinker = compiler.compileRoot(el, options)
36+
var contextOptions = this._context && this._context.$options
37+
var rootLinker = compiler.compileRoot(el, options, contextOptions)
3738

3839
// compile and link the rest
3940
var contentLinkFn

test/unit/specs/compiler/compile_spec.js

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

551+
it('should compile component container directives using correct context', function () {
552+
new Vue({
553+
el: el,
554+
directives: {
555+
test: {
556+
bind: function () {
557+
this.el.textContent = 'worked!'
558+
}
559+
}
560+
},
561+
template: '<comp v-test></comp>',
562+
components: { comp: { template: '<div></div>'}}
563+
})
564+
expect(el.textContent).toBe('worked!')
565+
expect(_.warn).not.toHaveBeenCalled()
566+
})
567+
551568
})
552569
}

0 commit comments

Comments
 (0)