( branch: IfBranchNode, keyIndex: number, context: TransformContext, )
| 238 | } |
| 239 | |
| 240 | function 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) { |
no test coverage detected