Преглед на файлове

fix(core): generate fragment root with patchFlag + optimize fragment w/ patchFlag

Evan You преди 6 години
родител
ревизия
ef50c333ce
променени са 3 файла, в които са добавени 13 реда и са изтрити 3 реда
  1. 11 2
      packages/compiler-core/src/transform.ts
  2. 1 1
      packages/compiler-core/src/transforms/vFor.ts
  3. 1 0
      packages/runtime-core/src/renderer.ts

+ 11 - 2
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
     )

+ 1 - 1
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
 

+ 1 - 0
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