@@ -46,25 +46,52 @@ function getSuper(Ctor: typeof VueImpl): typeof VueImpl | undefined {
46
46
return superProto . constructor as typeof VueImpl
47
47
}
48
48
49
+ function getOwn < T extends Object , K extends keyof T > (
50
+ value : T ,
51
+ key : K
52
+ ) : T [ K ] | undefined {
53
+ return value . hasOwnProperty ( key ) ? value [ key ] : undefined
54
+ }
55
+
49
56
export interface VueStatic {
50
57
// -- Class component configs
51
58
52
- /** @internal */
53
- __vccCache ?: ComponentOptions
54
-
55
- /** @internal */
56
- __vccBase ?: ComponentOptions
57
-
58
- /** @internal */
59
- __vccDecorators ?: ( ( options : ComponentOptions ) => void ) [ ]
60
-
61
- /** @internal */
62
- __vccExtend : ( options : ComponentOptions ) => void
63
-
64
- /** @internal */
65
- __vccHooks : string [ ]
66
-
67
- /** @internal */
59
+ /**
60
+ * @internal
61
+ * The cache of __vccOpts
62
+ */
63
+ __c ?: ComponentOptions
64
+
65
+ /**
66
+ * @internal
67
+ * The base options specified to this class.
68
+ */
69
+ __b ?: ComponentOptions
70
+
71
+ /**
72
+ * @internal
73
+ * Component options specified with `@Options` decorator
74
+ */
75
+ __o ?: ComponentOptions
76
+
77
+ /**
78
+ * @internal
79
+ * Decorators applied to this class.
80
+ */
81
+ __d ?: ( ( options : ComponentOptions ) => void ) [ ]
82
+
83
+ /**
84
+ * @internal
85
+ * Registered (lifecycle) hooks that will be ported from class methods
86
+ * into component options.
87
+ */
88
+ __h : string [ ]
89
+
90
+ /**
91
+ * @internal
92
+ * Final component options object that Vue core processes.
93
+ * The name must be __vccOpts since it is the contract with the Vue core.
94
+ */
68
95
__vccOpts : ComponentOptions
69
96
70
97
// --- Vue Loader etc injections
@@ -147,17 +174,7 @@ export interface VueConstructor<V extends VueBase = Vue> extends VueMixin<V> {
147
174
}
148
175
149
176
class VueImpl {
150
- /** @internal */
151
- static __vccCache ?: ComponentOptions
152
-
153
- /** @internal */
154
- static __vccBase ?: ComponentOptions
155
-
156
- /** @internal */
157
- static __vccDecorators ?: ( ( options : ComponentOptions ) => void ) [ ]
158
-
159
- /** @internal */
160
- static __vccHooks = [
177
+ static __h = [
161
178
'data' ,
162
179
'beforeCreate' ,
163
180
'created' ,
@@ -174,35 +191,34 @@ class VueImpl {
174
191
'serverPrefetch' ,
175
192
]
176
193
177
- /** @internal */
178
- static __vccExtend ( options : ComponentOptions ) {
179
- options . mixins = options . mixins || [ ]
180
- options . mixins . push ( this . __vccOpts )
181
- }
182
-
183
- /** @internal */
184
194
static get __vccOpts ( ) : ComponentOptions {
185
195
// Early return if `this` is base class as it does not have any options
186
196
if ( this === Vue ) {
187
197
return { }
188
198
}
189
199
190
- const cache = this . hasOwnProperty ( '__vccCache' ) && this . __vccCache
200
+ const Ctor = this as VueConstructor
201
+
202
+ const cache = getOwn ( Ctor , '__c' )
191
203
if ( cache ) {
192
204
return cache
193
205
}
194
206
195
- const Ctor = this
196
-
197
207
// If the options are provided via decorator use it as a base
198
- const options = ( this . __vccCache = this . hasOwnProperty ( '__vccBase' )
199
- ? { ...this . __vccBase }
200
- : { } )
208
+ const options : ComponentOptions = { ...getOwn ( Ctor , '__o' ) }
209
+ Ctor . __c = options
201
210
202
211
// Handle super class options
203
212
const Super = getSuper ( Ctor )
204
213
if ( Super ) {
205
- Super . __vccExtend ( options )
214
+ options . extends = Super . __vccOpts
215
+ }
216
+
217
+ // Inject base options as a mixin
218
+ const base = getOwn ( Ctor , '__b' )
219
+ if ( base ) {
220
+ options . mixins = options . mixins || [ ]
221
+ options . mixins . unshift ( base )
206
222
}
207
223
208
224
options . methods = { ...options . methods }
@@ -215,7 +231,7 @@ class VueImpl {
215
231
}
216
232
217
233
// hooks
218
- if ( Ctor . __vccHooks . indexOf ( key ) > - 1 ) {
234
+ if ( Ctor . __h . indexOf ( key ) > - 1 ) {
219
235
; ( options as any ) [ key ] = ( proto as any ) [ key ]
220
236
return
221
237
}
@@ -280,8 +296,7 @@ class VueImpl {
280
296
return promise ?? plainData
281
297
}
282
298
283
- const decorators =
284
- this . hasOwnProperty ( '__vccDecorators' ) && this . __vccDecorators
299
+ const decorators = getOwn ( Ctor , '__d' )
285
300
if ( decorators ) {
286
301
decorators . forEach ( ( fn ) => fn ( options ) )
287
302
}
@@ -305,7 +320,7 @@ class VueImpl {
305
320
}
306
321
307
322
static registerHooks ( keys : string [ ] ) : void {
308
- this . __vccHooks . push ( ...keys )
323
+ this . __h . push ( ...keys )
309
324
}
310
325
311
326
static props ( Props : { new ( ) : unknown } ) : VueConstructor {
@@ -318,8 +333,8 @@ class VueImpl {
318
333
} )
319
334
320
335
class PropsMixin extends this {
321
- static __vccExtend ( options : ComponentOptions ) {
322
- options . props = props
336
+ static __b : ComponentOptions = {
337
+ props,
323
338
}
324
339
}
325
340
return PropsMixin as VueConstructor
0 commit comments