Skip to content

Commit 7b37f78

Browse files
committed
wip: add private api compat flag
1 parent 6f8fe4e commit 7b37f78

File tree

3 files changed

+52
-35
lines changed

3 files changed

+52
-35
lines changed

packages/runtime-core/src/compat/compatConfig.ts

+10-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ export const enum DeprecationTypes {
5858

5959
RENDER_FUNCTION = 'RENDER_FUNCTION',
6060

61-
FILTERS = 'FILTERS'
61+
FILTERS = 'FILTERS',
62+
63+
PRIVATE_APIS = 'PRIVATE_APIS'
6264
}
6365

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

packages/runtime-core/src/compat/instance.ts

+37-33
Original file line numberDiff line numberDiff line change
@@ -91,40 +91,44 @@ export function installCompatInstanceProperties(map: PublicPropertiesMap) {
9191
$off: i => off.bind(null, i),
9292

9393
$children: getCompatChildren,
94-
$listeners: getCompatListeners,
94+
$listeners: getCompatListeners
95+
} as PublicPropertiesMap)
9596

96-
$vnode: i => i.vnode,
97+
if (isCompatEnabled(DeprecationTypes.PRIVATE_APIS, null)) {
98+
extend(map, {
99+
$vnode: i => i.vnode,
97100

98-
// inject addtional properties into $options for compat
99-
$options: i => {
100-
let res = resolveMergedOptions(i)
101-
if (res === i.type) res = i.type.__merged = extend({}, res)
102-
res.parent = i.proxy!.$parent
103-
res.propsData = i.vnode.props
104-
return res
105-
},
101+
// inject addtional properties into $options for compat
102+
$options: i => {
103+
let res = resolveMergedOptions(i)
104+
if (res === i.type) res = i.type.__merged = extend({}, res)
105+
res.parent = i.proxy!.$parent
106+
res.propsData = i.vnode.props
107+
return res
108+
},
106109

107-
// v2 render helpers
108-
$createElement: () => compatH,
109-
_self: i => i.proxy,
110-
_uid: i => i.uid,
111-
_c: () => compatH,
112-
_o: () => legacyMarkOnce,
113-
_n: () => toNumber,
114-
_s: () => toDisplayString,
115-
_l: () => renderList,
116-
_t: i => legacyRenderSlot.bind(null, i),
117-
_q: () => looseEqual,
118-
_i: () => looseIndexOf,
119-
_m: i => legacyRenderStatic.bind(null, i),
120-
_f: () => resolveFilter,
121-
_k: i => legacyCheckKeyCodes.bind(null, i),
122-
_b: () => legacyBindObjectProps,
123-
_v: () => createTextVNode,
124-
_e: () => createCommentVNode,
125-
_u: () => legacyresolveScopedSlots,
126-
_g: () => legacyBindObjectListeners,
127-
_d: () => legacyBindDynamicKeys,
128-
_p: () => legacyPrependModifier
129-
} as PublicPropertiesMap)
110+
// v2 render helpers
111+
$createElement: () => compatH,
112+
_self: i => i.proxy,
113+
_uid: i => i.uid,
114+
_c: () => compatH,
115+
_o: () => legacyMarkOnce,
116+
_n: () => toNumber,
117+
_s: () => toDisplayString,
118+
_l: () => renderList,
119+
_t: i => legacyRenderSlot.bind(null, i),
120+
_q: () => looseEqual,
121+
_i: () => looseIndexOf,
122+
_m: i => legacyRenderStatic.bind(null, i),
123+
_f: () => resolveFilter,
124+
_k: i => legacyCheckKeyCodes.bind(null, i),
125+
_b: () => legacyBindObjectProps,
126+
_v: () => createTextVNode,
127+
_e: () => createCommentVNode,
128+
_u: () => legacyresolveScopedSlots,
129+
_g: () => legacyBindObjectListeners,
130+
_d: () => legacyBindDynamicKeys,
131+
_p: () => legacyPrependModifier
132+
} as PublicPropertiesMap)
133+
}
130134
}

packages/runtime-core/src/compat/renderFn.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,11 @@ function convertLegacySlots(vnode: VNode): VNode {
310310

311311
export function defineLegacyVNodeProperties(vnode: VNode) {
312312
if (
313-
isCompatEnabled(DeprecationTypes.RENDER_FUNCTION, currentRenderingInstance)
313+
isCompatEnabled(
314+
DeprecationTypes.RENDER_FUNCTION,
315+
currentRenderingInstance
316+
) &&
317+
isCompatEnabled(DeprecationTypes.PRIVATE_APIS, currentRenderingInstance)
314318
) {
315319
const context = currentRenderingInstance
316320
const getInstance = () => vnode.component && vnode.component.proxy

0 commit comments

Comments
 (0)