]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): fix kebab-case prop required warning
authorEvan You <yyx990803@gmail.com>
Sat, 27 Mar 2021 15:16:39 +0000 (11:16 -0400)
committerEvan You <yyx990803@gmail.com>
Sat, 27 Mar 2021 15:16:39 +0000 (11:16 -0400)
fix #3495
ref #3363

packages/runtime-core/__tests__/componentProps.spec.ts
packages/runtime-core/src/componentProps.ts

index 7c90a54a12b10ba219cc0e8f8e2464fff144b0fb..a97c9d48190c1570158ce186a528fb421e6dc4c9 100644 (file)
@@ -319,6 +319,25 @@ describe('component props', () => {
     expect(`Missing required prop: "num"`).toHaveBeenWarned()
   })
 
+  // #3495
+  test('should not warn required props using kebab-case', async () => {
+    const Comp = {
+      props: {
+        fooBar: { type: String, required: true }
+      },
+      setup() {
+        return () => null
+      }
+    }
+    render(
+      h(Comp, {
+        'foo-bar': 'hello'
+      }),
+      nodeOps.createElement('div')
+    )
+    expect(`Missing required prop: "fooBar"`).not.toHaveBeenWarned()
+  })
+
   test('merging props from mixins and extends', () => {
     let setupProps: any
     let renderProxy: any
index 39c15471f809e708f4b4108c6cc2a6e4163363b0..3ea727ddcc3101e381ec4ebc6dfa6e7de3a2855f 100644 (file)
@@ -480,7 +480,12 @@ function validateProps(
   for (const key in options) {
     let opt = options[key]
     if (opt == null) continue
-    validateProp(key, resolvedValues[key], opt, !hasOwn(rawProps, key))
+    validateProp(
+      key,
+      resolvedValues[key],
+      opt,
+      !hasOwn(rawProps, key) && !hasOwn(rawProps, hyphenate(key))
+    )
   }
 }