( comp: ConcreteComponent, appContext: AppContext, asMixin = false, )
| 508 | const mixinPropsCache = new WeakMap<ConcreteComponent, NormalizedPropsOptions>() |
| 509 | |
| 510 | export 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)) { |
no test coverage detected