How to use the @vue/shared.PatchFlags.STABLE_FRAGMENT function in @vue/shared

To help you get started, we’ve selected a few @vue/shared examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vuejs / vue-next / packages / compiler-core / src / transforms / vFor.ts View on Github external
childBlock = slotOutlet.codegenNode as SlotOutletCodegenNode
        if (isTemplate && keyProperty) {
          // <template></template>
          // we need to inject the key to the renderSlot() call.
          // the props for renderSlot is passed as the 3rd argument.
          injectProp(childBlock, keyProperty, context)
        }
      } else if (isTemplate) {
        // <template>
        // should generate a fragment block for each loop
        childBlock = createBlockExpression(
          createCallExpression(helper(CREATE_BLOCK), [
            helper(FRAGMENT),
            keyProperty ? createObjectExpression([keyProperty]) : `null`,
            node.children,
            `${PatchFlags.STABLE_FRAGMENT} /* ${
              PatchFlagNames[PatchFlags.STABLE_FRAGMENT]
            } */`
          ]),
          context
        )
      } else {
        // Normal element v-for. Directly use the child's codegenNode
        // arguments, but replace createVNode() with createBlock()
        let codegenNode = node.codegenNode as ElementCodegenNode
        if (codegenNode.callee === WITH_DIRECTIVES) {
          codegenNode.arguments[0].callee = helper(CREATE_BLOCK)
        } else {
          codegenNode.callee = helper(CREATE_BLOCK)
        }
        childBlock = createBlockExpression(codegenNode, context)
      }</template>
