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

@@ -105,3 +105,17 @@ return function render() {
}
}"
`;
exports[`compiler: v-if codegen v-if with key 1`] = `
"const _Vue = Vue
return function render() {
with (this) {
const { openBlock: _openBlock, createVNode: _createVNode, createBlock: _createBlock, createCommentVNode: _createCommentVNode } = _Vue
return (_openBlock(), ok
? _createBlock(\\"div\\", { key: \\"some-key\\" })
: _createCommentVNode(\\"v-if\\", true))
}
}"
`;

View File

@@ -530,6 +530,20 @@ describe('compiler: v-if', () => {
)
})
test('v-if with key', () => {
const {
root,
node: { codegenNode }
} = parseWithIfTransform(`<div v-if="ok" key="some-key"/>`)
const branch1 = (codegenNode.expressions[1] as ConditionalExpression)
.consequent as CallExpression
expect(branch1.arguments).toMatchObject([
`"div"`,
createObjectMatcher({ key: 'some-key' })
])
expect(generate(root).code).toMatchSnapshot()
})
test.todo('with comments')
})
})