fix(runtime-core): ensure props definition objects are not mutated during props normalization (close: #6915) (#6916)

This commit is contained in:
Thorsten Lünborg 2022-10-22 11:20:02 +02:00 committed by GitHub
parent e6224f4256
commit 54b6ba32ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View 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)
})
})

View 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)