You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.6 KiB

4 years ago
  1. /* globals __VUE_SSR_CONTEXT__ */
  2. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  3. // This module is a runtime utility for cleaner component module output and will
  4. // be included in the final webpack user bundle.
  5. export default function normalizeComponent (
  6. scriptExports,
  7. render,
  8. staticRenderFns,
  9. functionalTemplate,
  10. injectStyles,
  11. scopeId,
  12. moduleIdentifier, /* server only */
  13. shadowMode /* vue-cli only */
  14. ) {
  15. // Vue.extend constructor export interop
  16. var options = typeof scriptExports === 'function'
  17. ? scriptExports.options
  18. : scriptExports
  19. // render functions
  20. if (render) {
  21. options.render = render
  22. options.staticRenderFns = staticRenderFns
  23. options._compiled = true
  24. }
  25. // functional template
  26. if (functionalTemplate) {
  27. options.functional = true
  28. }
  29. // scopedId
  30. if (scopeId) {
  31. options._scopeId = 'data-v-' + scopeId
  32. }
  33. var hook
  34. if (moduleIdentifier) { // server build
  35. hook = function (context) {
  36. // 2.3 injection
  37. context =
  38. context || // cached call
  39. (this.$vnode && this.$vnode.ssrContext) || // stateful
  40. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  41. // 2.2 with runInNewContext: true
  42. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  43. context = __VUE_SSR_CONTEXT__
  44. }
  45. // inject component styles
  46. if (injectStyles) {
  47. injectStyles.call(this, context)
  48. }
  49. // register component module identifier for async chunk inferrence
  50. if (context && context._registeredComponents) {
  51. context._registeredComponents.add(moduleIdentifier)
  52. }
  53. }
  54. // used by ssr in case component is cached and beforeCreate
  55. // never gets called
  56. options._ssrRegister = hook
  57. } else if (injectStyles) {
  58. hook = shadowMode
  59. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  60. : injectStyles
  61. }
  62. if (hook) {
  63. if (options.functional) {
  64. // for template-only hot-reload because in that case the render fn doesn't
  65. // go through the normalizer
  66. options._injectStyles = hook
  67. // register for functioal component in vue file
  68. var originalRender = options.render
  69. options.render = function renderWithStyleInjection (h, context) {
  70. hook.call(context)
  71. return originalRender(h, context)
  72. }
  73. } else {
  74. // inject component registration as beforeCreate hook
  75. var existing = options.beforeCreate
  76. options.beforeCreate = existing
  77. ? [].concat(existing, hook)
  78. : [hook]
  79. }
  80. }
  81. return {
  82. exports: scriptExports,
  83. options: options
  84. }
  85. }