github vuejs / vue-next / packages / compiler-core / src / transform.ts View on Github external
}
    } else {
      // - single , IfNode, ForNode: already blocks.
      // - single text node: always patched.
      // root codegen falls through via genNode()
      root.codegenNode = child
    }
  } else if (children.length &gt; 1) {
    // root has multiple nodes - return a fragment block.
    root.codegenNode = createBlockExpression(
      createCallExpression(helper(CREATE_BLOCK), [
        helper(FRAGMENT),
        `null`,
        root.children,
        `${PatchFlags.STABLE_FRAGMENT} /* ${
          PatchFlagNames[PatchFlags.STABLE_FRAGMENT]
        } */`
      ]),
      context
    )
  } else {
    // no children = noop. codegen will return null.
  }
  // finalize meta information
  root.helpers = [...context.helpers]
  root.components = [...context.components]
  root.directives = [...context.directives]
  root.imports = [...context.imports]
  root.hoists = context.hoists
  root.cached = context.cached
}
github vuejs / vue-next / packages / runtime-core / src / renderer.ts View on Github external
hostInsert(fragmentStartAnchor, container, anchor)
      hostInsert(fragmentEndAnchor, container, anchor)
      // a fragment can only have array children
      // since they are either generated by the compiler, or implicitly created
      // from arrays.
      mountChildren(
        n2.children as HostVNodeChildren,
        container,
        fragmentEndAnchor,
        parentComponent,
        parentSuspense,
        isSVG,
        optimized
      )
    } else {
      if (patchFlag &amp; PatchFlags.STABLE_FRAGMENT &amp;&amp; dynamicChildren != null) {
        // a stable fragment (template root or <template>) doesn't need to
        // patch children order, but it may contain dynamicChildren.
        patchBlockChildren(
          n1.dynamicChildren!,
          dynamicChildren,
          container,
          parentComponent,
          parentSuspense,
          isSVG
        )
      } else {
        // keyed / unkeyed, or manual fragments.
        // for keyed &amp; unkeyed, since they are compiler generated from v-for,
        // each child is guaranteed to be a block so the fragment will never
        // have dynamicChildren.
        patchChildren(</template>
github vuejs / vue-next / packages / compiler-core / src / transforms / vFor.ts View on Github external
if (isTemplate &amp;&amp; keyProperty) {
          // <template></template>
          // we need to inject the key to the renderSlot() call.
          // the props for renderSlot is passed as the 3rd argument.
          injectProp(childBlock, keyProperty, context)
        }
      } else if (isTemplate) {
        // <template>
        // should generate a fragment block for each loop
        childBlock = createBlockExpression(
          createCallExpression(helper(CREATE_BLOCK), [
            helper(FRAGMENT),
            keyProperty ? createObjectExpression([keyProperty]) : `null`,
            node.children,
            `${PatchFlags.STABLE_FRAGMENT} /* ${
              PatchFlagNames[PatchFlags.STABLE_FRAGMENT]
            } */`
          ]),
          context
        )
      } else {
        // Normal element v-for. Directly use the child's codegenNode
        // arguments, but replace createVNode() with createBlock()
        let codegenNode = node.codegenNode as ElementCodegenNode
        if (codegenNode.callee === WITH_DIRECTIVES) {
          codegenNode.arguments[0].callee = helper(CREATE_BLOCK)
        } else {
          codegenNode.callee = helper(CREATE_BLOCK)
        }
        childBlock = createBlockExpression(codegenNode, context)
      }
</template>
github vuejs / vue-next / packages / compiler-core / src / transform.ts View on Github external
root.codegenNode = codegenNode
      }
    } else {
      // - single , IfNode, ForNode: already blocks.
      // - single text node: always patched.
      // root codegen falls through via genNode()
      root.codegenNode = child
    }
  } else if (children.length &gt; 1) {
    // root has multiple nodes - return a fragment block.
    root.codegenNode = createBlockExpression(
      createCallExpression(helper(CREATE_BLOCK), [
        helper(FRAGMENT),
        `null`,
        root.children,
        `${PatchFlags.STABLE_FRAGMENT} /* ${
          PatchFlagNames[PatchFlags.STABLE_FRAGMENT]
        } */`
      ]),
      context
    )
  } else {
    // no children = noop. codegen will return null.
  }
  // finalize meta information
  root.helpers = [...context.helpers]
  root.components = [...context.components]
  root.directives = [...context.directives]
  root.imports = [...context.imports]
  root.hoists = context.hoists
  root.cached = context.cached
}
github vuejs / vue-next / packages / compiler-core / __tests__ / transform.spec.ts View on Github external
test('multiple children', () =&gt; {
      const ast = transformWithCodegen(`<div><div>`)
      expect(ast.codegenNode).toMatchObject(
        createBlockMatcher([
          FRAGMENT,
          `null`,
          [
            { type: NodeTypes.ELEMENT, tag: `div` },
            { type: NodeTypes.ELEMENT, tag: `div` }
          ],
          genFlagText(PatchFlags.STABLE_FRAGMENT)
        ])
      )
    })
  })</div></div>
github vuejs / vue-next / packages / compiler-core / __tests__ / transforms / vFor.spec.ts View on Github external
root,
        node: { codegenNode }
      } = parseWithForTransform(
        '<template>hello<span></span></template>'
      )
      expect(assertSharedCodegen(codegenNode)).toMatchObject({
        source: { content: `items` },
        params: [{ content: `item` }],
        blockArgs: [
          FRAGMENT,
          `null`,
          [
            { type: NodeTypes.TEXT, content: `hello` },
            { type: NodeTypes.ELEMENT, tag: `span` }
          ],
          genFlagText(PatchFlags.STABLE_FRAGMENT)
        ]
      })
      expect(generate(root).code).toMatchSnapshot()
    })
github vuejs / vue-next / packages / compiler-core / __tests__ / transforms / vFor.spec.ts View on Github external
} = parseWithForTransform(
        '<template>hello<span></span></template>'
      )
      expect(assertSharedCodegen(codegenNode, true)).toMatchObject({
        source: { content: `items` },
        params: [{ content: `item` }],
        blockArgs: [
          FRAGMENT,
          createObjectMatcher({
            key: `[item]`
          }),
          [
            { type: NodeTypes.TEXT, content: `hello` },
            { type: NodeTypes.ELEMENT, tag: `span` }
          ],
          genFlagText(PatchFlags.STABLE_FRAGMENT)
        ]
      })
      expect(generate(root).code).toMatchSnapshot()
    })