MCPcopy
hub / github.com/vuejs/core / createRootCodegen

Function createRootCodegen

packages/compiler-core/src/transform.ts:358–404  ·  view source on GitHub ↗
(root: RootNode, context: TransformContext)

Source from the content-addressed store, hash-verified

356}
357
358function createRootCodegen(root: RootNode, context: TransformContext) {
359 const { helper } = context
360 const { children } = root
361 if (children.length === 1) {
362 const singleElementRootChild = getSingleElementRoot(root)
363 // if the single child is an element, turn it into a block.
364 if (singleElementRootChild && singleElementRootChild.codegenNode) {
365 // single element root is never hoisted so codegenNode will never be
366 // SimpleExpressionNode
367 const codegenNode = singleElementRootChild.codegenNode
368 if (codegenNode.type === NodeTypes.VNODE_CALL) {
369 convertToBlock(codegenNode, context)
370 }
371 root.codegenNode = codegenNode
372 } else {
373 // - single <slot/>, IfNode, ForNode: already blocks.
374 // - single text node: always patched.
375 // root codegen falls through via genNode()
376 root.codegenNode = children[0]
377 }
378 } else if (children.length > 1) {
379 // root has multiple nodes - return a fragment block.
380 let patchFlag = PatchFlags.STABLE_FRAGMENT
381 // check if the fragment actually contains a single valid child with
382 // the rest being comments
383 if (
384 __DEV__ &&
385 children.filter(c => c.type !== NodeTypes.COMMENT).length === 1
386 ) {
387 patchFlag |= PatchFlags.DEV_ROOT_FRAGMENT
388 }
389 root.codegenNode = createVNodeCall(
390 context,
391 helper(FRAGMENT),
392 undefined,
393 root.children,
394 patchFlag,
395 undefined,
396 undefined,
397 true,
398 undefined,
399 false /* isComponent */,
400 )
401 } else {
402 // no children = noop. codegen will return null.
403 }
404}
405
406export function traverseChildren(
407 parent: ParentNode,

Callers 1

transformFunction · 0.85

Calls 5

getSingleElementRootFunction · 0.90
convertToBlockFunction · 0.90
createVNodeCallFunction · 0.90
helperFunction · 0.70
filterMethod · 0.65

Tested by

no test coverage detected