MCPcopy
hub / github.com/vuejs/core / extractRuntimeProps

Function extractRuntimeProps

packages/compiler-sfc/src/script/defineProps.ts:179–209  ·  view source on GitHub ↗
(
  ctx: TypeResolveContext,
)

Source from the content-addressed store, hash-verified

177}
178
179export function extractRuntimeProps(
180 ctx: TypeResolveContext,
181): string | undefined {
182 // this is only called if propsTypeDecl exists
183 const props = resolveRuntimePropsFromType(ctx, ctx.propsTypeDecl!)
184 if (!props.length) {
185 return
186 }
187
188 const propStrings: string[] = []
189 const hasStaticDefaults = hasStaticWithDefaults(ctx)
190
191 for (const prop of props) {
192 propStrings.push(genRuntimePropFromType(ctx, prop, hasStaticDefaults))
193 // register bindings
194 if ('bindingMetadata' in ctx && !(prop.key in ctx.bindingMetadata)) {
195 ctx.bindingMetadata[prop.key] = BindingTypes.PROPS
196 }
197 }
198
199 let propsDecls = `{
200 ${propStrings.join(',\n ')}\n }`
201
202 if (ctx.propsRuntimeDefaults && !hasStaticDefaults) {
203 propsDecls = `/*@__PURE__*/${ctx.helper(
204 'mergeDefaults',
205 )}(${propsDecls}, ${ctx.getString(ctx.propsRuntimeDefaults)})`
206 }
207
208 return propsDecls
209}
210
211function resolveRuntimePropsFromType(
212 ctx: TypeResolveContext,

Callers 1

genRuntimePropsFunction · 0.85

Calls 6

hasStaticWithDefaultsFunction · 0.85
genRuntimePropFromTypeFunction · 0.85
getStringMethod · 0.80
pushMethod · 0.65
helperMethod · 0.65

Tested by

no test coverage detected