@@ -8,7 +8,11 @@ import {
88} from '@babel/types'
99import { BindingTypes , isFunctionType } from '@vue/compiler-dom'
1010import { ScriptCompileContext } from './context'
11- import { inferRuntimeType , resolveTypeElements } from './resolveType'
11+ import {
12+ TypeResolveContext ,
13+ inferRuntimeType ,
14+ resolveTypeElements
15+ } from './resolveType'
1216import {
1317 resolveObjectKey ,
1418 UNKNOWN_TYPE ,
@@ -150,7 +154,7 @@ export function genRuntimeProps(ctx: ScriptCompileContext): string | undefined {
150154 }
151155 }
152156 } else if ( ctx . propsTypeDecl ) {
153- propsDecls = genRuntimePropsFromTypes ( ctx )
157+ propsDecls = extractRuntimeProps ( ctx )
154158 }
155159
156160 const modelsDecls = genModelProps ( ctx )
@@ -162,7 +166,9 @@ export function genRuntimeProps(ctx: ScriptCompileContext): string | undefined {
162166 }
163167}
164168
165- function genRuntimePropsFromTypes ( ctx : ScriptCompileContext ) {
169+ export function extractRuntimeProps (
170+ ctx : TypeResolveContext
171+ ) : string | undefined {
166172 // this is only called if propsTypeDecl exists
167173 const props = resolveRuntimePropsFromType ( ctx , ctx . propsTypeDecl ! )
168174 if ( ! props . length ) {
@@ -175,7 +181,7 @@ function genRuntimePropsFromTypes(ctx: ScriptCompileContext) {
175181 for ( const prop of props ) {
176182 propStrings . push ( genRuntimePropFromType ( ctx , prop , hasStaticDefaults ) )
177183 // register bindings
178- if ( ! ( prop . key in ctx . bindingMetadata ) ) {
184+ if ( 'bindingMetadata' in ctx && ! ( prop . key in ctx . bindingMetadata ) ) {
179185 ctx . bindingMetadata [ prop . key ] = BindingTypes . PROPS
180186 }
181187 }
@@ -193,7 +199,7 @@ function genRuntimePropsFromTypes(ctx: ScriptCompileContext) {
193199}
194200
195201function resolveRuntimePropsFromType (
196- ctx : ScriptCompileContext ,
202+ ctx : TypeResolveContext ,
197203 node : Node
198204) : PropTypeData [ ] {
199205 const props : PropTypeData [ ] = [ ]
@@ -222,7 +228,7 @@ function resolveRuntimePropsFromType(
222228}
223229
224230function genRuntimePropFromType (
225- ctx : ScriptCompileContext ,
231+ ctx : TypeResolveContext ,
226232 { key, required, type, skipCheck } : PropTypeData ,
227233 hasStaticDefaults : boolean
228234) : string {
@@ -284,7 +290,7 @@ function genRuntimePropFromType(
284290 * static properties, we can directly generate more optimized default
285291 * declarations. Otherwise we will have to fallback to runtime merging.
286292 */
287- function hasStaticWithDefaults ( ctx : ScriptCompileContext ) {
293+ function hasStaticWithDefaults ( ctx : TypeResolveContext ) {
288294 return ! ! (
289295 ctx . propsRuntimeDefaults &&
290296 ctx . propsRuntimeDefaults . type === 'ObjectExpression' &&
@@ -297,7 +303,7 @@ function hasStaticWithDefaults(ctx: ScriptCompileContext) {
297303}
298304
299305function genDestructuredDefaultValue (
300- ctx : ScriptCompileContext ,
306+ ctx : TypeResolveContext ,
301307 key : string ,
302308 inferredType ?: string [ ]
303309) :
0 commit comments