// add data hook to collect class properties as Vue instance's data
;(options.mixins||(options.mixins=[])).push({data(this:Vue){returncollectDataFromConstructor(this,Component)}})
functionforwardStaticMembers(Extended: typeofVue,Original: typeofVue,Super: typeofVue):void{// We have to use getOwnPropertyNames since Babel registers methods as non-enumerable
Object.getOwnPropertyNames(Original).forEach(key=>{// Skip the properties that should not be overwritten
// 剔除应该忽略的
if(shouldIgnore[key]){return}// Some browsers does not allow reconfigure built-in properties
// 剔除configurable为false的
constextendedDescriptor=Object.getOwnPropertyDescriptor(Extended,key)if(extendedDescriptor&&!extendedDescriptor.configurable){return}constdescriptor=Object.getOwnPropertyDescriptor(Original,key)!// If the user agent does not support `__proto__` or its family (IE <= 10),
// the sub class properties may be inherited properties from the super class in TypeScript.
// We need to exclude such properties to prevent to overwrite
// the component options object which stored on the extended constructor (See #192).
// If the value is a referenced value (object or function),
// we can check equality of them and exclude it if they have the same reference.
// If it is a primitive value, it will be forwarded for safety.
// 如果不存在__proto__的情况
if(!hasProto){// Only `cid` is explicitly exluded from property forwarding
// because we cannot detect whether it is a inherited property or not
// on the no `__proto__` environment even though the property is reserved.
if(key==='cid'){return}constsuperDescriptor=Object.getOwnPropertyDescriptor(Super,key)// 如果值相等的情况也剔除出去
if(!isPrimitive(descriptor.value)&&superDescriptor&&superDescriptor.value===descriptor.value){return}}// 往需要继承的对象上写入值
Object.defineProperty(Extended,key,descriptor)})}
exportfunctioncollectDataFromConstructor(vm: Vue,Component: VueClass<Vue>){// override _init to prevent to init as Vue instance
// 储存原来的_init方法
constoriginalInit=Component.prototype._init// 重写_init方法
Component.prototype._init=function(this:Vue){// proxy to actual vm
// 获取对象实例上的属性
constkeys=Object.getOwnPropertyNames(vm)// 2.2.0 compat (props are no longer exposed as self properties)
if(vm.$options.props){for(constkeyinvm.$options.props){if(!vm.hasOwnProperty(key)){// 搜集props中的key,同时也加入到keys中
keys.push(key)}}}// 定义对应key的取值和赋值方式
keys.forEach(key=>{Object.defineProperty(this,key,{get:()=>vm[key],set:value=>{vm[key]=value},configurable: true})})}// should be acquired class property values
// 组件实例化
constdata=newComponent()// restore original _init to avoid memory leak (#209)
// 恢复原来的_init方法
Component.prototype._init=originalInit// create plain data object
// 实例化后的对象
constplainData={}Object.keys(data).forEach(key=>{// 并且该值一定是非undefined
if(data[key]!==undefined){plainData[key]=data[key]}})returnplainData}