feat(compiler-core): do not generate TEXT flag if child is constant

This commit is contained in:
Evan You
2019-10-16 12:00:55 -04:00
parent 6607edab2d
commit 6a75c3463b
5 changed files with 52 additions and 13 deletions

View File

@@ -190,7 +190,7 @@ exports[`compiler: hoistStatic transform prefixIdentifiers hoist nested static t
"const _Vue = Vue
const _createVNode = Vue.createVNode
const _hoisted_1 = _createVNode(\\"span\\", { foo: 0 }, _toString(1), 1 /* TEXT */)
const _hoisted_1 = _createVNode(\\"span\\", { foo: 0 }, _toString(1))
return function render() {
with (this) {
@@ -300,6 +300,20 @@ return function render() {
}"
`;
exports[`compiler: hoistStatic transform should NOT hoist element with dynamic ref 1`] = `
"const _Vue = Vue
return function render() {
with (this) {
const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue
return (_openBlock(), _createBlock(\\"div\\", null, [
_createVNode(\\"div\\", { ref: foo }, null, 32 /* NEED_PATCH */)
]))
}
}"
`;
exports[`compiler: hoistStatic transform should NOT hoist root node 1`] = `
"const _Vue = Vue

View File

@@ -273,6 +273,28 @@ describe('compiler: hoistStatic transform', () => {
expect(generate(root).code).toMatchSnapshot()
})
test('should NOT hoist element with dynamic ref', () => {
const { root, args } = transformWithHoist(`<div><div :ref="foo"/></div>`)
expect(root.hoists.length).toBe(0)
expect(args[2]).toMatchObject([
{
type: NodeTypes.ELEMENT,
codegenNode: {
callee: CREATE_VNODE,
arguments: [
`"div"`,
createObjectMatcher({
ref: `[foo]`
}),
`null`,
genFlagText(PatchFlags.NEED_PATCH)
]
}
}
])
expect(generate(root).code).toMatchSnapshot()
})
test('hoist static props for elements with directives', () => {
const { root, args } = transformWithHoist(
`<div><div id="foo" v-foo/></div>`
@@ -521,8 +543,7 @@ describe('compiler: hoistStatic transform', () => {
isStatic: false,
isConstant: true
}
},
'1 /* TEXT */'
}
]
}
])