Skip to content

Commit 79f6193

Browse files
committed
fix vuejs#129
1 parent 774161b commit 79f6193

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/main.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,14 @@ function extend (options) {
154154
* extension option, but only as an instance option.
155155
*/
156156
function inheritOptions (child, parent, topLevel) {
157-
child = child || makeHash()
157+
child = child || {}
158158
if (!parent) return child
159159
for (var key in parent) {
160160
if (key === 'el' || key === 'methods') continue
161161
var val = child[key],
162162
parentVal = parent[key],
163-
type = utils.typeOf(val)
163+
type = utils.typeOf(val),
164+
parentType = utils.typeOf(parentVal)
164165
if (topLevel && type === 'Function' && parentVal) {
165166
// merge hook functions into an array
166167
child[key] = [val]
@@ -169,9 +170,9 @@ function inheritOptions (child, parent, topLevel) {
169170
} else {
170171
child[key].push(parentVal)
171172
}
172-
} else if (topLevel && type === 'Object') {
173+
} else if (topLevel && (type === 'Object' || parentType === 'Object')) {
173174
// merge toplevel object options
174-
inheritOptions(val, parentVal)
175+
child[key] = inheritOptions(val, parentVal)
175176
} else if (val === undefined) {
176177
// inherit if child doesn't override
177178
child[key] = parentVal

test/unit/specs/api.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,11 +373,17 @@ describe('UNIT: API', function () {
373373
})
374374

375375
it('should allow subclasses to attach private assets', function () {
376+
var testId = 'sub-private'
376377
var Sub = Vue.extend({})
377-
Sub.component('test', {})
378-
assert.strictEqual(Sub.options.components.test.super, Vue)
379-
Sub.partial('test', '123')
380-
assert.ok(Sub.options.partials.test instanceof window.DocumentFragment)
378+
Sub.component(testId, {})
379+
assert.strictEqual(Sub.options.components[testId].super, Vue)
380+
Sub.partial(testId, '123')
381+
assert.ok(Sub.options.partials[testId] instanceof window.DocumentFragment)
382+
383+
var Sub2 = Vue.extend({})
384+
Sub2.component(testId, {})
385+
assert.notStrictEqual(Sub.options.components[testId], Sub2.options.components[testId])
386+
assert.notOk(Vue.options.components[testId])
381387
})
382388

383389
it('should allow subclasses to use plugins', function () {

0 commit comments

Comments
 (0)