vHtml.ts 672 B

12345678910111213141516171819202122232425
  1. import {
  2. DirectiveTransform,
  3. createCompilerError,
  4. ErrorCodes,
  5. createObjectProperty,
  6. createSimpleExpression
  7. } from '@vue/compiler-core'
  8. export const transformVHtml: DirectiveTransform = (dir, node, context) => {
  9. const { exp, loc } = dir
  10. if (!exp) {
  11. context.onError(createCompilerError(ErrorCodes.X_V_HTML_NO_EXPRESSION, loc))
  12. }
  13. if (node.children.length) {
  14. context.onError(createCompilerError(ErrorCodes.X_V_HTML_WITH_CHILDREN, loc))
  15. node.children.length = 0
  16. }
  17. return {
  18. props: createObjectProperty(
  19. createSimpleExpression(`innerHTML`, true, loc),
  20. exp || createSimpleExpression('', true)
  21. ),
  22. needRuntime: false
  23. }
  24. }