Skip to content

fix(setup): returning render function breaks when extending with an empty object #383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { VueConstructor } from 'vue'
*/
function mergeData(from: AnyObject, to: AnyObject): Object {
if (!from) return to
if (!to) return from

let key: any
let toVal: any
let fromVal: any
Expand Down Expand Up @@ -56,8 +58,8 @@ export function install(
) {
return function mergedSetupFn(props: any, context: any) {
return mergeData(
typeof parent === 'function' ? parent(props, context) || {} : {},
typeof child === 'function' ? child(props, context) || {} : {}
typeof parent === 'function' ? parent(props, context) || {} : undefined,
typeof child === 'function' ? child(props, context) || {} : undefined
)
}
}
Expand Down
12 changes: 12 additions & 0 deletions test/setup.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,4 +663,16 @@ describe('setup', () => {
expect(context).toBe(vm)
})
})

it('should work after extending with an undefined setup', () => {
const opts = {
setup() {
return () => h('div', 'Composition-api')
},
}
const Constructor = Vue.extend(opts).extend({})

const vm = new Vue(Constructor).$mount()
expect(vm.$el.textContent).toBe('Composition-api')
})
})