// 判断组件内容是对象,调用extend方法生成组件构造函数 if (isObject(Ctor)) { Ctor = baseCtor.extend(CtorastypeofComponent) }
// 组件构造函数一定是一个构造函数,如果组件构造函数不是一个函数,直接报错非法的组件定义 if (typeofCtor !== 'function') { if (__DEV__) { warn(`Invalid Component definition: ${String(Ctor)}`, context) } return }
// 异步组件 let asyncFactory // @ts-expect-error if (isUndef(Ctor.cid)) { asyncFactory = Ctor Ctor = resolveAsyncComponent(asyncFactory, baseCtor) if (Ctor === undefined) { // return a placeholder node for async component, which is rendered // as a comment node but preserves all the raw information for the node. // the information will be used for async server-rendering and hydration. returncreateAsyncPlaceholder(asyncFactory, data, context, children, tag) } }
// 函数组件 if (isTrue(Ctor.options.functional)) { returncreateFunctionalComponent( CtorastypeofComponent, propsData, data, context, children ) }
// 监听器 const listeners = data.on // replace with listeners with .native modifier // so it gets processed during parent component patch. data.on = data.nativeOn
// @ts-expect-error if (isTrue(Ctor.options.abstract)) { // abstract components do not keep anything // other than props & listeners & slot
// work around flow const slot = data.slot data = {} if (slot) { data.slot = slot } }
// install component management hooks onto the placeholder node installComponentHooks(data)
// return a placeholder vnode // @ts-expect-error const name = getComponentName(Ctor.options) || tag const vnode = newVNode( // @ts-expect-error `vue-component-${Ctor.cid}${name ? `-${name}` : ''}`, data, undefined, undefined, undefined, context, // @ts-expect-error { Ctor, propsData, listeners, tag, children }, asyncFactory )