defineRender.ts 832 B

12345678910111213141516171819202122232425262728293031323334
  1. import { Node } from '@babel/types'
  2. import { isCallOf } from './utils'
  3. import { ScriptCompileContext } from './context'
  4. import { warnOnce } from '../warn'
  5. export const DEFINE_RENDER = 'defineRender'
  6. export function processDefineRender(
  7. ctx: ScriptCompileContext,
  8. node: Node
  9. ): boolean {
  10. if (!isCallOf(node, DEFINE_RENDER)) {
  11. return false
  12. }
  13. if (!ctx.options.defineRender) {
  14. warnOnce(
  15. `${DEFINE_RENDER}() is an experimental feature and disabled by default.\n` +
  16. `To enable it, follow the RFC at https://github.com/vuejs/rfcs/discussions/TODO.`
  17. )
  18. return false
  19. }
  20. if (ctx.hasDefineRenderCall) {
  21. ctx.error(`duplicate ${DEFINE_RENDER}() call`, node)
  22. }
  23. ctx.hasDefineRenderCall = true
  24. if (node.arguments.length > 0) {
  25. ctx.renderFunction = node.arguments[0]
  26. }
  27. return true
  28. }