refactor(compiler-core): simplify hoistStatic check for nodes without patchFlag

close #1912
This commit is contained in:
Evan You
2020-08-20 11:43:34 -04:00
parent 255a2bd178
commit 91700fbec2
4 changed files with 42 additions and 24 deletions

View File

@@ -271,6 +271,22 @@ return function render(_ctx, _cache) {
}"
`;
exports[`compiler: hoistStatic transform prefixIdentifiers should NOT hoist keyed template v-for with plain element 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(), _createBlock(\\"div\\", null, [
(_openBlock(true), _createBlock(_Fragment, null, _renderList(items, (item) => {
return (_openBlock(), _createBlock(\\"span\\", { key: item }))
}), 128 /* KEYED_FRAGMENT */))
]))
}
}"
`;
exports[`compiler: hoistStatic transform should NOT hoist components 1`] = `
"const _Vue = Vue

View File

@@ -600,5 +600,13 @@ describe('compiler: hoistStatic transform', () => {
}).code
).toMatchSnapshot()
})
test('should NOT hoist keyed template v-for with plain element child', () => {
const root = transformWithHoist(
`<div><template v-for="item in items" :key="item"><span/></template></div>`
)
expect(root.hoists.length).toBe(0)
expect(generate(root).code).toMatchSnapshot()
})
})
})