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

Function transformMemo

packages/compiler-core/src/transforms/vMemo.ts:16–43  ·  view source on GitHub ↗
(node, context)

Source from the content-addressed store, hash-verified

14const seen = new WeakSet()
15
16export 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}

Callers

nothing calls this directly

Calls 8

findDirFunction · 0.90
convertToBlockFunction · 0.90
createCallExpressionFunction · 0.90
createFunctionExpressionFunction · 0.90
StringInterface · 0.85
hasMethod · 0.80
helperMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected