fix(compiler-core): avoid override user keys when injecting branch key (#630)

This commit is contained in:
Ruijia Tang
2020-01-20 23:15:53 +08:00
committed by Evan You
parent c71ca354b9
commit aca2c2a81e
3 changed files with 40 additions and 1 deletions

View File

@@ -253,7 +253,18 @@ export function injectProp(
}
propsWithInjection = props
} else if (props.type === NodeTypes.JS_OBJECT_EXPRESSION) {
props.properties.unshift(prop)
let alreadyExists = false
// check existing key to avoid overriding user provided keys
if (prop.key.type === NodeTypes.SIMPLE_EXPRESSION) {
const propKeyName = prop.key.content
alreadyExists = props.properties.some(p => (
p.key.type === NodeTypes.SIMPLE_EXPRESSION &&
p.key.content === propKeyName
))
}
if (!alreadyExists) {
props.properties.unshift(prop)
}
propsWithInjection = props
} else {
// single v-bind with expression, return a merged replacement