From: Evan You Date: Tue, 25 Sep 2018 18:26:36 +0000 (-0400) Subject: refactor: remove unnecessary normalization X-Git-Tag: v3.0.0-alpha.0~1189 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7b7ae573886df9df12c550c53638e933186bb6c3;p=thirdparty%2Fvuejs%2Fcore.git refactor: remove unnecessary normalization --- diff --git a/packages/core/src/componentOptions.ts b/packages/core/src/componentOptions.ts index 82c5f0ca3a..fbe2508393 100644 --- a/packages/core/src/componentOptions.ts +++ b/packages/core/src/componentOptions.ts @@ -22,10 +22,6 @@ export type ComponentPropsOptions

= { [K in keyof P]: PropValidator } -export type NormalizedPropsOptions

= { - [K in keyof P]: PropOptions -} - export type Prop = { (): T } | { new (...args: any[]): T & object } export type PropType = Prop | Prop[] diff --git a/packages/core/src/componentProps.ts b/packages/core/src/componentProps.ts index dd1b3509f6..514f33ca3d 100644 --- a/packages/core/src/componentProps.ts +++ b/packages/core/src/componentProps.ts @@ -9,7 +9,6 @@ import { immutable, unwrap, lock, unlock } from '@vue/observer' import { Data, ComponentPropsOptions, - NormalizedPropsOptions, PropValidator, PropOptions } from './componentOptions' @@ -77,10 +76,7 @@ export function resolveProps( Component: ComponentClass | FunctionalComponent ): { props: Data; attrs?: Data } { const hasDeclaredProps = rawOptions !== void 0 - const options = (hasDeclaredProps && - normalizePropsOptions( - rawOptions as ComponentPropsOptions - )) as NormalizedPropsOptions + const options = rawOptions as ComponentPropsOptions if (!rawData && !hasDeclaredProps) { return EMPTY_PROPS } @@ -120,7 +116,7 @@ export function resolveProps( if (props[key] === void 0) { const opt = options[key] if (opt != null && opt.hasOwnProperty('default')) { - const defaultValue = opt.default + const defaultValue = (opt as PropOptions).default props[key] = typeof defaultValue === 'function' ? defaultValue() : defaultValue } @@ -130,28 +126,6 @@ export function resolveProps( return { props, attrs } } -const normalizeCache = new WeakMap< - ComponentPropsOptions, - NormalizedPropsOptions ->() - -function normalizePropsOptions( - raw: ComponentPropsOptions -): NormalizedPropsOptions { - let cached = normalizeCache.get(raw) - if (cached) { - return cached - } - const normalized: NormalizedPropsOptions = {} - for (const key in raw) { - const opt = raw[key] - normalized[key] = - typeof opt === 'function' ? { type: opt } : (opt as PropOptions) - } - normalizeCache.set(raw, normalized) - return normalized -} - function validateProp( key: string, value: any,