diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap index 6ecefb03..1a10ec98 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/hoistStatic.spec.ts.snap @@ -1,6 +1,23 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`compiler: hositStatic transform hoist nested static tree 1`] = ` +exports[`compiler: hoistStatic transform hoist element with static key 1`] = ` +"const _Vue = Vue +const _createVNode = Vue.createVNode + +const _hoisted_1 = _createVNode(\\"div\\", { key: \\"foo\\" }) + +return function render() { + with (this) { + const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + + return (_openBlock(), _createBlock(\\"div\\", null, [ + _hoisted_1 + ])) + } +}" +`; + +exports[`compiler: hoistStatic transform hoist nested static tree 1`] = ` "const _Vue = Vue const _createVNode = Vue.createVNode @@ -20,7 +37,7 @@ return function render() { }" `; -exports[`compiler: hositStatic transform hoist siblings with common non-hoistable parent 1`] = ` +exports[`compiler: hoistStatic transform hoist siblings with common non-hoistable parent 1`] = ` "const _Vue = Vue const _createVNode = Vue.createVNode @@ -39,7 +56,7 @@ return function render() { }" `; -exports[`compiler: hositStatic transform hoist simple element 1`] = ` +exports[`compiler: hoistStatic transform hoist simple element 1`] = ` "const _Vue = Vue const _createVNode = Vue.createVNode @@ -56,7 +73,7 @@ return function render() { }" `; -exports[`compiler: hositStatic transform hoist static props for elements with directives 1`] = ` +exports[`compiler: hoistStatic transform hoist static props for elements with directives 1`] = ` "const _Vue = Vue const _createVNode = Vue.createVNode @@ -77,7 +94,7 @@ return function render() { }" `; -exports[`compiler: hositStatic transform hoist static props for elements with dynamic text children 1`] = ` +exports[`compiler: hoistStatic transform hoist static props for elements with dynamic text children 1`] = ` "const _Vue = Vue const _createVNode = Vue.createVNode @@ -94,7 +111,7 @@ return function render() { }" `; -exports[`compiler: hositStatic transform hoist static props for elements with unhoistable children 1`] = ` +exports[`compiler: hoistStatic transform hoist static props for elements with unhoistable children 1`] = ` "const _Vue = Vue const _createVNode = Vue.createVNode @@ -115,7 +132,7 @@ return function render() { }" `; -exports[`compiler: hositStatic transform should NOT hoist components 1`] = ` +exports[`compiler: hoistStatic transform should NOT hoist components 1`] = ` "const _Vue = Vue return function render() { @@ -131,7 +148,21 @@ return function render() { }" `; -exports[`compiler: hositStatic transform should NOT hoist element with dynamic props 1`] = ` +exports[`compiler: hoistStatic transform should NOT hoist element with dynamic key 1`] = ` +"const _Vue = Vue + +return function render() { + with (this) { + const { createVNode: _createVNode, createBlock: _createBlock, openBlock: _openBlock } = _Vue + + return (_openBlock(), _createBlock(\\"div\\", null, [ + _createVNode(\\"div\\", { key: foo }) + ])) + } +}" +`; + +exports[`compiler: hoistStatic transform should NOT hoist element with dynamic props 1`] = ` "const _Vue = Vue return function render() { @@ -145,7 +176,7 @@ return function render() { }" `; -exports[`compiler: hositStatic transform should NOT hoist root node 1`] = ` +exports[`compiler: hoistStatic transform should NOT hoist root node 1`] = ` "const _Vue = Vue return function render() { @@ -157,7 +188,7 @@ return function render() { }" `; -exports[`compiler: hositStatic transform should hoist v-for children if static 1`] = ` +exports[`compiler: hoistStatic transform should hoist v-for children if static 1`] = ` "const _Vue = Vue const _createVNode = Vue.createVNode @@ -179,7 +210,7 @@ return function render() { }" `; -exports[`compiler: hositStatic transform should hoist v-if props/children if static 1`] = ` +exports[`compiler: hoistStatic transform should hoist v-if props/children if static 1`] = ` "const _Vue = Vue const _createVNode = Vue.createVNode diff --git a/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts b/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts index 7e5e2010..05cb7bdd 100644 --- a/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts +++ b/packages/compiler-core/__tests__/transforms/hoistStatic.spec.ts @@ -42,7 +42,7 @@ function transformWithHoist(template: string) { } } -describe('compiler: hositStatic transform', () => { +describe('compiler: hoistStatic transform', () => { test('should NOT hoist root node', () => { // if the whole tree is static, the root still needs to be a block // so that it's patched in optimized mode to skip children @@ -187,6 +187,52 @@ describe('compiler: hositStatic transform', () => { expect(generate(root).code).toMatchSnapshot() }) + test('hoist element with static key', () => { + const { root, args } = transformWithHoist(`