1import Vm from '../model'; 2import { hasOwn } from '../../utils/index'; 3 4/** 5 * Get a prop's type. 6 * @param {Function} fn - Prop.type. 7 * @return {string} - Prop's type. 8 */ 9function getPropType(fn) { 10 const match = fn && fn.toString().match(/^\s*function (\w+)/); 11 return match ? match[1] : ''; 12} 13 14/** 15 * Get default prop value. 16 * @param {Vm} vm - Vm object. 17 * @param {PropInterface} prop - Default prop. 18 * @return {PropVauleInterfance | undefined} Default prop value or Null. 19 */ 20function getDefaultPropValue(vm, prop) { 21 if (!prop) { 22 return undefined; 23 } 24 if (!hasOwn(prop, 'default')) { 25 return undefined; 26 } 27 const __hasDefault = true; 28 const def = prop.default; 29 const __isDefaultValue = 30 typeof def === 'function' && getPropType(prop.type) !== 'Function' 31 ? def.call(vm) 32 : def; 33 return { __hasDefault, __isDefaultValue }; 34} 35 36export { 37 getDefaultPropValue 38}; 39