@@ -15,6 +15,7 @@ import {
15
15
DeprecationTypes ,
16
16
assertCompatEnabled ,
17
17
isCompatEnabled ,
18
+ warnDeprecation ,
18
19
} from './compatConfig'
19
20
import { off , on , once } from './instanceEventEmitter'
20
21
import { getCompatListeners } from './instanceListeners'
@@ -121,50 +122,77 @@ export function installCompatInstanceProperties(map: PublicPropertiesMap) {
121
122
122
123
$children : getCompatChildren ,
123
124
$listeners : getCompatListeners ,
125
+
126
+ // inject additional properties into $options for compat
127
+ // e.g. vuex needs this.$options.parent
128
+ $options : i => {
129
+ if ( ! isCompatEnabled ( DeprecationTypes . PRIVATE_APIS , i ) ) {
130
+ return resolveMergedOptions ( i )
131
+ }
132
+ if ( i . resolvedOptions ) {
133
+ return i . resolvedOptions
134
+ }
135
+ const res = ( i . resolvedOptions = extend ( { } , resolveMergedOptions ( i ) ) )
136
+ Object . defineProperties ( res , {
137
+ parent : {
138
+ get ( ) {
139
+ warnDeprecation ( DeprecationTypes . PRIVATE_APIS , i , '$options.parent' )
140
+ return i . proxy ! . $parent
141
+ } ,
142
+ } ,
143
+ propsData : {
144
+ get ( ) {
145
+ warnDeprecation (
146
+ DeprecationTypes . PRIVATE_APIS ,
147
+ i ,
148
+ '$options.propsData' ,
149
+ )
150
+ return i . vnode . props
151
+ } ,
152
+ } ,
153
+ } )
154
+ return res
155
+ } ,
124
156
} as PublicPropertiesMap )
125
157
126
- /* istanbul ignore if */
127
- if ( isCompatEnabled ( DeprecationTypes . PRIVATE_APIS , null ) ) {
128
- extend ( map , {
129
- // needed by many libs / render fns
130
- $vnode : i => i . vnode ,
131
-
132
- // inject additional properties into $options for compat
133
- // e.g. vuex needs this.$options.parent
134
- $options : i => {
135
- const res = extend ( { } , resolveMergedOptions ( i ) )
136
- res . parent = i . proxy ! . $parent
137
- res . propsData = i . vnode . props
138
- return res
139
- } ,
140
-
141
- // some private properties that are likely accessed...
142
- _self : i => i . proxy ,
143
- _uid : i => i . uid ,
144
- _data : i => i . data ,
145
- _isMounted : i => i . isMounted ,
146
- _isDestroyed : i => i . isUnmounted ,
147
-
148
- // v2 render helpers
149
- $createElement : ( ) => compatH ,
150
- _c : ( ) => compatH ,
151
- _o : ( ) => legacyMarkOnce ,
152
- _n : ( ) => looseToNumber ,
153
- _s : ( ) => toDisplayString ,
154
- _l : ( ) => renderList ,
155
- _t : i => legacyRenderSlot . bind ( null , i ) ,
156
- _q : ( ) => looseEqual ,
157
- _i : ( ) => looseIndexOf ,
158
- _m : i => legacyRenderStatic . bind ( null , i ) ,
159
- _f : ( ) => resolveFilter ,
160
- _k : i => legacyCheckKeyCodes . bind ( null , i ) ,
161
- _b : ( ) => legacyBindObjectProps ,
162
- _v : ( ) => createTextVNode ,
163
- _e : ( ) => createCommentVNode ,
164
- _u : ( ) => legacyresolveScopedSlots ,
165
- _g : ( ) => legacyBindObjectListeners ,
166
- _d : ( ) => legacyBindDynamicKeys ,
167
- _p : ( ) => legacyPrependModifier ,
168
- } as PublicPropertiesMap )
158
+ const privateAPIs = {
159
+ // needed by many libs / render fns
160
+ $vnode : i => i . vnode ,
161
+
162
+ // some private properties that are likely accessed...
163
+ _self : i => i . proxy ,
164
+ _uid : i => i . uid ,
165
+ _data : i => i . data ,
166
+ _isMounted : i => i . isMounted ,
167
+ _isDestroyed : i => i . isUnmounted ,
168
+
169
+ // v2 render helpers
170
+ $createElement : ( ) => compatH ,
171
+ _c : ( ) => compatH ,
172
+ _o : ( ) => legacyMarkOnce ,
173
+ _n : ( ) => looseToNumber ,
174
+ _s : ( ) => toDisplayString ,
175
+ _l : ( ) => renderList ,
176
+ _t : i => legacyRenderSlot . bind ( null , i ) ,
177
+ _q : ( ) => looseEqual ,
178
+ _i : ( ) => looseIndexOf ,
179
+ _m : i => legacyRenderStatic . bind ( null , i ) ,
180
+ _f : ( ) => resolveFilter ,
181
+ _k : i => legacyCheckKeyCodes . bind ( null , i ) ,
182
+ _b : ( ) => legacyBindObjectProps ,
183
+ _v : ( ) => createTextVNode ,
184
+ _e : ( ) => createCommentVNode ,
185
+ _u : ( ) => legacyresolveScopedSlots ,
186
+ _g : ( ) => legacyBindObjectListeners ,
187
+ _d : ( ) => legacyBindDynamicKeys ,
188
+ _p : ( ) => legacyPrependModifier ,
189
+ } as PublicPropertiesMap
190
+
191
+ for ( const key in privateAPIs ) {
192
+ map [ key ] = i => {
193
+ if ( isCompatEnabled ( DeprecationTypes . PRIVATE_APIS , i ) ) {
194
+ return privateAPIs [ key ] ( i )
195
+ }
196
+ }
169
197
}
170
198
}
0 commit comments