fix(compiler-core): should attach key to single element child of <template v-for>
(#1910)
This commit is contained in:
parent
7ffb79c563
commit
69cfed6b31
@ -104,6 +104,23 @@ return function render(_ctx, _cache) {
|
|||||||
}"
|
}"
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`compiler: v-for codegen template v-for key injection with single child 1`] = `
|
||||||
|
"const _Vue = Vue
|
||||||
|
|
||||||
|
return function render(_ctx, _cache) {
|
||||||
|
with (_ctx) {
|
||||||
|
const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createBlock: _createBlock, createVNode: _createVNode } = _Vue
|
||||||
|
|
||||||
|
return (_openBlock(true), _createBlock(_Fragment, null, _renderList(items, (item) => {
|
||||||
|
return (_openBlock(), _createBlock(\\"span\\", {
|
||||||
|
key: item.id,
|
||||||
|
id: item.id
|
||||||
|
}, null, 8 /* PROPS */, [\\"id\\"]))
|
||||||
|
}), 128 /* KEYED_FRAGMENT */))
|
||||||
|
}
|
||||||
|
}"
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`compiler: v-for codegen template v-for w/ <slot/> 1`] = `
|
exports[`compiler: v-for codegen template v-for w/ <slot/> 1`] = `
|
||||||
"const _Vue = Vue
|
"const _Vue = Vue
|
||||||
|
|
||||||
|
@ -770,6 +770,29 @@ describe('compiler: v-for', () => {
|
|||||||
expect(generate(root).code).toMatchSnapshot()
|
expect(generate(root).code).toMatchSnapshot()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// #1907
|
||||||
|
test('template v-for key injection with single child', () => {
|
||||||
|
const {
|
||||||
|
root,
|
||||||
|
node: { codegenNode }
|
||||||
|
} = parseWithForTransform(
|
||||||
|
'<template v-for="item in items" :key="item.id"><span :id="item.id" /></template>'
|
||||||
|
)
|
||||||
|
expect(assertSharedCodegen(codegenNode, true)).toMatchObject({
|
||||||
|
source: { content: `items` },
|
||||||
|
params: [{ content: `item` }],
|
||||||
|
innerVNodeCall: {
|
||||||
|
type: NodeTypes.VNODE_CALL,
|
||||||
|
tag: `"span"`,
|
||||||
|
props: createObjectMatcher({
|
||||||
|
key: '[item.id]',
|
||||||
|
id: '[item.id]'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
expect(generate(root).code).toMatchSnapshot()
|
||||||
|
})
|
||||||
|
|
||||||
test('v-for on <slot/>', () => {
|
test('v-for on <slot/>', () => {
|
||||||
const {
|
const {
|
||||||
root,
|
root,
|
||||||
|
@ -145,6 +145,9 @@ export const transformFor = createStructuralDirectiveTransform(
|
|||||||
// but mark it as a block.
|
// but mark it as a block.
|
||||||
childBlock = (children[0] as PlainElementNode)
|
childBlock = (children[0] as PlainElementNode)
|
||||||
.codegenNode as VNodeCall
|
.codegenNode as VNodeCall
|
||||||
|
if (isTemplate && keyProperty) {
|
||||||
|
injectProp(childBlock, keyProperty, context)
|
||||||
|
}
|
||||||
childBlock.isBlock = !isStableFragment
|
childBlock.isBlock = !isStableFragment
|
||||||
if (childBlock.isBlock) {
|
if (childBlock.isBlock) {
|
||||||
helper(OPEN_BLOCK)
|
helper(OPEN_BLOCK)
|
||||||
|
Loading…
Reference in New Issue
Block a user