import { Component } from 'types/component' import { PropOptions } from 'types/options' import { popTarget, pushTarget } from '../core/observer/dep' import { def, invokeWithErrorHandling, isReserved, warn } from '../core/util' import VNode from '../core/vdom/vnode' import { bind, emptyObject, isArray, isFunction, isObject } from '../shared/util' import { currentInstance, setCurrentInstance } from './currentInstance' import { shallowReactive } from './reactivity/reactive' import { proxyWithRefUnwrap } from './reactivity/ref' /** * @internal */ export interface SetupContext { attrs: Record listeners: Record slots: Record VNode[]> emit: (event: string, ...args: any[]) => any expose: (exposed: Record) => void } export function initSetup(vm: Component) { const options = vm.$options const setup = options.setup if (setup) { const ctx = (vm._setupContext = createSetupContext(vm)) setCurrentInstance(vm) pushTarget() const setupResult = invokeWithErrorHandling( setup, null, [vm._props || shallowReactive({}), ctx], vm, `setup` ) popTarget() setCurrentInstance() if (isFunction(setupResult)) { // render function // @ts-ignore options.render = setupResult } else if (isObject(setupResult)) { // bindings if (__DEV__ && setupResult instanceof VNode) { warn( `setup() should not return VNodes directly - ` + `return a render function instead.` ) } vm._setupState = setupResult // __sfc indicates compiled bindings from