Browse Source

fix #615 parent not skipping paramAttributes

Evan You 11 years ago
parent
commit
d0faa07d42
3 changed files with 36 additions and 7 deletions
  1. 6 1
      src/compiler/compile.js
  2. 13 6
      src/instance/compile.js
  3. 17 0
      test/unit/specs/directives/component_spec.js

+ 6 - 1
src/compiler/compile.js

@@ -19,7 +19,8 @@ var templateParser = require('../parsers/template')
  * @param {Element|DocumentFragment} el
  * @param {Object} options
  * @param {Boolean} partial
- * @param {Boolean} asParent
+ * @param {Boolean} asParent - compiling a component
+ *                             container as its parent.
  * @return {Function}
  */
 
@@ -509,6 +510,10 @@ function collectDirectives (el, options, asParent) {
  */
 
 function collectAttrDirective (el, name, value, options) {
+  if (options._skipAttrs &&
+      options._skipAttrs.indexOf(name) > -1) {
+    return
+  }
   var tokens = textParser.parse(value)
   if (tokens) {
     var def = options.directives.attr

+ 13 - 6
src/instance/compile.js

@@ -18,6 +18,7 @@ var transclude = require('../compiler/transclude')
 
 exports._compile = function (el) {
   var options = this.$options
+  var parent = options._parent
   if (options._linkFn) {
     this._initElement(el)
     options._linkFn(this, el)
@@ -27,20 +28,26 @@ exports._compile = function (el) {
       // separate container element and content
       var content = options._content = _.extractContent(raw)
       // create two separate linekrs for container and content
+      var parentOptions = parent.$options
+      
+      // hack: we need to skip the paramAttributes for this
+      // child instance when compiling its parent container
+      // linker. there could be a better way to do this.
+      parentOptions._skipAttrs = options.paramAttributes
       var containerLinkFn =
-        compile(raw, options, true, true)
+        compile(raw, parentOptions, true, true)
+      parentOptions._skipAttrs = null
+
       if (content) {
         var contentLinkFn =
-          compile(content, options, true, true)
+          compile(content, parentOptions, true)
         // call content linker now, before transclusion
-        this._contentUnlinkFn =
-          contentLinkFn(options._parent, content)
+        this._contentUnlinkFn = contentLinkFn(parent, content)
       }
       // tranclude, this possibly replaces original
       el = transclude(el, options)
       // now call the container linker on the resolved el
-      this._containerUnlinkFn =
-        containerLinkFn(options._parent, el)
+      this._containerUnlinkFn = containerLinkFn(parent, el)
     } else {
       // simply transclude
       el = transclude(el, options)

+ 17 - 0
test/unit/specs/directives/component_spec.js

@@ -200,6 +200,23 @@ if (_.inBrowser) {
       })
     })
 
+    it('paramAttributes', function () {
+      var vm = new Vue({
+        el: el,
+        data: {
+          list: [{a:1}, {a:2}]
+        },
+        template: '<ul v-component="test" collection="{{list}}"></ul>',
+        components: {
+          test: {
+            template: '<li v-repeat="collection">{{a}}</li>',
+            paramAttributes: ['collection']
+          }
+        }
+      })
+      expect(el.innerHTML).toBe('<ul><li>1</li><li>2</li><!--v-repeat--></ul><!--v-component-->')
+    })
+
     it('wait-for', function (done) {
       var vm = new Vue({
         el: el,