]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): should preserve props casing when component has no declared props
authorEvan You <yyx990803@gmail.com>
Mon, 6 Jan 2020 20:05:57 +0000 (15:05 -0500)
committerEvan You <yyx990803@gmail.com>
Mon, 6 Jan 2020 20:05:57 +0000 (15:05 -0500)
close #583

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

index 9e7b498bc5535f590245d480ef077b8a6378f475..59da83977b115b7fa8c7b3bdd30d3c6e1de30ea6 100644 (file)
@@ -32,7 +32,8 @@ describe('attribute fallthrough', () => {
             id: 'test',
             class: 'c' + count.value,
             style: { color: count.value ? 'red' : 'green' },
-            onClick: inc
+            onClick: inc,
+            'data-id': 1
           })
       }
     }
@@ -66,6 +67,7 @@ describe('attribute fallthrough', () => {
     expect(node.getAttribute('class')).toBe('c2 c0')
     expect(node.style.color).toBe('green')
     expect(node.style.fontWeight).toBe('bold')
+    expect(node.dataset.id).toBe('1')
     node.dispatchEvent(new CustomEvent('click'))
     expect(click).toHaveBeenCalled()
 
index 54d67ed4d35d0b2f42d8d64d8d7c327aa4c450a5..a0acd982f2a29b765e6864e8e65adffcb2fa8106 100644 (file)
@@ -127,13 +127,17 @@ export function resolveProps(
       if (key === 'key' || key === 'ref') continue
       // 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)) {
-        // 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]
+      if (hasDeclaredProps) {
+        const camelKey = camelize(key)
+        if (hasOwn(options, camelKey)) {
+          setProp(camelKey, rawProps[key])
+        } else {
+          // 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])
+        setProp(key, rawProps[key])
       }
     }
   }