From a1da9c28a0a7030124b1deb9369685760c67be47 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 17 Mar 2020 11:36:56 -0400 Subject: [PATCH] fix(compiler-core): assign patchFlag for template v-if fragment fix #850 --- .../__tests__/__snapshots__/compile.spec.ts.snap | 6 +++--- .../__tests__/transforms/__snapshots__/vIf.spec.ts.snap | 4 ++-- packages/compiler-core/src/transforms/vIf.ts | 5 ++++- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap b/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap index 409bc203..0534a5eb 100644 --- a/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap +++ b/packages/compiler-core/__tests__/__snapshots__/compile.spec.ts.snap @@ -16,7 +16,7 @@ return function render(_ctx, _cache) { ? (_openBlock(), _createBlock(\\"div\\", { key: 0 }, \\"yes\\")) : (_openBlock(), _createBlock(_Fragment, { key: 1 }, [ _createTextVNode(\\"no\\") - ])), + ], 64 /* STABLE_FRAGMENT */)), (_openBlock(true), _createBlock(_Fragment, null, _renderList(list, (value, index) => { return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */) @@ -40,7 +40,7 @@ return function render(_ctx, _cache) { ? (_openBlock(), _createBlock(\\"div\\", { key: 0 }, \\"yes\\")) : (_openBlock(), _createBlock(_Fragment, { key: 1 }, [ _createTextVNode(\\"no\\") - ])), + ], 64 /* STABLE_FRAGMENT */)), (_openBlock(true), _createBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => { return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */) @@ -63,7 +63,7 @@ export function render(_ctx, _cache) { ? (_openBlock(), _createBlock(\\"div\\", { key: 0 }, \\"yes\\")) : (_openBlock(), _createBlock(_Fragment, { key: 1 }, [ _createTextVNode(\\"no\\") - ])), + ], 64 /* STABLE_FRAGMENT */)), (_openBlock(true), _createBlock(_Fragment, null, _renderList(_ctx.list, (value, index) => { return (_openBlock(), _createBlock(\\"div\\", null, [ _createVNode(\\"span\\", null, _toDisplayString(value + index), 1 /* TEXT */) diff --git a/packages/compiler-core/__tests__/transforms/__snapshots__/vIf.spec.ts.snap b/packages/compiler-core/__tests__/transforms/__snapshots__/vIf.spec.ts.snap index 3bd43610..73184e0a 100644 --- a/packages/compiler-core/__tests__/transforms/__snapshots__/vIf.spec.ts.snap +++ b/packages/compiler-core/__tests__/transforms/__snapshots__/vIf.spec.ts.snap @@ -26,7 +26,7 @@ return function render(_ctx, _cache) { _createVNode(\\"div\\"), \\"hello\\", _createVNode(\\"p\\") - ])) + ], 64 /* STABLE_FRAGMENT */)) : _createCommentVNode(\\"v-if\\", true) } }" @@ -71,7 +71,7 @@ return function render(_ctx, _cache) { ? (_openBlock(), _createBlock(\\"div\\", { key: 0 })) : orNot ? (_openBlock(), _createBlock(\\"p\\", { key: 1 })) - : (_openBlock(), _createBlock(_Fragment, { key: 2 }, [\\"fine\\"])) + : (_openBlock(), _createBlock(_Fragment, { key: 2 }, [\\"fine\\"], 64 /* STABLE_FRAGMENT */)) } }" `; diff --git a/packages/compiler-core/src/transforms/vIf.ts b/packages/compiler-core/src/transforms/vIf.ts index 0c0ecc4c..5394cb8f 100644 --- a/packages/compiler-core/src/transforms/vIf.ts +++ b/packages/compiler-core/src/transforms/vIf.ts @@ -29,6 +29,7 @@ import { OPEN_BLOCK } from '../runtimeHelpers' import { injectProp } from '../utils' +import { PatchFlags, PatchFlagNames } from '@vue/shared' export const transformIf = createStructuralDirectiveTransform( /^(if|else|else-if)$/, @@ -197,7 +198,9 @@ function createChildrenCodegenNode( helper(FRAGMENT), createObjectExpression([keyProperty]), children, - undefined, + `${PatchFlags.STABLE_FRAGMENT} /* ${ + PatchFlagNames[PatchFlags.STABLE_FRAGMENT] + } */`, undefined, undefined, true,