@@ -8,7 +8,11 @@ import {
8
8
} from '@babel/types'
9
9
import { BindingTypes , isFunctionType } from '@vue/compiler-dom'
10
10
import { ScriptCompileContext } from './context'
11
- import { inferRuntimeType , resolveTypeElements } from './resolveType'
11
+ import {
12
+ TypeResolveContext ,
13
+ inferRuntimeType ,
14
+ resolveTypeElements
15
+ } from './resolveType'
12
16
import {
13
17
resolveObjectKey ,
14
18
UNKNOWN_TYPE ,
@@ -150,7 +154,7 @@ export function genRuntimeProps(ctx: ScriptCompileContext): string | undefined {
150
154
}
151
155
}
152
156
} else if ( ctx . propsTypeDecl ) {
153
- propsDecls = genRuntimePropsFromTypes ( ctx )
157
+ propsDecls = extractRuntimeProps ( ctx )
154
158
}
155
159
156
160
const modelsDecls = genModelProps ( ctx )
@@ -162,7 +166,9 @@ export function genRuntimeProps(ctx: ScriptCompileContext): string | undefined {
162
166
}
163
167
}
164
168
165
- function genRuntimePropsFromTypes ( ctx : ScriptCompileContext ) {
169
+ export function extractRuntimeProps (
170
+ ctx : TypeResolveContext
171
+ ) : string | undefined {
166
172
// this is only called if propsTypeDecl exists
167
173
const props = resolveRuntimePropsFromType ( ctx , ctx . propsTypeDecl ! )
168
174
if ( ! props . length ) {
@@ -175,7 +181,7 @@ function genRuntimePropsFromTypes(ctx: ScriptCompileContext) {
175
181
for ( const prop of props ) {
176
182
propStrings . push ( genRuntimePropFromType ( ctx , prop , hasStaticDefaults ) )
177
183
// register bindings
178
- if ( ! ( prop . key in ctx . bindingMetadata ) ) {
184
+ if ( 'bindingMetadata' in ctx && ! ( prop . key in ctx . bindingMetadata ) ) {
179
185
ctx . bindingMetadata [ prop . key ] = BindingTypes . PROPS
180
186
}
181
187
}
@@ -193,7 +199,7 @@ function genRuntimePropsFromTypes(ctx: ScriptCompileContext) {
193
199
}
194
200
195
201
function resolveRuntimePropsFromType (
196
- ctx : ScriptCompileContext ,
202
+ ctx : TypeResolveContext ,
197
203
node : Node
198
204
) : PropTypeData [ ] {
199
205
const props : PropTypeData [ ] = [ ]
@@ -222,7 +228,7 @@ function resolveRuntimePropsFromType(
222
228
}
223
229
224
230
function genRuntimePropFromType (
225
- ctx : ScriptCompileContext ,
231
+ ctx : TypeResolveContext ,
226
232
{ key, required, type, skipCheck } : PropTypeData ,
227
233
hasStaticDefaults : boolean
228
234
) : string {
@@ -284,7 +290,7 @@ function genRuntimePropFromType(
284
290
* static properties, we can directly generate more optimized default
285
291
* declarations. Otherwise we will have to fallback to runtime merging.
286
292
*/
287
- function hasStaticWithDefaults ( ctx : ScriptCompileContext ) {
293
+ function hasStaticWithDefaults ( ctx : TypeResolveContext ) {
288
294
return ! ! (
289
295
ctx . propsRuntimeDefaults &&
290
296
ctx . propsRuntimeDefaults . type === 'ObjectExpression' &&
@@ -297,7 +303,7 @@ function hasStaticWithDefaults(ctx: ScriptCompileContext) {
297
303
}
298
304
299
305
function genDestructuredDefaultValue (
300
- ctx : ScriptCompileContext ,
306
+ ctx : TypeResolveContext ,
301
307
key : string ,
302
308
inferredType ?: string [ ]
303
309
) :
0 commit comments