Skip to content

Commit d0faa07

Browse files
committed
fix #615 parent not skipping paramAttributes
1 parent 51cfffb commit d0faa07

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

src/compiler/compile.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ var templateParser = require('../parsers/template')
1919
* @param {Element|DocumentFragment} el
2020
* @param {Object} options
2121
* @param {Boolean} partial
22-
* @param {Boolean} asParent
22+
* @param {Boolean} asParent - compiling a component
23+
* container as its parent.
2324
* @return {Function}
2425
*/
2526

@@ -509,6 +510,10 @@ function collectDirectives (el, options, asParent) {
509510
*/
510511

511512
function collectAttrDirective (el, name, value, options) {
513+
if (options._skipAttrs &&
514+
options._skipAttrs.indexOf(name) > -1) {
515+
return
516+
}
512517
var tokens = textParser.parse(value)
513518
if (tokens) {
514519
var def = options.directives.attr

src/instance/compile.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var transclude = require('../compiler/transclude')
1818

1919
exports._compile = function (el) {
2020
var options = this.$options
21+
var parent = options._parent
2122
if (options._linkFn) {
2223
this._initElement(el)
2324
options._linkFn(this, el)
@@ -27,20 +28,26 @@ exports._compile = function (el) {
2728
// separate container element and content
2829
var content = options._content = _.extractContent(raw)
2930
// create two separate linekrs for container and content
31+
var parentOptions = parent.$options
32+
33+
// hack: we need to skip the paramAttributes for this
34+
// child instance when compiling its parent container
35+
// linker. there could be a better way to do this.
36+
parentOptions._skipAttrs = options.paramAttributes
3037
var containerLinkFn =
31-
compile(raw, options, true, true)
38+
compile(raw, parentOptions, true, true)
39+
parentOptions._skipAttrs = null
40+
3241
if (content) {
3342
var contentLinkFn =
34-
compile(content, options, true, true)
43+
compile(content, parentOptions, true)
3544
// call content linker now, before transclusion
36-
this._contentUnlinkFn =
37-
contentLinkFn(options._parent, content)
45+
this._contentUnlinkFn = contentLinkFn(parent, content)
3846
}
3947
// tranclude, this possibly replaces original
4048
el = transclude(el, options)
4149
// now call the container linker on the resolved el
42-
this._containerUnlinkFn =
43-
containerLinkFn(options._parent, el)
50+
this._containerUnlinkFn = containerLinkFn(parent, el)
4451
} else {
4552
// simply transclude
4653
el = transclude(el, options)

test/unit/specs/directives/component_spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,23 @@ if (_.inBrowser) {
200200
})
201201
})
202202

203+
it('paramAttributes', function () {
204+
var vm = new Vue({
205+
el: el,
206+
data: {
207+
list: [{a:1}, {a:2}]
208+
},
209+
template: '<ul v-component="test" collection="{{list}}"></ul>',
210+
components: {
211+
test: {
212+
template: '<li v-repeat="collection">{{a}}</li>',
213+
paramAttributes: ['collection']
214+
}
215+
}
216+
})
217+
expect(el.innerHTML).toBe('<ul><li>1</li><li>2</li><!--v-repeat--></ul><!--v-component-->')
218+
})
219+
203220
it('wait-for', function (done) {
204221
var vm = new Vue({
205222
el: el,

0 commit comments

Comments
 (0)