import { extend , looseEqual , looseIndexOf , NOOP , toDisplayString , toNumber } from '@vue/shared' ; import { ComponentPublicInstance , PublicPropertiesMap } from '../componentPublicInstance' ; import { getCompatChildren } from './instanceChildren' ; import { DeprecationTypes , assertCompatEnabled , isCompatEnabled } from './compatConfig' ; import { off , on , once } from './instanceEventEmitter' ; import { getCompatListeners } from './instanceListeners' ; import { shallowReadonly } from '@vue/reactivity' ; import { legacySlotProxyHandlers } from './componentFunctional' ; import { compatH } from './renderFn' ; import { createCommentVNode , createTextVNode } from '../vnode' ; import { renderList } from '../helpers/renderList' ; import { legacyBindDynamicKeys , legacyBindObjectListeners , legacyBindObjectProps , legacyCheckKeyCodes , legacyMarkOnce , legacyPrependModifier , legacyRenderSlot , legacyRenderStatic , legacyresolveScopedSlots } from './renderHelpers' ; import { resolveFilter } from '../helpers/resolveAssets' ; import { InternalSlots , Slots } from '../componentSlots' ; import { ContextualRenderFn } from '../componentRenderContext' ; import { resolveMergedOptions } from '../componentOptions' ; export type LegacyPublicInstance = ComponentPublicInstance & LegacyPublicProperties ; export interface LegacyPublicProperties { $set ( target , key , value ) : void ; $delete ( target , key ) : void ; $mount ( el ? ) : this ; $destroy ( ) : void ; $scopedSlots : Slots ; $on ( event , fn ) : this ; $once ( event , fn ) : this ; $off ( event ? , fn ? ) : this ; $children : LegacyPublicProperties [ ] ; $listeners : Record < string , Function | Function [ ] > ; } export function installCompatInstanceProperties ( map ) { const set = ( target , key , val ) => { target [ key ] = val ; } ; const del = ( target , key ) => { delete target [ key ] ; } ; extend ( map , { $set : i => { assertCompatEnabled ( DeprecationTypes . INSTANCE_SET , i ) ; return set ; } , $delete : i => { assertCompatEnabled ( DeprecationTypes . INSTANCE_DELETE , i ) ; return del ; } , $mount : i => { assertCompatEnabled ( DeprecationTypes . GLOBAL_MOUNT , null ) ; return i . ctx . _compat_mount || NOOP ; } , $destroy : i => { assertCompatEnabled ( DeprecationTypes . INSTANCE_DESTROY , i ) ; return i . ctx . _compat_destroy || NOOP ; } , $slots : i => { if ( isCompatEnabled ( DeprecationTypes . RENDER_FUNCTION , i ) && i . render && i . render . _compatWrapped ) { return new Proxy ( i . slots , legacySlotProxyHandlers ) ; } return __DEV__ ? shallowReadonly ( i . slots ) : i . slots ; } , $scopedSlots : i => { assertCompatEnabled ( DeprecationTypes . INSTANCE_SCOPED_SLOTS , i ) ; const res = { } ; for ( const key in i . slots ) { const fn = i . slots [ key ] ! ; if ( ! ( fn as ContextualRenderFn ) . _ns ) { res [ key ] = fn ; } } return res ; } , $on : i => on . bind ( null , i ) , $once : i => once . bind ( null , i ) , $off : i => off . bind ( null , i ) , $children : getCompatChildren , $listeners : getCompatListeners } as PublicPropertiesMap ) ; if ( isCompatEnabled ( DeprecationTypes . PRIVATE_APIS , null ) ) { extend ( map , { $vnode : i => i . vnode , $options : i => { const res = extend ( { } , resolveMergedOptions ( i ) ) ; res . parent = i . proxy ! . $parent ; res . propsData = i . vnode . props ; return res ; } , _self : i => i . proxy , _uid : i => i . uid , _data : i => i . data , _isMounted : i => i . isMounted , _isDestroyed : i => i . isUnmounted , $createElement : ( ) => compatH , _c : ( ) => compatH , _o : ( ) => legacyMarkOnce , _n : ( ) => toNumber , _s : ( ) => toDisplayString , _l : ( ) => renderList , _t : i => legacyRenderSlot . bind ( null , i ) , _q : ( ) => looseEqual , _i : ( ) => looseIndexOf , _m : i => legacyRenderStatic . bind ( null , i ) , _f : ( ) => resolveFilter , _k : i => legacyCheckKeyCodes . bind ( null , i ) , _b : ( ) => legacyBindObjectProps , _v : ( ) => createTextVNode , _e : ( ) => createCommentVNode , _u : ( ) => legacyresolveScopedSlots , _g : ( ) => legacyBindObjectListeners , _d : ( ) => legacyBindDynamicKeys , _p : ( ) => legacyPrependModifier } as PublicPropertiesMap ) ; } }