| 6 | const seen = new WeakSet() |
| 7 | |
| 8 | export const transformOnce: NodeTransform = (node, context) => { |
| 9 | if (node.type === NodeTypes.ELEMENT && findDir(node, 'once', true)) { |
| 10 | if (seen.has(node) || context.inVOnce || context.inSSR) { |
| 11 | return |
| 12 | } |
| 13 | seen.add(node) |
| 14 | context.inVOnce = true |
| 15 | context.helper(SET_BLOCK_TRACKING) |
| 16 | return () => { |
| 17 | context.inVOnce = false |
| 18 | const cur = context.currentNode as ElementNode | IfNode | ForNode |
| 19 | if (cur.codegenNode) { |
| 20 | cur.codegenNode = context.cache( |
| 21 | cur.codegenNode, |
| 22 | true /* isVNode */, |
| 23 | true /* inVOnce */, |
| 24 | ) |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | } |