]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
wip: optimize props validation
authorEvan You <evan@vuejs.org>
Thu, 5 Dec 2024 09:50:09 +0000 (17:50 +0800)
committerEvan You <evan@vuejs.org>
Thu, 5 Dec 2024 09:50:09 +0000 (17:50 +0800)
packages/runtime-core/src/componentProps.ts
packages/runtime-vapor/src/componentProps.ts

index 5a5808713e715c786d5f7e58f2fcf154f73fa6f1..fbc4ca5bf25a3c4437e67590bea181a55500f40f 100644 (file)
@@ -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 + '".')
   }
 }
index 41101a079a9e08a6269e67c49ca5704cdf593272..1fca42bfd5837f30aaf4338661ed62a01caec1e1 100644 (file)
@@ -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)