dx(compiler-core): warn on <template v-for> key misplacement
Note: the behavior is different from Vue 2. `<template v-for>` are compiled into an array of Fragment vnodes so the key should be placed the `<template>` for v-for to use it for diffing.
This commit is contained in:
@@ -263,6 +263,34 @@ describe('compiler: v-for', () => {
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
test('<template v-for> key placement', () => {
|
||||
const onError = jest.fn()
|
||||
parseWithForTransform(
|
||||
`
|
||||
<template v-for="item in items">
|
||||
<div :key="item.id"/>
|
||||
</template>`,
|
||||
{ onError }
|
||||
)
|
||||
|
||||
expect(onError).toHaveBeenCalledTimes(1)
|
||||
expect(onError).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
code: ErrorCodes.X_V_FOR_TEMPLATE_KEY_PLACEMENT
|
||||
})
|
||||
)
|
||||
|
||||
// should not warn on nested v-for keys
|
||||
parseWithForTransform(
|
||||
`
|
||||
<template v-for="item in items">
|
||||
<div v-for="c in item.children" :key="c.id"/>
|
||||
</template>`,
|
||||
{ onError }
|
||||
)
|
||||
expect(onError).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('source location', () => {
|
||||
|
||||
Reference in New Issue
Block a user