runtimeHelpers.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. export const FRAGMENT = Symbol(__DEV__ ? `Fragment` : ``)
  2. export const PORTAL = Symbol(__DEV__ ? `Portal` : ``)
  3. export const COMMENT = Symbol(__DEV__ ? `Comment` : ``)
  4. export const TEXT = Symbol(__DEV__ ? `Text` : ``)
  5. export const SUSPENSE = Symbol(__DEV__ ? `Suspense` : ``)
  6. export const OPEN_BLOCK = Symbol(__DEV__ ? `openBlock` : ``)
  7. export const CREATE_BLOCK = Symbol(__DEV__ ? `createBlock` : ``)
  8. export const CREATE_VNODE = Symbol(__DEV__ ? `createVNode` : ``)
  9. export const RESOLVE_COMPONENT = Symbol(__DEV__ ? `resolveComponent` : ``)
  10. export const RESOLVE_DYNAMIC_COMPONENT = Symbol(
  11. __DEV__ ? `resolveDynamicComponent` : ``
  12. )
  13. export const RESOLVE_DIRECTIVE = Symbol(__DEV__ ? `resolveDirective` : ``)
  14. export const WITH_DIRECTIVES = Symbol(__DEV__ ? `withDirectives` : ``)
  15. export const RENDER_LIST = Symbol(__DEV__ ? `renderList` : ``)
  16. export const RENDER_SLOT = Symbol(__DEV__ ? `renderSlot` : ``)
  17. export const CREATE_SLOTS = Symbol(__DEV__ ? `createSlots` : ``)
  18. export const TO_STRING = Symbol(__DEV__ ? `toString` : ``)
  19. export const MERGE_PROPS = Symbol(__DEV__ ? `mergeProps` : ``)
  20. export const TO_HANDLERS = Symbol(__DEV__ ? `toHandlers` : ``)
  21. export const CAMELIZE = Symbol(__DEV__ ? `camelize` : ``)
  22. export const SET_BLOCK_TRACKING = Symbol(__DEV__ ? `setBlockTracking` : ``)
  23. // Name mapping for runtime helpers that need to be imported from 'vue' in
  24. // generated code. Make sure these are correctly exported in the runtime!
  25. // Using `any` here because TS doesn't allow symbols as index type.
  26. export const helperNameMap: any = {
  27. [FRAGMENT]: `Fragment`,
  28. [PORTAL]: `Portal`,
  29. [COMMENT]: `Comment`,
  30. [TEXT]: `Text`,
  31. [SUSPENSE]: `Suspense`,
  32. [OPEN_BLOCK]: `openBlock`,
  33. [CREATE_BLOCK]: `createBlock`,
  34. [CREATE_VNODE]: `createVNode`,
  35. [RESOLVE_COMPONENT]: `resolveComponent`,
  36. [RESOLVE_DYNAMIC_COMPONENT]: `resolveDynamicComponent`,
  37. [RESOLVE_DIRECTIVE]: `resolveDirective`,
  38. [WITH_DIRECTIVES]: `withDirectives`,
  39. [RENDER_LIST]: `renderList`,
  40. [RENDER_SLOT]: `renderSlot`,
  41. [CREATE_SLOTS]: `createSlots`,
  42. [TO_STRING]: `toString`,
  43. [MERGE_PROPS]: `mergeProps`,
  44. [TO_HANDLERS]: `toHandlers`,
  45. [CAMELIZE]: `camelize`,
  46. [SET_BLOCK_TRACKING]: `setBlockTracking`
  47. }
  48. export function registerRuntimeHelpers(helpers: any) {
  49. Object.getOwnPropertySymbols(helpers).forEach(s => {
  50. helperNameMap[s] = helpers[s]
  51. })
  52. }