16 lines
495 B
TypeScript
16 lines
495 B
TypeScript
import { NodeTransform } from '../transform'
|
|
import { findDir } from '../utils'
|
|
import { NodeTypes } from '../ast'
|
|
import { SET_BLOCK_TRACKING } from '../runtimeHelpers'
|
|
|
|
export const transformOnce: NodeTransform = (node, context) => {
|
|
if (node.type === NodeTypes.ELEMENT && findDir(node, 'once', true)) {
|
|
context.helper(SET_BLOCK_TRACKING)
|
|
return () => {
|
|
if (node.codegenNode) {
|
|
node.codegenNode = context.cache(node.codegenNode, true /* isVNode */)
|
|
}
|
|
}
|
|
}
|
|
}
|