wip: more compat tweaks

This commit is contained in:
Evan You 2021-04-22 17:30:54 -04:00
parent 7e0224aa8c
commit 6f8fe4eac9
6 changed files with 29 additions and 10 deletions

View File

@ -4,6 +4,7 @@ import { DeprecationTypes, isCompatEnabled } from './compatConfig'
export function shouldSkipAttr(
key: string,
value: any,
instance: ComponentInternalInstance
): boolean {
if (
@ -18,5 +19,9 @@ export function shouldSkipAttr(
) {
return true
}
// vue-router
if (key.startsWith('routerView') || key === 'registerRouteInstance') {
return true
}
return false
}

View File

@ -153,10 +153,7 @@ export function createCompatVue(
// copy prototype augmentations as config.globalProperties
if (isCompatEnabled(DeprecationTypes.GLOBAL_PROTOTYPE, null)) {
app.config.globalProperties = extend(
Object.create(Ctor.prototype),
singletonApp.config.globalProperties
)
app.config.globalProperties = Ctor.prototype
}
let hasPrototypeAugmentations = false
for (const key in Ctor.prototype) {
@ -449,7 +446,9 @@ function defineReactive(obj: any, key: string, val: any) {
})
} else {
Object.keys(val).forEach(key => {
try {
defineReactiveSimple(val, key, val[key])
} catch (e) {}
})
}
}

View File

@ -93,11 +93,14 @@ export function installCompatInstanceProperties(map: PublicPropertiesMap) {
$children: getCompatChildren,
$listeners: getCompatListeners,
// inject parent into $options for compat
$vnode: i => i.vnode,
// inject addtional properties into $options for compat
$options: i => {
let res = resolveMergedOptions(i)
if (res === i.type) res = i.type.__merged = extend({}, res)
res.parent = i.proxy!.$parent
res.propsData = i.vnode.props
return res
},

View File

@ -24,6 +24,7 @@ import {
resolveDynamicComponent
} from '../helpers/resolveAssets'
import {
Comment,
createVNode,
isVNode,
normalizeChildren,
@ -121,6 +122,10 @@ export function compatH(
propsOrChildren?: any,
children?: any
): VNode {
if (!type) {
type = Comment
}
// to support v2 string component name look!up
if (typeof type === 'string') {
const t = hyphenate(type)
@ -201,6 +206,8 @@ function convertLegacyProps(
}
}
}
} else if (key === 'hook') {
// TODO
} else if (!skipLegacyRootLevelProps(key)) {
converted[key] = legacyProps[key as keyof LegacyVNodeProps]
}

View File

@ -229,7 +229,7 @@ export function updateProps(
)
}
} else {
if (__COMPAT__ && shouldSkipAttr(key, instance)) {
if (__COMPAT__ && shouldSkipAttr(key, attrs[key], instance)) {
continue
}
if (value !== attrs[key]) {
@ -337,7 +337,7 @@ function setFullProps(
// Any non-declared (either as a prop or an emitted event) props are put
// into a separate `attrs` object for spreading. Make sure to preserve
// original key casing
if (__COMPAT__ && shouldSkipAttr(key, instance)) {
if (__COMPAT__ && shouldSkipAttr(key, attrs[key], instance)) {
continue
}
if (value !== attrs[key]) {

View File

@ -345,8 +345,13 @@ export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
hasOwn(globalProperties, key))
) {
if (__COMPAT__) {
const desc = Object.getOwnPropertyDescriptor(globalProperties, key)!
if (desc.get) {
return desc.get.call(instance.proxy)
} else {
const val = globalProperties[key]
return isFunction(val) ? val.bind(instance.proxy) : val
}
} else {
return globalProperties[key]
}