// 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-enumerableObject.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的const extendedDescriptor = Object.getOwnPropertyDescriptor(Extended, key)
if (extendedDescriptor && !extendedDescriptor.configurable) {
return
}
const descriptor = 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
}
const superDescriptor = Object.getOwnPropertyDescriptor(Super, key)
// 如果值相等的情况也剔除出去if (
!isPrimitive(descriptor.value) &&
superDescriptor &&
superDescriptor.value === descriptor.value
) {
return
}
}
// 往需要继承的对象上写入值Object.defineProperty(Extended, key, descriptor)
})
}