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

Function normalizePropsOptions

packages/runtime-core/src/componentProps.ts:510–616  ·  view source on GitHub ↗
(
  comp: ConcreteComponent,
  appContext: AppContext,
  asMixin = false,
)

Source from the content-addressed store, hash-verified

508const mixinPropsCache = new WeakMap<ConcreteComponent, NormalizedPropsOptions>()
509
510export function normalizePropsOptions(
511 comp: ConcreteComponent,
512 appContext: AppContext,
513 asMixin = false,
514): NormalizedPropsOptions {
515 const cache =
516 __FEATURE_OPTIONS_API__ && asMixin ? mixinPropsCache : appContext.propsCache
517 const cached = cache.get(comp)
518 if (cached) {
519 return cached
520 }
521
522 const raw = comp.props
523 const normalized: NormalizedPropsOptions[0] = {}
524 const needCastKeys: NormalizedPropsOptions[1] = []
525
526 // apply mixin/extends props
527 let hasExtends = false
528 if (__FEATURE_OPTIONS_API__ && !isFunction(comp)) {
529 const extendProps = (raw: ComponentOptions) => {
530 if (__COMPAT__ && isFunction(raw)) {
531 raw = raw.options
532 }
533 hasExtends = true
534 const [props, keys] = normalizePropsOptions(raw, appContext, true)
535 extend(normalized, props)
536 if (keys) needCastKeys.push(...keys)
537 }
538 if (!asMixin && appContext.mixins.length) {
539 appContext.mixins.forEach(extendProps)
540 }
541 if (comp.extends) {
542 extendProps(comp.extends)
543 }
544 if (comp.mixins) {
545 comp.mixins.forEach(extendProps)
546 }
547 }
548
549 if (!raw && !hasExtends) {
550 if (isObject(comp)) {
551 cache.set(comp, EMPTY_ARR as any)
552 }
553 return EMPTY_ARR as any
554 }
555
556 if (isArray(raw)) {
557 for (let i = 0; i < raw.length; i++) {
558 if (__DEV__ && !isString(raw[i])) {
559 warn(`props must be strings when using array syntax.`, raw[i])
560 }
561 const normalizedKey = camelize(raw[i])
562 if (validatePropName(normalizedKey)) {
563 normalized[normalizedKey] = EMPTY_OBJ
564 }
565 }
566 } else if (raw) {
567 if (__DEV__ && !isObject(raw)) {

Callers 2

createComponentInstanceFunction · 0.90
extendPropsFunction · 0.85

Calls 11

isFunctionFunction · 0.90
isObjectFunction · 0.90
isStringFunction · 0.90
warnFunction · 0.90
hasOwnFunction · 0.90
extendPropsFunction · 0.85
validatePropNameFunction · 0.85
forEachMethod · 0.80
pushMethod · 0.65
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected