mirror of https://github.com/vuejs/core.git
wip: optimize props validation
This commit is contained in:
parent
fc9aa62248
commit
4baaa7bca3
|
@ -701,15 +701,16 @@ export function validateProps(
|
|||
resolvedProps = toRaw(resolvedProps)
|
||||
const camelizePropsKey = Object.keys(rawProps).map(key => camelize(key))
|
||||
for (const key in options) {
|
||||
let opt = options[key]
|
||||
if (opt == null) continue
|
||||
validateProp(
|
||||
key,
|
||||
resolvedProps[key],
|
||||
opt,
|
||||
__DEV__ ? shallowReadonly(resolvedProps) : resolvedProps,
|
||||
!camelizePropsKey.includes(key),
|
||||
)
|
||||
const opt = options[key]
|
||||
if (opt != null) {
|
||||
validateProp(
|
||||
key,
|
||||
resolvedProps[key],
|
||||
opt,
|
||||
resolvedProps,
|
||||
!camelizePropsKey.includes(key),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -750,7 +751,10 @@ function validateProp(
|
|||
}
|
||||
}
|
||||
// custom validator
|
||||
if (validator && !validator(value, resolvedProps)) {
|
||||
if (
|
||||
validator &&
|
||||
!validator(value, __DEV__ ? shallowReadonly(resolvedProps) : resolvedProps)
|
||||
) {
|
||||
warn('Invalid prop: custom validator check failed for prop "' + key + '".')
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,4 @@
|
|||
import {
|
||||
EMPTY_ARR,
|
||||
NO,
|
||||
YES,
|
||||
camelize,
|
||||
extend,
|
||||
hasOwn,
|
||||
isFunction,
|
||||
} from '@vue/shared'
|
||||
import { EMPTY_ARR, NO, YES, camelize, hasOwn, isFunction } from '@vue/shared'
|
||||
import type { VaporComponent, VaporComponentInstance } from './component'
|
||||
import {
|
||||
type NormalizedPropsOptions,
|
||||
|
@ -239,7 +231,12 @@ export function setupPropsValidation(instance: VaporComponentInstance): void {
|
|||
const rawProps = instance.rawProps
|
||||
if (!rawProps) return
|
||||
renderEffect(() => {
|
||||
const mergedRawProps = extend({}, rawProps)
|
||||
const mergedRawProps: Record<string, any> = {}
|
||||
for (const key in rawProps) {
|
||||
if (key !== '$') {
|
||||
mergedRawProps[key] = rawProps[key]()
|
||||
}
|
||||
}
|
||||
if (rawProps.$) {
|
||||
for (const source of rawProps.$) {
|
||||
const isDynamic = isFunction(source)
|
||||
|
|
Loading…
Reference in New Issue