]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): ensure props definition objects are not mutated during props norma...
authorThorsten Lünborg <t.luenborg@googlemail.com>
Sat, 22 Oct 2022 09:20:02 +0000 (11:20 +0200)
committerGitHub <noreply@github.com>
Sat, 22 Oct 2022 09:20:02 +0000 (11:20 +0200)
packages/runtime-core/__tests__/componentProps.spec.ts
packages/runtime-core/src/componentProps.ts

index 40725dfcd135508d8833c37c46690c3892d51643..cdb77838e316a2d949d0b7bc40aca487a6ff5c3e 100644 (file)
@@ -595,4 +595,23 @@ describe('component props', () => {
       JSON.stringify(attrs) + Object.keys(attrs)
     )
   })
+
+  // #691ef
+  test('should not mutate original props long-form definition object', () => {
+    const props = {
+      msg: {
+        type: String
+      }
+    }
+    const Comp = defineComponent({
+      props,
+      render() {}
+    })
+
+    const root = nodeOps.createElement('div')
+
+    render(h(Comp, { msg: 'test' }), root)
+
+    expect(Object.keys(props.msg).length).toBe(1)
+  })
 })
index 09b487811b5b85aa16852fccf42afe73f975b622..d59a4e94699b177169775bea0fdf0f6b83b3e042 100644 (file)
@@ -522,7 +522,7 @@ export function normalizePropsOptions(
       if (validatePropName(normalizedKey)) {
         const opt = raw[key]
         const prop: NormalizedProp = (normalized[normalizedKey] =
-          isArray(opt) || isFunction(opt) ? { type: opt } : opt)
+          isArray(opt) || isFunction(opt) ? { type: opt } : { ...opt })
         if (prop) {
           const booleanIndex = getTypeIndex(Boolean, prop.type)
           const stringIndex = getTypeIndex(String, prop.type)