/**
 * Internal utilities.
 */ import Vue , { ComponentOptions , VueConstructor } from 'vue' ; const vueInternalPropNames = Object . getOwnPropertyNames ( new Vue ( ) ) ; const vueInternalHooks = [ 'data' , 'props' , 'watch' , 'beforeCreate' , 'created' , 'beforeMount' , 'mounted' , 'beforeUpdate' , 'updated' , 'activated' , 'deactivated' , 'beforeDestroy' , 'destroyed' , 'render' ] ; internal export const PROP_KEY = '$_vt_props' ; internal export function BuildOptions ( Component , options ? ) { if ( ! options ) { options = { } ; } options . name = options . name || Component . name ; const proto = Component . prototype ; if ( Object . getPrototypeOf ( proto ) instanceof Vue ) { Object . setPrototypeOf ( proto . constructor , function ( ) { } ) ; } const constructor = new proto . constructor ( ) ; const propAttrs = proto [ PROP_KEY ] ; let propNames ; delete proto [ PROP_KEY ] ; if ( propAttrs ) { const props = { } ; propNames = Object . getOwnPropertyNames ( propAttrs ) ; for ( const prop of propNames ) { let propVal ; const descriptor = Object . getOwnPropertyDescriptor ( propAttrs , prop ) as PropertyDescriptor ; const constructorDefault = constructor [ prop ] ; if ( typeof descriptor . value === 'object' ) { propVal = descriptor . value ; if ( ! propVal . default ) { propVal . default = constructorDefault ; } } else if ( constructorDefault ) { propVal = { default : constructorDefault } ; } if ( typeof propVal === 'undefined' ) { propVal = true ; } props [ prop ] = propVal ; } if ( ! options . props ) { options . props = { } ; } for ( const p in props ) { if ( props . hasOwnProperty ( p ) ) { options . props [ p ] = props [ p ] ; } } } Object . getOwnPropertyNames ( proto ) . forEach ( function ( key ) { if ( key === 'constructor' ) { return ; } if ( vueInternalHooks . indexOf ( key ) > - 1 ) { options [ key ] = proto [ key ] ; return ; } const descriptor = Object . getOwnPropertyDescriptor ( proto , key ) as PropertyDescriptor ; if ( typeof descriptor . value === 'function' ) { ; ( options . methods || ( options . methods = { } ) ) [ key ] = descriptor . value ; } else if ( descriptor . get || descriptor . set ) { ; ( options . computed || ( options . computed = { } ) ) [ key ] = { get : descriptor . get , set : descriptor . set } ; } } ) ; const dataNames = [ ] ; let restrictedNames = vueInternalPropNames ; if ( propNames ) { restrictedNames = restrictedNames . concat ( propNames ) ; } Object . getOwnPropertyNames ( constructor ) . forEach ( function ( key ) { if ( restrictedNames . indexOf ( key ) === - 1 ) { dataNames . push ( key ) ; } } ) ; if ( dataNames . length > 0 ) { let parentData ; const parentDataType = typeof options . data ; if ( parentDataType === 'function' ) { parentData = options . data ( ) ; } else if ( parentDataType === 'object' ) { parentData = options . data ; } options . data = ( ) => { const dataObj = parentData || { } ; dataNames . forEach ( function ( prop ) { const descriptor = Object . getOwnPropertyDescriptor ( constructor , prop ) as PropertyDescriptor ; if ( ! descriptor . get && ! descriptor . set && typeof descriptor . value !== 'function' ) { dataObj [ prop ] = constructor [ prop ] ; } } ) ; return dataObj ; } ; } return options ; }