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

Function createChildrenCodegenNode

packages/compiler-core/src/transforms/vIf.ts:240–304  ·  view source on GitHub ↗
(
  branch: IfBranchNode,
  keyIndex: number,
  context: TransformContext,
)

Source from the content-addressed store, hash-verified

238}
239
240function createChildrenCodegenNode(
241 branch: IfBranchNode,
242 keyIndex: number,
243 context: TransformContext,
244): BlockCodegenNode | MemoExpression {
245 const { helper } = context
246 const keyProperty = createObjectProperty(
247 `key`,
248 createSimpleExpression(
249 `${keyIndex}`,
250 false,
251 locStub,
252 ConstantTypes.CAN_CACHE,
253 ),
254 )
255 const { children } = branch
256 const firstChild = children[0]
257 const needFragmentWrapper =
258 children.length !== 1 || firstChild.type !== NodeTypes.ELEMENT
259 if (needFragmentWrapper) {
260 if (children.length === 1 && firstChild.type === NodeTypes.FOR) {
261 // optimize away nested fragments when child is a ForNode
262 const vnodeCall = firstChild.codegenNode!
263 injectProp(vnodeCall, keyProperty, context)
264 return vnodeCall
265 } else {
266 let patchFlag = PatchFlags.STABLE_FRAGMENT
267 // check if the fragment actually contains a single valid child with
268 // the rest being comments
269 if (
270 __DEV__ &&
271 !branch.isTemplateIf &&
272 children.filter(c => c.type !== NodeTypes.COMMENT).length === 1
273 ) {
274 patchFlag |= PatchFlags.DEV_ROOT_FRAGMENT
275 }
276
277 return createVNodeCall(
278 context,
279 helper(FRAGMENT),
280 createObjectExpression([keyProperty]),
281 children,
282 patchFlag,
283 undefined,
284 undefined,
285 true,
286 false,
287 false /* isComponent */,
288 branch.loc,
289 )
290 }
291 } else {
292 const ret = (firstChild as ElementNode).codegenNode as
293 | BlockCodegenNode
294 | MemoExpression
295 const vnodeCall = getMemoedVNodeCall(ret)
296 // Change createVNode to createBlock.
297 if (vnodeCall.type === NodeTypes.VNODE_CALL) {

Callers 1

Calls 9

createObjectPropertyFunction · 0.90
createSimpleExpressionFunction · 0.90
injectPropFunction · 0.90
createVNodeCallFunction · 0.90
createObjectExpressionFunction · 0.90
getMemoedVNodeCallFunction · 0.90
convertToBlockFunction · 0.90
filterMethod · 0.65
helperFunction · 0.50

Tested by

no test coverage detected