]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(props): enable case conversion in all builds, preserve casing for attrs
authorEvan You <yyx990803@gmail.com>
Thu, 24 Oct 2019 14:59:57 +0000 (10:59 -0400)
committerEvan You <yyx990803@gmail.com>
Thu, 24 Oct 2019 14:59:57 +0000 (10:59 -0400)
packages/runtime-core/src/componentProps.ts

index acd6471d5b8aefd0843c7d16a8cd42a4e259172f..8f9e603e2703011b935fc98f92121fcbcb23601e 100644 (file)
@@ -128,11 +128,13 @@ export function resolveProps(
     for (const key in rawProps) {
       // key, ref are reserved
       if (isReservedProp(key)) continue
-      const camelKey = __RUNTIME_COMPILE__ ? camelize(key) : key
-      // any non-declared data are put into a separate `attrs` object
-      // for spreading
+      // prop option names are camelized during normalization, so to support
+      // kebab -> camel conversion here we need to camelize the key.
+      const camelKey = camelize(key)
       if (hasDeclaredProps && !hasOwn(options, camelKey)) {
-        ;(attrs || (attrs = {}))[camelKey] = rawProps[key]
+        // Any non-declared props are put into a separate `attrs` object
+        // for spreading. Make sure to preserve original key casing
+        ;(attrs || (attrs = {}))[key] = rawProps[key]
       } else {
         setProp(camelKey, rawProps[key])
       }
@@ -164,9 +166,11 @@ export function resolveProps(
       }
       // runtime validation
       if (__DEV__ && rawProps) {
-        let rawValue = rawProps[key]
-        if (__RUNTIME_COMPILE__ && !(key in rawProps)) {
+        let rawValue
+        if (!(key in rawProps) && hyphenate(key) in rawProps) {
           rawValue = rawProps[hyphenate(key)]
+        } else {
+          rawValue = rawProps[key]
         }
         validateProp(key, toRaw(rawValue), opt, isAbsent)
       }