Evan You 12 лет назад
Родитель
Сommit
79f6193825
2 измененных файлов с 15 добавлено и 8 удалено
  1. 5 4
      src/main.js
  2. 10 4
      test/unit/specs/api.js

+ 5 - 4
src/main.js

@@ -154,13 +154,14 @@ function extend (options) {
  *  extension option, but only as an instance option.
  */
 function inheritOptions (child, parent, topLevel) {
-    child = child || makeHash()
+    child = child || {}
     if (!parent) return child
     for (var key in parent) {
         if (key === 'el' || key === 'methods') continue
         var val = child[key],
             parentVal = parent[key],
-            type = utils.typeOf(val)
+            type = utils.typeOf(val),
+            parentType = utils.typeOf(parentVal)
         if (topLevel && type === 'Function' && parentVal) {
             // merge hook functions into an array
             child[key] = [val]
@@ -169,9 +170,9 @@ function inheritOptions (child, parent, topLevel) {
             } else {
                 child[key].push(parentVal)
             }
-        } else if (topLevel && type === 'Object') {
+        } else if (topLevel && (type === 'Object' || parentType === 'Object')) {
             // merge toplevel object options
-            inheritOptions(val, parentVal)
+            child[key] = inheritOptions(val, parentVal)
         } else if (val === undefined) {
             // inherit if child doesn't override
             child[key] = parentVal

+ 10 - 4
test/unit/specs/api.js

@@ -373,11 +373,17 @@ describe('UNIT: API', function () {
         })
 
         it('should allow subclasses to attach private assets', function () {
+            var testId = 'sub-private'
             var Sub = Vue.extend({})
-            Sub.component('test', {})
-            assert.strictEqual(Sub.options.components.test.super, Vue)
-            Sub.partial('test', '123')
-            assert.ok(Sub.options.partials.test instanceof window.DocumentFragment)
+            Sub.component(testId, {})
+            assert.strictEqual(Sub.options.components[testId].super, Vue)
+            Sub.partial(testId, '123')
+            assert.ok(Sub.options.partials[testId] instanceof window.DocumentFragment)
+
+            var Sub2 = Vue.extend({})
+            Sub2.component(testId, {})
+            assert.notStrictEqual(Sub.options.components[testId], Sub2.options.components[testId])
+            assert.notOk(Vue.options.components[testId])
         })
 
         it('should allow subclasses to use plugins', function () {