From: Evan You Date: Thu, 12 Dec 2019 22:58:32 +0000 (-0500) Subject: fix(core): generate fragment root with patchFlag + optimize fragment w/ patchFlag X-Git-Tag: v3.0.0-alpha.0~57 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ef50c333ce0d6b48dfc9e1f1219f26d6f2406e76;p=thirdparty%2Fvuejs%2Fcore.git fix(core): generate fragment root with patchFlag + optimize fragment w/ patchFlag --- diff --git a/packages/compiler-core/src/transform.ts b/packages/compiler-core/src/transform.ts index 0c01cd841a..dfa73edc3e 100644 --- a/packages/compiler-core/src/transform.ts +++ b/packages/compiler-core/src/transform.ts @@ -18,7 +18,13 @@ import { CacheExpression, createCacheExpression } from './ast' -import { isString, isArray, NOOP } from '@vue/shared' +import { + isString, + isArray, + NOOP, + PatchFlags, + PatchFlagNames +} from '@vue/shared' import { defaultOnError } from './errors' import { TO_STRING, @@ -283,7 +289,10 @@ function finalizeRoot(root: RootNode, context: TransformContext) { createCallExpression(helper(CREATE_BLOCK), [ helper(FRAGMENT), `null`, - root.children + root.children, + `${PatchFlags.UNKEYED_FRAGMENT} /* ${ + PatchFlagNames[PatchFlags.UNKEYED_FRAGMENT] + } */` ]), context ) diff --git a/packages/compiler-core/src/transforms/vFor.ts b/packages/compiler-core/src/transforms/vFor.ts index c09a19f1ee..418999cbc1 100644 --- a/packages/compiler-core/src/transforms/vFor.ts +++ b/packages/compiler-core/src/transforms/vFor.ts @@ -79,7 +79,7 @@ export const transformFor = createStructuralDirectiveTransform( helper(FRAGMENT), `null`, renderExp, - fragmentFlag + (__DEV__ ? ` /* ${PatchFlagNames[fragmentFlag]} */` : ``) + `${fragmentFlag} /* ${PatchFlagNames[fragmentFlag]} */` ]) ]) as ForCodegenNode diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index b688525ddc..d3c38c3dc3 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -1033,6 +1033,7 @@ export function createRenderer< } // fast path if (patchFlag > 0) { + optimized = true if (patchFlag & PatchFlags.KEYED_FRAGMENT) { // this could be either fully-keyed or mixed (some keyed some not) // presence of patchFlag means children are guaranteed to be arrays