fix(compiler-core): v-if key error should only be checking same key on different branches

This commit is contained in:
Evan You
2020-08-04 12:01:07 -04:00
parent c3f8c780e7
commit de0c8a7e3e
5 changed files with 74 additions and 15 deletions

View File

@@ -285,10 +285,23 @@ describe('compiler: v-if', () => {
test('error on user key', () => {
const onError = jest.fn()
parseWithIfTransform(`<div v-if="ok" :key="1" />`, { onError })
// dynamic
parseWithIfTransform(
`<div v-if="ok" :key="a + 1" /><div v-else :key="a + 1" />`,
{ onError }
)
expect(onError.mock.calls[0]).toMatchObject([
{
code: ErrorCodes.X_V_IF_KEY
code: ErrorCodes.X_V_IF_SAME_KEY
}
])
// static
parseWithIfTransform(`<div v-if="ok" key="1" /><div v-else key="1" />`, {
onError
})
expect(onError.mock.calls[1]).toMatchObject([
{
code: ErrorCodes.X_V_IF_SAME_KEY
}
])
})