(node, context)
| 14 | const seen = new WeakSet() |
| 15 | |
| 16 | export const transformMemo: NodeTransform = (node, context) => { |
| 17 | if (node.type === NodeTypes.ELEMENT) { |
| 18 | const dir = findDir(node, 'memo') |
| 19 | if (!dir || seen.has(node) || context.inSSR) { |
| 20 | return |
| 21 | } |
| 22 | seen.add(node) |
| 23 | return () => { |
| 24 | const codegenNode = |
| 25 | node.codegenNode || |
| 26 | (context.currentNode as PlainElementNode).codegenNode |
| 27 | if (codegenNode && codegenNode.type === NodeTypes.VNODE_CALL) { |
| 28 | // non-component sub tree should be turned into a block |
| 29 | if (node.tagType !== ElementTypes.COMPONENT) { |
| 30 | convertToBlock(codegenNode, context) |
| 31 | } |
| 32 | node.codegenNode = createCallExpression(context.helper(WITH_MEMO), [ |
| 33 | dir.exp!, |
| 34 | createFunctionExpression(undefined, codegenNode), |
| 35 | `_cache`, |
| 36 | String(context.cached.length), |
| 37 | ]) as MemoExpression |
| 38 | // increment cache count |
| 39 | context.cached.push(null) |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |
nothing calls this directly
no test coverage detected