component.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { isFunction, isObject } from '@vue/shared'
  2. import { Component, ComponentInternalInstance } from '../component'
  3. import {
  4. checkCompatEnabled,
  5. DeprecationTypes,
  6. softAssertCompatEnabled
  7. } from './compatConfig'
  8. import { convertLegacyAsyncComponent } from './componentAsync'
  9. import { convertLegacyFunctionalComponent } from './componentFunctional'
  10. export function convertLegacyComponent(
  11. comp: any,
  12. instance: ComponentInternalInstance | null
  13. ): Component {
  14. if (comp.__isBuiltIn) {
  15. return comp
  16. }
  17. // 2.x constructor
  18. if (isFunction(comp) && comp.cid) {
  19. comp = comp.options
  20. }
  21. // 2.x async component
  22. if (
  23. isFunction(comp) &&
  24. checkCompatEnabled(DeprecationTypes.COMPONENT_ASYNC, instance, comp)
  25. ) {
  26. // since after disabling this, plain functions are still valid usage, do not
  27. // use softAssert here.
  28. return convertLegacyAsyncComponent(comp)
  29. }
  30. // 2.x functional component
  31. if (
  32. isObject(comp) &&
  33. comp.functional &&
  34. softAssertCompatEnabled(
  35. DeprecationTypes.COMPONENT_FUNCTIONAL,
  36. instance,
  37. comp
  38. )
  39. ) {
  40. return convertLegacyFunctionalComponent(comp)
  41. }
  42. return comp
  43. }