refactor(compiler-core): emit error on v-if key usage
This commit is contained in:
@@ -145,17 +145,3 @@ return function render(_ctx, _cache) {
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`compiler: v-if codegen v-if with key 1`] = `
|
||||
"const _Vue = Vue
|
||||
|
||||
return function render(_ctx, _cache) {
|
||||
with (_ctx) {
|
||||
const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock, createCommentVNode: _createCommentVNode } = _Vue
|
||||
|
||||
return ok
|
||||
? (_openBlock(), _createBlock(\\"div\\", { key: \\"some-key\\" }))
|
||||
: _createCommentVNode(\\"v-if\\", true)
|
||||
}
|
||||
}"
|
||||
`;
|
||||
|
||||
@@ -282,6 +282,16 @@ describe('compiler: v-if', () => {
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
test('error on user key', () => {
|
||||
const onError = jest.fn()
|
||||
parseWithIfTransform(`<div v-if="ok" :key="1" />`, { onError })
|
||||
expect(onError.mock.calls[0]).toMatchObject([
|
||||
{
|
||||
code: ErrorCodes.X_V_IF_KEY
|
||||
}
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
describe('codegen', () => {
|
||||
@@ -581,18 +591,6 @@ describe('compiler: v-if', () => {
|
||||
expect(branch1.props).toMatchObject(createObjectMatcher({ key: `[0]` }))
|
||||
})
|
||||
|
||||
test('v-if with key', () => {
|
||||
const {
|
||||
root,
|
||||
node: { codegenNode }
|
||||
} = parseWithIfTransform(`<div v-if="ok" key="some-key"/>`)
|
||||
expect(codegenNode.consequent).toMatchObject({
|
||||
tag: `"div"`,
|
||||
props: createObjectMatcher({ key: 'some-key' })
|
||||
})
|
||||
expect(generate(root).code).toMatchSnapshot()
|
||||
})
|
||||
|
||||
test('with comments', () => {
|
||||
const { node } = parseWithIfTransform(`
|
||||
<template v-if="ok">
|
||||
|
||||
Reference in New Issue
Block a user