mirror of https://github.com/vuejs/core.git
fix(runtime-core): ensure props definition objects are not mutated during props normalization (close: #6915) (#6916)
This commit is contained in:
parent
e6224f4256
commit
54b6ba32ca
|
|
@ -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)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue