fix(compiler-core): elements with dynamic keys should be forced into blocks
fix #916
This commit is contained in:
@@ -292,10 +292,10 @@ exports[`compiler: hoistStatic transform should NOT hoist element with dynamic k
|
||||
|
||||
return function render(_ctx, _cache) {
|
||||
with (_ctx) {
|
||||
const { createVNode: _createVNode, openBlock: _openBlock, createBlock: _createBlock } = _Vue
|
||||
const { openBlock: _openBlock, createBlock: _createBlock, createVNode: _createVNode } = _Vue
|
||||
|
||||
return (_openBlock(), _createBlock(\\"div\\", null, [
|
||||
_createVNode(\\"div\\", { key: foo })
|
||||
(_openBlock(), _createBlock(\\"div\\", { key: foo }))
|
||||
]))
|
||||
}
|
||||
}"
|
||||
|
||||
@@ -36,7 +36,7 @@ exports[`compiler: v-for codegen keyed v-for 1`] = `
|
||||
|
||||
return function render(_ctx, _cache) {
|
||||
with (_ctx) {
|
||||
const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createBlock: _createBlock, createVNode: _createVNode } = _Vue
|
||||
const { renderList: _renderList, Fragment: _Fragment, openBlock: _openBlock, createBlock: _createBlock } = _Vue
|
||||
|
||||
return (_openBlock(true), _createBlock(_Fragment, null, _renderList(items, (item) => {
|
||||
return (_openBlock(), _createBlock(\\"span\\", { key: item }))
|
||||
|
||||
@@ -861,4 +861,17 @@ describe('compiler: element transform', () => {
|
||||
isBlock: true
|
||||
})
|
||||
})
|
||||
|
||||
// #938
|
||||
test('element with dynamic keys should be forced into blocks', () => {
|
||||
const ast = parse(`<div><div :key="foo" /></div>`)
|
||||
transform(ast, {
|
||||
nodeTransforms: [transformElement]
|
||||
})
|
||||
expect((ast as any).children[0].children[0].codegenNode).toMatchObject({
|
||||
type: NodeTypes.VNODE_CALL,
|
||||
tag: `"div"`,
|
||||
isBlock: true
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user