wip: add private api compat flag

This commit is contained in:
Evan You 2021-04-22 17:50:49 -04:00
parent 6f8fe4eac9
commit 7b37f78dc9
3 changed files with 54 additions and 37 deletions

View File

@ -58,7 +58,9 @@ export const enum DeprecationTypes {
RENDER_FUNCTION = 'RENDER_FUNCTION',
FILTERS = 'FILTERS'
FILTERS = 'FILTERS',
PRIVATE_APIS = 'PRIVATE_APIS'
}
type DeprecationData = {
@ -404,6 +406,13 @@ const deprecationData: Record<DeprecationTypes, DeprecationData> = {
`The "|" symbol will be treated as native JavaScript bitwise OR operator. ` +
`Use method calls or computed properties instead.`,
link: `https://v3.vuejs.org/guide/migration/filters.html`
},
[DeprecationTypes.PRIVATE_APIS]: {
message: name =>
`"${name}" is a Vue 2 private API that no longer exists in Vue 3. ` +
`If you are seeing this warning only due to a dependency, you can ` +
`suppress this warning via { PRIVATE_APIS: 'supress-warning' }.`
}
}

View File

@ -91,40 +91,44 @@ export function installCompatInstanceProperties(map: PublicPropertiesMap) {
$off: i => off.bind(null, i),
$children: getCompatChildren,
$listeners: getCompatListeners,
$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
},
// v2 render helpers
$createElement: () => compatH,
_self: i => i.proxy,
_uid: i => i.uid,
_c: () => compatH,
_o: () => legacyMarkOnce,
_n: () => toNumber,
_s: () => toDisplayString,
_l: () => renderList,
_t: i => legacyRenderSlot.bind(null, i),
_q: () => looseEqual,
_i: () => looseIndexOf,
_m: i => legacyRenderStatic.bind(null, i),
_f: () => resolveFilter,
_k: i => legacyCheckKeyCodes.bind(null, i),
_b: () => legacyBindObjectProps,
_v: () => createTextVNode,
_e: () => createCommentVNode,
_u: () => legacyresolveScopedSlots,
_g: () => legacyBindObjectListeners,
_d: () => legacyBindDynamicKeys,
_p: () => legacyPrependModifier
$listeners: getCompatListeners
} as PublicPropertiesMap)
if (isCompatEnabled(DeprecationTypes.PRIVATE_APIS, null)) {
extend(map, {
$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
},
// v2 render helpers
$createElement: () => compatH,
_self: i => i.proxy,
_uid: i => i.uid,
_c: () => compatH,
_o: () => legacyMarkOnce,
_n: () => toNumber,
_s: () => toDisplayString,
_l: () => renderList,
_t: i => legacyRenderSlot.bind(null, i),
_q: () => looseEqual,
_i: () => looseIndexOf,
_m: i => legacyRenderStatic.bind(null, i),
_f: () => resolveFilter,
_k: i => legacyCheckKeyCodes.bind(null, i),
_b: () => legacyBindObjectProps,
_v: () => createTextVNode,
_e: () => createCommentVNode,
_u: () => legacyresolveScopedSlots,
_g: () => legacyBindObjectListeners,
_d: () => legacyBindDynamicKeys,
_p: () => legacyPrependModifier
} as PublicPropertiesMap)
}
}

View File

@ -310,7 +310,11 @@ function convertLegacySlots(vnode: VNode): VNode {
export function defineLegacyVNodeProperties(vnode: VNode) {
if (
isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, currentRenderingInstance)
isCompatEnabled(
DeprecationTypes.RENDER_FUNCTION,
currentRenderingInstance
) &&
isCompatEnabled(DeprecationTypes.PRIVATE_APIS, currentRenderingInstance)
) {
const context = currentRenderingInstance
const getInstance = () => vnode.component && vnode.component.proxy