vue 2.6.13 → 2.7.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/README.md +17 -295
  2. package/compiler-sfc/index.d.ts +1 -0
  3. package/compiler-sfc/index.js +1 -0
  4. package/compiler-sfc/index.mjs +1 -0
  5. package/compiler-sfc/package.json +5 -0
  6. package/dist/vue.common.dev.js +11481 -11946
  7. package/dist/vue.common.prod.js +8 -3
  8. package/dist/vue.esm.browser.js +11321 -12011
  9. package/dist/vue.esm.browser.min.js +8 -3
  10. package/dist/vue.esm.js +11476 -11984
  11. package/dist/vue.js +11484 -11949
  12. package/dist/vue.min.js +8 -3
  13. package/dist/vue.runtime.common.dev.js +8427 -8421
  14. package/dist/vue.runtime.common.prod.js +8 -3
  15. package/dist/vue.runtime.esm.js +8436 -8454
  16. package/dist/vue.runtime.js +8430 -8424
  17. package/dist/vue.runtime.min.js +8 -3
  18. package/package.json +88 -111
  19. package/packages/compiler-sfc/dist/compiler-sfc.js +7 -0
  20. package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
  21. package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
  22. package/packages/compiler-sfc/package.json +30 -0
  23. package/src/compiler/{codeframe.js → codeframe.ts} +9 -7
  24. package/src/compiler/codegen/{events.js → events.ts} +21 -41
  25. package/src/compiler/codegen/{index.js → index.ts} +146 -136
  26. package/src/compiler/{create-compiler.js → create-compiler.ts} +26 -18
  27. package/src/compiler/directives/bind.ts +9 -0
  28. package/src/compiler/directives/{index.js → index.ts} +0 -2
  29. package/src/compiler/directives/{model.js → model.ts} +15 -18
  30. package/src/compiler/directives/{on.js → on.ts} +3 -4
  31. package/src/compiler/{error-detector.js → error-detector.ts} +61 -31
  32. package/src/compiler/{helpers.js → helpers.ts} +73 -61
  33. package/src/compiler/{index.js → index.ts} +2 -3
  34. package/src/compiler/{optimizer.js → optimizer.ts} +30 -23
  35. package/src/compiler/parser/{entity-decoder.js → entity-decoder.ts} +1 -3
  36. package/src/compiler/parser/{filter-parser.js → filter-parser.ts} +43 -24
  37. package/src/compiler/parser/{html-parser.js → html-parser.ts} +50 -29
  38. package/src/compiler/parser/{index.js → index.ts} +190 -172
  39. package/src/compiler/parser/{text-parser.js → text-parser.ts} +8 -9
  40. package/src/compiler/{to-function.js → to-function.ts} +27 -22
  41. package/src/core/components/{index.js → index.ts} +0 -0
  42. package/src/core/components/{keep-alive.js → keep-alive.ts} +42 -30
  43. package/src/core/{config.js → config.ts} +28 -30
  44. package/src/core/global-api/{assets.js → assets.ts} +8 -7
  45. package/src/core/global-api/{extend.js → extend.ts} +10 -13
  46. package/src/core/global-api/{index.js → index.ts} +4 -5
  47. package/src/core/global-api/{mixin.js → mixin.ts} +2 -3
  48. package/src/core/global-api/use.ts +23 -0
  49. package/src/core/{index.js → index.ts} +1 -1
  50. package/src/core/instance/{events.js → events.ts} +41 -24
  51. package/src/core/instance/{index.js → index.ts} +9 -5
  52. package/src/core/instance/{init.js → init.ts} +26 -15
  53. package/src/core/instance/inject.ts +72 -0
  54. package/src/core/instance/{lifecycle.js → lifecycle.ts} +86 -44
  55. package/src/core/instance/{proxy.js → proxy.ts} +29 -24
  56. package/src/core/instance/render-helpers/{bind-dynamic-keys.js → bind-dynamic-keys.ts} +6 -5
  57. package/src/core/instance/render-helpers/{bind-object-listeners.js → bind-object-listeners.ts} +4 -8
  58. package/src/core/instance/render-helpers/{bind-object-props.js → bind-object-props.ts} +12 -17
  59. package/src/core/instance/render-helpers/{check-keycodes.js → check-keycodes.ts} +5 -7
  60. package/src/core/instance/render-helpers/{index.js → index.ts} +1 -3
  61. package/src/core/instance/render-helpers/{render-list.js → render-list.ts} +12 -13
  62. package/src/core/instance/render-helpers/{render-slot.js → render-slot.ts} +10 -11
  63. package/src/core/instance/render-helpers/{render-static.js → render-static.ts} +7 -10
  64. package/src/core/instance/render-helpers/{resolve-filter.js → resolve-filter.ts} +1 -3
  65. package/src/core/instance/render-helpers/{resolve-scoped-slots.js → resolve-scoped-slots.ts} +11 -8
  66. package/src/core/instance/render-helpers/{resolve-slots.js → resolve-slots.ts} +12 -11
  67. package/src/core/instance/{render.js → render.ts} +66 -29
  68. package/src/core/instance/{state.js → state.ts} +100 -83
  69. package/src/core/observer/{array.js → array.ts} +11 -2
  70. package/src/core/observer/{dep.js → dep.ts} +37 -15
  71. package/src/core/observer/{index.js → index.ts} +137 -71
  72. package/src/core/observer/{scheduler.js → scheduler.ts} +42 -43
  73. package/src/core/observer/{traverse.js → traverse.ts} +10 -7
  74. package/src/core/observer/{watcher.js → watcher.ts} +88 -60
  75. package/src/core/util/{debug.js → debug.ts} +38 -34
  76. package/src/core/util/{env.js → env.ts} +27 -30
  77. package/src/core/util/{error.js → error.ts} +12 -14
  78. package/src/core/util/{index.js → index.ts} +0 -2
  79. package/src/core/util/{lang.js → lang.ts} +6 -7
  80. package/src/core/util/{next-tick.js → next-tick.ts} +16 -10
  81. package/src/core/util/{options.js → options.ts} +119 -114
  82. package/src/core/util/{perf.js → perf.ts} +5 -1
  83. package/src/core/util/{props.js → props.ts} +54 -50
  84. package/src/core/vdom/{create-component.js → create-component.ts} +51 -50
  85. package/src/core/vdom/{create-element.js → create-element.ts} +49 -43
  86. package/src/core/vdom/{create-functional-component.js → create-functional-component.ts} +52 -27
  87. package/src/core/vdom/helpers/{extract-props.js → extract-props.ts} +18 -18
  88. package/src/core/vdom/helpers/{get-first-component-child.js → get-first-component-child.ts} +6 -5
  89. package/src/core/vdom/helpers/{index.js → index.ts} +0 -2
  90. package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
  91. package/src/core/vdom/helpers/{merge-hook.js → merge-hook.ts} +7 -5
  92. package/src/core/vdom/helpers/{normalize-children.js → normalize-children.ts} +26 -16
  93. package/src/core/vdom/helpers/{normalize-scoped-slots.js → normalize-scoped-slots.ts} +23 -17
  94. package/src/core/vdom/helpers/{resolve-async-component.js → resolve-async-component.ts} +29 -37
  95. package/src/core/vdom/helpers/update-listeners.ts +101 -0
  96. package/src/core/vdom/modules/{directives.js → directives.ts} +20 -14
  97. package/src/core/vdom/modules/index.ts +4 -0
  98. package/src/core/vdom/modules/template-ref.ts +96 -0
  99. package/src/core/vdom/{patch.js → patch.ts} +239 -138
  100. package/src/core/vdom/{vnode.js → vnode.ts} +36 -31
  101. package/src/global.d.ts +15 -0
  102. package/src/platforms/web/compiler/directives/html.ts +8 -0
  103. package/src/platforms/web/compiler/directives/{index.js → index.ts} +0 -0
  104. package/src/platforms/web/compiler/directives/{model.js → model.ts} +47 -41
  105. package/src/platforms/web/compiler/directives/{text.js → text.ts} +2 -3
  106. package/src/platforms/web/compiler/{index.js → index.ts} +0 -2
  107. package/src/platforms/web/compiler/modules/{class.js → class.ts} +10 -15
  108. package/src/platforms/web/compiler/modules/{index.js → index.ts} +1 -5
  109. package/src/platforms/web/compiler/modules/{model.js → model.ts} +6 -11
  110. package/src/platforms/web/compiler/modules/{style.js → style.ts} +9 -14
  111. package/src/platforms/web/compiler/{options.js → options.ts} +1 -2
  112. package/src/platforms/web/compiler/{util.js → util.ts} +5 -7
  113. package/src/platforms/web/entry-compiler-sfc.ts +1 -0
  114. package/src/platforms/web/{entry-compiler.js → entry-compiler.ts} +1 -3
  115. package/src/platforms/web/{entry-runtime.js → entry-runtime-esm.ts} +2 -2
  116. package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
  117. package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
  118. package/src/platforms/web/entry-runtime.ts +7 -0
  119. package/src/platforms/web/runtime/{class-util.js → class-util.ts} +2 -4
  120. package/src/platforms/web/runtime/components/{index.js → index.ts} +0 -0
  121. package/src/platforms/web/runtime/components/{transition-group.js → transition-group.ts} +59 -46
  122. package/src/platforms/web/runtime/components/{transition.js → transition.ts} +43 -36
  123. package/src/platforms/web/runtime/directives/{index.js → index.ts} +0 -0
  124. package/src/platforms/web/runtime/directives/{model.js → model.ts} +22 -21
  125. package/src/platforms/web/runtime/directives/{show.js → show.ts} +11 -10
  126. package/src/platforms/web/runtime/{index.js → index.ts} +9 -10
  127. package/src/platforms/web/runtime/modules/{attrs.js → attrs.ts} +12 -16
  128. package/src/platforms/web/runtime/modules/{class.js → class.ts} +7 -18
  129. package/src/platforms/web/runtime/modules/{dom-props.js → dom-props.ts} +24 -17
  130. package/src/platforms/web/runtime/modules/{events.js → events.ts} +22 -15
  131. package/src/platforms/web/runtime/modules/{index.js → index.ts} +1 -8
  132. package/src/platforms/web/runtime/modules/{style.js → style.ts} +24 -13
  133. package/src/platforms/web/runtime/modules/{transition.js → transition.ts} +61 -63
  134. package/src/platforms/web/runtime/node-ops.ts +66 -0
  135. package/src/platforms/web/runtime/{patch.js → patch.ts} +0 -2
  136. package/src/platforms/web/runtime/{transition-util.js → transition-util.ts} +63 -38
  137. package/src/platforms/web/{entry-runtime-with-compiler.js → runtime-with-compiler.ts} +28 -19
  138. package/src/platforms/web/util/{attrs.js → attrs.ts} +18 -14
  139. package/src/platforms/web/util/{class.js → class.ts} +23 -21
  140. package/src/platforms/web/util/{compat.js → compat.ts} +4 -4
  141. package/src/platforms/web/util/{element.js → element.ts} +21 -22
  142. package/src/platforms/web/util/{index.js → index.ts} +2 -6
  143. package/src/platforms/web/util/{style.js → style.ts} +12 -12
  144. package/src/sfc/{parser.js → parser.ts} +18 -15
  145. package/src/shared/{constants.js → constants.ts} +2 -6
  146. package/src/shared/{util.js → util.ts} +78 -55
  147. package/src/types/compiler.ts +224 -0
  148. package/src/types/component.ts +209 -0
  149. package/src/types/global-api.ts +37 -0
  150. package/src/types/modules.d.ts +15 -0
  151. package/src/types/options.ts +120 -0
  152. package/src/types/ssr.ts +27 -0
  153. package/src/types/utils.ts +3 -0
  154. package/src/types/vnode.ts +127 -0
  155. package/src/v3/apiInject.ts +66 -0
  156. package/src/v3/apiLifecycle.ts +53 -0
  157. package/src/v3/apiSetup.ts +161 -0
  158. package/src/v3/apiWatch.ts +355 -0
  159. package/src/v3/currentInstance.ts +23 -0
  160. package/src/v3/debug.ts +21 -0
  161. package/src/v3/h.ts +18 -0
  162. package/src/v3/index.ts +77 -0
  163. package/src/v3/reactivity/computed.ts +100 -0
  164. package/src/v3/reactivity/effect.ts +20 -0
  165. package/src/v3/reactivity/effectScope.ts +134 -0
  166. package/src/v3/reactivity/operations.ts +14 -0
  167. package/src/v3/reactivity/reactive.ts +123 -0
  168. package/src/v3/reactivity/readonly.ts +121 -0
  169. package/src/v3/reactivity/ref.ts +249 -0
  170. package/types/index.d.ts +10 -13
  171. package/types/options.d.ts +265 -132
  172. package/types/plugin.d.ts +4 -4
  173. package/types/umd.d.ts +47 -27
  174. package/types/v3-generated.d.ts +389 -0
  175. package/types/v3.d.ts +16 -0
  176. package/types/vnode.d.ts +70 -57
  177. package/types/vue.d.ts +292 -88
  178. package/dist/README.md +0 -122
  179. package/src/compiler/directives/bind.js +0 -11
  180. package/src/core/global-api/use.js +0 -23
  181. package/src/core/instance/inject.js +0 -73
  182. package/src/core/vdom/helpers/is-async-placeholder.js +0 -5
  183. package/src/core/vdom/helpers/update-listeners.js +0 -95
  184. package/src/core/vdom/modules/index.js +0 -7
  185. package/src/core/vdom/modules/ref.js +0 -45
  186. package/src/platforms/web/compiler/directives/html.js +0 -9
  187. package/src/platforms/web/entry-server-basic-renderer.js +0 -13
  188. package/src/platforms/web/entry-server-renderer.js +0 -27
  189. package/src/platforms/web/runtime/node-ops.js +0 -59
  190. package/src/platforms/web/server/compiler.js +0 -11
  191. package/src/platforms/web/server/directives/index.js +0 -7
  192. package/src/platforms/web/server/directives/model.js +0 -44
  193. package/src/platforms/web/server/directives/show.js +0 -12
  194. package/src/platforms/web/server/modules/attrs.js +0 -67
  195. package/src/platforms/web/server/modules/class.js +0 -11
  196. package/src/platforms/web/server/modules/dom-props.js +0 -50
  197. package/src/platforms/web/server/modules/index.js +0 -11
  198. package/src/platforms/web/server/modules/style.js +0 -41
  199. package/src/platforms/web/server/util.js +0 -101
  200. package/src/platforms/weex/compiler/directives/index.js +0 -5
  201. package/src/platforms/weex/compiler/directives/model.js +0 -33
  202. package/src/platforms/weex/compiler/index.js +0 -52
  203. package/src/platforms/weex/compiler/modules/append.js +0 -27
  204. package/src/platforms/weex/compiler/modules/class.js +0 -74
  205. package/src/platforms/weex/compiler/modules/index.js +0 -13
  206. package/src/platforms/weex/compiler/modules/props.js +0 -37
  207. package/src/platforms/weex/compiler/modules/recycle-list/component-root.js +0 -13
  208. package/src/platforms/weex/compiler/modules/recycle-list/component.js +0 -16
  209. package/src/platforms/weex/compiler/modules/recycle-list/index.js +0 -60
  210. package/src/platforms/weex/compiler/modules/recycle-list/recycle-list.js +0 -50
  211. package/src/platforms/weex/compiler/modules/recycle-list/text.js +0 -23
  212. package/src/platforms/weex/compiler/modules/recycle-list/v-bind.js +0 -21
  213. package/src/platforms/weex/compiler/modules/recycle-list/v-for.js +0 -33
  214. package/src/platforms/weex/compiler/modules/recycle-list/v-if.js +0 -63
  215. package/src/platforms/weex/compiler/modules/recycle-list/v-on.js +0 -25
  216. package/src/platforms/weex/compiler/modules/recycle-list/v-once.js +0 -19
  217. package/src/platforms/weex/compiler/modules/style.js +0 -87
  218. package/src/platforms/weex/entry-compiler.js +0 -2
  219. package/src/platforms/weex/entry-framework.js +0 -187
  220. package/src/platforms/weex/entry-runtime-factory.js +0 -6
  221. package/src/platforms/weex/runtime/components/index.js +0 -9
  222. package/src/platforms/weex/runtime/components/richtext.js +0 -82
  223. package/src/platforms/weex/runtime/components/transition-group.js +0 -148
  224. package/src/platforms/weex/runtime/components/transition.js +0 -9
  225. package/src/platforms/weex/runtime/directives/index.js +0 -2
  226. package/src/platforms/weex/runtime/index.js +0 -42
  227. package/src/platforms/weex/runtime/modules/attrs.js +0 -44
  228. package/src/platforms/weex/runtime/modules/class.js +0 -76
  229. package/src/platforms/weex/runtime/modules/events.js +0 -54
  230. package/src/platforms/weex/runtime/modules/index.js +0 -13
  231. package/src/platforms/weex/runtime/modules/style.js +0 -84
  232. package/src/platforms/weex/runtime/modules/transition.js +0 -270
  233. package/src/platforms/weex/runtime/node-ops.js +0 -91
  234. package/src/platforms/weex/runtime/patch.js +0 -16
  235. package/src/platforms/weex/runtime/recycle-list/render-component-template.js +0 -34
  236. package/src/platforms/weex/runtime/recycle-list/virtual-component.js +0 -136
  237. package/src/platforms/weex/runtime/text-node.js +0 -9
  238. package/src/platforms/weex/util/element.js +0 -52
  239. package/src/platforms/weex/util/index.js +0 -40
  240. package/src/platforms/weex/util/parser.js +0 -60
  241. package/src/server/bundle-renderer/create-bundle-renderer.js +0 -151
  242. package/src/server/bundle-renderer/create-bundle-runner.js +0 -150
  243. package/src/server/bundle-renderer/source-map-support.js +0 -45
  244. package/src/server/create-basic-renderer.js +0 -37
  245. package/src/server/create-renderer.js +0 -152
  246. package/src/server/optimizing-compiler/codegen.js +0 -264
  247. package/src/server/optimizing-compiler/index.js +0 -20
  248. package/src/server/optimizing-compiler/modules.js +0 -124
  249. package/src/server/optimizing-compiler/optimizer.js +0 -141
  250. package/src/server/optimizing-compiler/runtime-helpers.js +0 -150
  251. package/src/server/render-context.js +0 -130
  252. package/src/server/render-stream.js +0 -95
  253. package/src/server/render.js +0 -437
  254. package/src/server/template-renderer/create-async-file-mapper.js +0 -57
  255. package/src/server/template-renderer/index.js +0 -277
  256. package/src/server/template-renderer/parse-template.js +0 -42
  257. package/src/server/template-renderer/template-stream.js +0 -82
  258. package/src/server/util.js +0 -18
  259. package/src/server/webpack-plugin/client.js +0 -65
  260. package/src/server/webpack-plugin/server.js +0 -66
  261. package/src/server/webpack-plugin/util.js +0 -34
  262. package/src/server/write.js +0 -50
@@ -1,5 +1,3 @@
1
- /* @flow */
2
-
3
1
  import VNode, { cloneVNode } from './vnode'
4
2
  import { createElement } from './create-element'
5
3
  import { resolveInject } from '../instance/inject'
@@ -12,17 +10,20 @@ import {
12
10
  isDef,
13
11
  isTrue,
14
12
  hasOwn,
13
+ isArray,
15
14
  camelize,
16
15
  emptyObject,
17
16
  validateProp
18
17
  } from '../util/index'
18
+ import type { Component } from 'types/component'
19
+ import type { VNodeData } from 'types/vnode'
19
20
 
20
- export function FunctionalRenderContext (
21
+ export function FunctionalRenderContext(
21
22
  data: VNodeData,
22
23
  props: Object,
23
- children: ?Array<VNode>,
24
+ children: Array<VNode> | undefined,
24
25
  parent: Component,
25
- Ctor: Class<Component>
26
+ Ctor: typeof Component
26
27
  ) {
27
28
  const options = Ctor.options
28
29
  // ensure the createElement function in functional components
@@ -30,14 +31,13 @@ export function FunctionalRenderContext (
30
31
  let contextVm
31
32
  if (hasOwn(parent, '_uid')) {
32
33
  contextVm = Object.create(parent)
33
- // $flow-disable-line
34
34
  contextVm._original = parent
35
35
  } else {
36
36
  // the context vm passed in is a functional context as well.
37
37
  // in this case we want to make sure we are able to get a hold to the
38
38
  // real context instance.
39
39
  contextVm = parent
40
- // $flow-disable-line
40
+ // @ts-ignore
41
41
  parent = parent._original
42
42
  }
43
43
  const isCompiled = isTrue(options._compiled)
@@ -52,19 +52,20 @@ export function FunctionalRenderContext (
52
52
  this.slots = () => {
53
53
  if (!this.$slots) {
54
54
  normalizeScopedSlots(
55
+ parent,
55
56
  data.scopedSlots,
56
- this.$slots = resolveSlots(children, parent)
57
+ (this.$slots = resolveSlots(children, parent))
57
58
  )
58
59
  }
59
60
  return this.$slots
60
61
  }
61
62
 
62
- Object.defineProperty(this, 'scopedSlots', ({
63
+ Object.defineProperty(this, 'scopedSlots', {
63
64
  enumerable: true,
64
- get () {
65
- return normalizeScopedSlots(data.scopedSlots, this.slots())
65
+ get() {
66
+ return normalizeScopedSlots(parent, data.scopedSlots, this.slots())
66
67
  }
67
- }: any))
68
+ } as any)
68
69
 
69
70
  // support for compiled functional template
70
71
  if (isCompiled) {
@@ -72,31 +73,36 @@ export function FunctionalRenderContext (
72
73
  this.$options = options
73
74
  // pre-resolve slots for renderSlot()
74
75
  this.$slots = this.slots()
75
- this.$scopedSlots = normalizeScopedSlots(data.scopedSlots, this.$slots)
76
+ this.$scopedSlots = normalizeScopedSlots(
77
+ parent,
78
+ data.scopedSlots,
79
+ this.$slots
80
+ )
76
81
  }
77
82
 
78
83
  if (options._scopeId) {
79
84
  this._c = (a, b, c, d) => {
80
85
  const vnode = createElement(contextVm, a, b, c, d, needNormalization)
81
- if (vnode && !Array.isArray(vnode)) {
86
+ if (vnode && !isArray(vnode)) {
82
87
  vnode.fnScopeId = options._scopeId
83
88
  vnode.fnContext = parent
84
89
  }
85
90
  return vnode
86
91
  }
87
92
  } else {
88
- this._c = (a, b, c, d) => createElement(contextVm, a, b, c, d, needNormalization)
93
+ this._c = (a, b, c, d) =>
94
+ createElement(contextVm, a, b, c, d, needNormalization)
89
95
  }
90
96
  }
91
97
 
92
98
  installRenderHelpers(FunctionalRenderContext.prototype)
93
99
 
94
- export function createFunctionalComponent (
95
- Ctor: Class<Component>,
96
- propsData: ?Object,
100
+ export function createFunctionalComponent(
101
+ Ctor: typeof Component,
102
+ propsData: Object | undefined,
97
103
  data: VNodeData,
98
104
  contextVm: Component,
99
- children: ?Array<VNode>
105
+ children?: Array<VNode>
100
106
  ): VNode | Array<VNode> | void {
101
107
  const options = Ctor.options
102
108
  const props = {}
@@ -121,34 +127,53 @@ export function createFunctionalComponent (
121
127
  const vnode = options.render.call(null, renderContext._c, renderContext)
122
128
 
123
129
  if (vnode instanceof VNode) {
124
- return cloneAndMarkFunctionalResult(vnode, data, renderContext.parent, options, renderContext)
125
- } else if (Array.isArray(vnode)) {
130
+ return cloneAndMarkFunctionalResult(
131
+ vnode,
132
+ data,
133
+ renderContext.parent,
134
+ options,
135
+ renderContext
136
+ )
137
+ } else if (isArray(vnode)) {
126
138
  const vnodes = normalizeChildren(vnode) || []
127
139
  const res = new Array(vnodes.length)
128
140
  for (let i = 0; i < vnodes.length; i++) {
129
- res[i] = cloneAndMarkFunctionalResult(vnodes[i], data, renderContext.parent, options, renderContext)
141
+ res[i] = cloneAndMarkFunctionalResult(
142
+ vnodes[i],
143
+ data,
144
+ renderContext.parent,
145
+ options,
146
+ renderContext
147
+ )
130
148
  }
131
149
  return res
132
150
  }
133
151
  }
134
152
 
135
- function cloneAndMarkFunctionalResult (vnode, data, contextVm, options, renderContext) {
153
+ function cloneAndMarkFunctionalResult(
154
+ vnode,
155
+ data,
156
+ contextVm,
157
+ options,
158
+ renderContext
159
+ ) {
136
160
  // #7817 clone node before setting fnContext, otherwise if the node is reused
137
161
  // (e.g. it was from a cached normal slot) the fnContext causes named slots
138
162
  // that should not be matched to match.
139
163
  const clone = cloneVNode(vnode)
140
164
  clone.fnContext = contextVm
141
165
  clone.fnOptions = options
142
- if (process.env.NODE_ENV !== 'production') {
143
- (clone.devtoolsMeta = clone.devtoolsMeta || {}).renderContext = renderContext
166
+ if (__DEV__) {
167
+ ;(clone.devtoolsMeta = clone.devtoolsMeta || ({} as any)).renderContext =
168
+ renderContext
144
169
  }
145
170
  if (data.slot) {
146
- (clone.data || (clone.data = {})).slot = data.slot
171
+ ;(clone.data || (clone.data = {})).slot = data.slot
147
172
  }
148
173
  return clone
149
174
  }
150
175
 
151
- function mergeProps (to, from) {
176
+ function mergeProps(to, from) {
152
177
  for (const key in from) {
153
178
  to[camelize(key)] = from[key]
154
179
  }
@@ -1,5 +1,3 @@
1
- /* @flow */
2
-
3
1
  import {
4
2
  tip,
5
3
  hasOwn,
@@ -8,12 +6,14 @@ import {
8
6
  hyphenate,
9
7
  formatComponentName
10
8
  } from 'core/util/index'
9
+ import type { Component } from 'types/component'
10
+ import type { VNodeData } from 'types/vnode'
11
11
 
12
- export function extractPropsFromVNodeData (
12
+ export function extractPropsFromVNodeData(
13
13
  data: VNodeData,
14
- Ctor: Class<Component>,
14
+ Ctor: typeof Component,
15
15
  tag?: string
16
- ): ?Object {
16
+ ): object | undefined {
17
17
  // we are only extracting raw values here.
18
18
  // validation and default values are handled in the child
19
19
  // component itself.
@@ -26,32 +26,32 @@ export function extractPropsFromVNodeData (
26
26
  if (isDef(attrs) || isDef(props)) {
27
27
  for (const key in propOptions) {
28
28
  const altKey = hyphenate(key)
29
- if (process.env.NODE_ENV !== 'production') {
29
+ if (__DEV__) {
30
30
  const keyInLowerCase = key.toLowerCase()
31
- if (
32
- key !== keyInLowerCase &&
33
- attrs && hasOwn(attrs, keyInLowerCase)
34
- ) {
31
+ if (key !== keyInLowerCase && attrs && hasOwn(attrs, keyInLowerCase)) {
35
32
  tip(
36
33
  `Prop "${keyInLowerCase}" is passed to component ` +
37
- `${formatComponentName(tag || Ctor)}, but the declared prop name is` +
38
- ` "${key}". ` +
39
- `Note that HTML attributes are case-insensitive and camelCased ` +
40
- `props need to use their kebab-case equivalents when using in-DOM ` +
41
- `templates. You should probably use "${altKey}" instead of "${key}".`
34
+ `${formatComponentName(
35
+ // @ts-expect-error tag is string
36
+ tag || Ctor
37
+ )}, but the declared prop name is` +
38
+ ` "${key}". ` +
39
+ `Note that HTML attributes are case-insensitive and camelCased ` +
40
+ `props need to use their kebab-case equivalents when using in-DOM ` +
41
+ `templates. You should probably use "${altKey}" instead of "${key}".`
42
42
  )
43
43
  }
44
44
  }
45
45
  checkProp(res, props, key, altKey, true) ||
46
- checkProp(res, attrs, key, altKey, false)
46
+ checkProp(res, attrs, key, altKey, false)
47
47
  }
48
48
  }
49
49
  return res
50
50
  }
51
51
 
52
- function checkProp (
52
+ function checkProp(
53
53
  res: Object,
54
- hash: ?Object,
54
+ hash: Object | undefined,
55
55
  key: string,
56
56
  altKey: string,
57
57
  preserve: boolean
@@ -1,10 +1,11 @@
1
- /* @flow */
2
-
3
- import { isDef } from 'shared/util'
1
+ import { isDef, isArray } from 'shared/util'
2
+ import VNode from '../vnode'
4
3
  import { isAsyncPlaceholder } from './is-async-placeholder'
5
4
 
6
- export function getFirstComponentChild (children: ?Array<VNode>): ?VNode {
7
- if (Array.isArray(children)) {
5
+ export function getFirstComponentChild(
6
+ children?: Array<VNode>
7
+ ): VNode | undefined {
8
+ if (isArray(children)) {
8
9
  for (let i = 0; i < children.length; i++) {
9
10
  const c = children[i]
10
11
  if (isDef(c) && (isDef(c.componentOptions) || isAsyncPlaceholder(c))) {
@@ -1,5 +1,3 @@
1
- /* @flow */
2
-
3
1
  export * from './merge-hook'
4
2
  export * from './extract-props'
5
3
  export * from './update-listeners'
@@ -0,0 +1,6 @@
1
+ import VNode from '../vnode'
2
+
3
+ export function isAsyncPlaceholder(node: VNode): boolean {
4
+ // @ts-expect-error not really boolean type
5
+ return node.isComment && node.asyncFactory
6
+ }
@@ -1,17 +1,19 @@
1
- /* @flow */
2
-
3
1
  import VNode from '../vnode'
4
2
  import { createFnInvoker } from './update-listeners'
5
3
  import { remove, isDef, isUndef, isTrue } from 'shared/util'
6
4
 
7
- export function mergeVNodeHook (def: Object, hookKey: string, hook: Function) {
5
+ export function mergeVNodeHook(
6
+ def: Record<string, any>,
7
+ hookKey: string,
8
+ hook: Function
9
+ ) {
8
10
  if (def instanceof VNode) {
9
- def = def.data.hook || (def.data.hook = {})
11
+ def = def.data!.hook || (def.data!.hook = {})
10
12
  }
11
13
  let invoker
12
14
  const oldHook = def[hookKey]
13
15
 
14
- function wrappedHook () {
16
+ function wrappedHook() {
15
17
  hook.apply(this, arguments)
16
18
  // important: remove merged hook to ensure it's called only once
17
19
  // and prevent memory leak
@@ -1,7 +1,12 @@
1
- /* @flow */
2
-
3
1
  import VNode, { createTextVNode } from 'core/vdom/vnode'
4
- import { isFalse, isTrue, isDef, isUndef, isPrimitive } from 'shared/util'
2
+ import {
3
+ isFalse,
4
+ isTrue,
5
+ isArray,
6
+ isDef,
7
+ isUndef,
8
+ isPrimitive
9
+ } from 'shared/util'
5
10
 
6
11
  // The template compiler attempts to minimize the need for normalization by
7
12
  // statically analyzing the template at compile time.
@@ -15,9 +20,9 @@ import { isFalse, isTrue, isDef, isUndef, isPrimitive } from 'shared/util'
15
20
  // normalization is needed - if any child is an Array, we flatten the whole
16
21
  // thing with Array.prototype.concat. It is guaranteed to be only 1-level deep
17
22
  // because functional components already normalize their own children.
18
- export function simpleNormalizeChildren (children: any) {
23
+ export function simpleNormalizeChildren(children: any) {
19
24
  for (let i = 0; i < children.length; i++) {
20
- if (Array.isArray(children[i])) {
25
+ if (isArray(children[i])) {
21
26
  return Array.prototype.concat.apply([], children)
22
27
  }
23
28
  }
@@ -28,20 +33,23 @@ export function simpleNormalizeChildren (children: any) {
28
33
  // e.g. <template>, <slot>, v-for, or when the children is provided by user
29
34
  // with hand-written render functions / JSX. In such cases a full normalization
30
35
  // is needed to cater to all possible types of children values.
31
- export function normalizeChildren (children: any): ?Array<VNode> {
36
+ export function normalizeChildren(children: any): Array<VNode> | undefined {
32
37
  return isPrimitive(children)
33
38
  ? [createTextVNode(children)]
34
- : Array.isArray(children)
35
- ? normalizeArrayChildren(children)
36
- : undefined
39
+ : isArray(children)
40
+ ? normalizeArrayChildren(children)
41
+ : undefined
37
42
  }
38
43
 
39
- function isTextNode (node): boolean {
44
+ function isTextNode(node): boolean {
40
45
  return isDef(node) && isDef(node.text) && isFalse(node.isComment)
41
46
  }
42
47
 
43
- function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNode> {
44
- const res = []
48
+ function normalizeArrayChildren(
49
+ children: any,
50
+ nestedIndex?: string
51
+ ): Array<VNode> {
52
+ const res: VNode[] = []
45
53
  let i, c, lastIndex, last
46
54
  for (i = 0; i < children.length; i++) {
47
55
  c = children[i]
@@ -49,12 +57,12 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
49
57
  lastIndex = res.length - 1
50
58
  last = res[lastIndex]
51
59
  // nested
52
- if (Array.isArray(c)) {
60
+ if (isArray(c)) {
53
61
  if (c.length > 0) {
54
62
  c = normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`)
55
63
  // merge adjacent text nodes
56
64
  if (isTextNode(c[0]) && isTextNode(last)) {
57
- res[lastIndex] = createTextVNode(last.text + (c[0]: any).text)
65
+ res[lastIndex] = createTextVNode(last.text + c[0].text)
58
66
  c.shift()
59
67
  }
60
68
  res.push.apply(res, c)
@@ -75,10 +83,12 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
75
83
  res[lastIndex] = createTextVNode(last.text + c.text)
76
84
  } else {
77
85
  // default key for nested array children (likely generated by v-for)
78
- if (isTrue(children._isVList) &&
86
+ if (
87
+ isTrue(children._isVList) &&
79
88
  isDef(c.tag) &&
80
89
  isUndef(c.key) &&
81
- isDef(nestedIndex)) {
90
+ isDef(nestedIndex)
91
+ ) {
82
92
  c.key = `__vlist${nestedIndex}_${i}__`
83
93
  }
84
94
  res.push(c)
@@ -1,16 +1,18 @@
1
- /* @flow */
2
-
3
1
  import { def } from 'core/util/lang'
4
2
  import { normalizeChildren } from 'core/vdom/helpers/normalize-children'
5
- import { emptyObject } from 'shared/util'
3
+ import { emptyObject, isArray } from 'shared/util'
6
4
  import { isAsyncPlaceholder } from './is-async-placeholder'
5
+ import type VNode from '../vnode'
6
+ import { Component } from 'types/component'
7
+ import { currentInstance, setCurrentInstance } from 'v3/currentInstance'
7
8
 
8
- export function normalizeScopedSlots (
9
+ export function normalizeScopedSlots(
10
+ ownerVm: Component,
9
11
  slots: { [key: string]: Function } | void,
10
- normalSlots: { [key: string]: Array<VNode> },
11
- prevSlots?: { [key: string]: Function } | void
12
+ normalSlots: { [key: string]: VNode[] }
12
13
  ): any {
13
14
  let res
15
+ const prevSlots = ownerVm.$scopedSlots
14
16
  const hasNormalSlots = Object.keys(normalSlots).length > 0
15
17
  const isStable = slots ? !!slots.$stable : !hasNormalSlots
16
18
  const key = slots && slots.$key
@@ -34,7 +36,7 @@ export function normalizeScopedSlots (
34
36
  res = {}
35
37
  for (const key in slots) {
36
38
  if (slots[key] && key[0] !== '$') {
37
- res[key] = normalizeScopedSlot(normalSlots, key, slots[key])
39
+ res[key] = normalizeScopedSlot(ownerVm, normalSlots, key, slots[key])
38
40
  }
39
41
  }
40
42
  }
@@ -47,7 +49,7 @@ export function normalizeScopedSlots (
47
49
  // avoriaz seems to mock a non-extensible $scopedSlots object
48
50
  // and when that is passed down this would cause an error
49
51
  if (slots && Object.isExtensible(slots)) {
50
- (slots: any)._normalized = res
52
+ slots._normalized = res
51
53
  }
52
54
  def(res, '$stable', isStable)
53
55
  def(res, '$key', key)
@@ -55,17 +57,21 @@ export function normalizeScopedSlots (
55
57
  return res
56
58
  }
57
59
 
58
- function normalizeScopedSlot(normalSlots, key, fn) {
60
+ function normalizeScopedSlot(vm, normalSlots, key, fn) {
59
61
  const normalized = function () {
62
+ const cur = currentInstance
63
+ setCurrentInstance(vm)
60
64
  let res = arguments.length ? fn.apply(null, arguments) : fn({})
61
- res = res && typeof res === 'object' && !Array.isArray(res)
62
- ? [res] // single vnode
63
- : normalizeChildren(res)
64
- let vnode: VNode = res && res[0]
65
- return res && (
66
- !vnode ||
67
- (vnode.isComment && !isAsyncPlaceholder(vnode)) // #9658, #10391
68
- ) ? undefined
65
+ res =
66
+ res && typeof res === 'object' && !isArray(res)
67
+ ? [res] // single vnode
68
+ : normalizeChildren(res)
69
+ const vnode: VNode | null = res && res[0]
70
+ setCurrentInstance(cur)
71
+ return res &&
72
+ (!vnode ||
73
+ (res.length === 1 && vnode.isComment && !isAsyncPlaceholder(vnode))) // #9658, #10391
74
+ ? undefined
69
75
  : res
70
76
  }
71
77
  // this is a slot using the new v-slot syntax without scope. although it is
@@ -1,5 +1,3 @@
1
- /* @flow */
2
-
3
1
  import {
4
2
  warn,
5
3
  once,
@@ -12,27 +10,24 @@ import {
12
10
  remove
13
11
  } from 'core/util/index'
14
12
 
15
- import { createEmptyVNode } from 'core/vdom/vnode'
13
+ import VNode, { createEmptyVNode } from 'core/vdom/vnode'
16
14
  import { currentRenderingInstance } from 'core/instance/render'
15
+ import type { VNodeData } from 'types/vnode'
16
+ import type { Component } from 'types/component'
17
17
 
18
- function ensureCtor (comp: any, base) {
19
- if (
20
- comp.__esModule ||
21
- (hasSymbol && comp[Symbol.toStringTag] === 'Module')
22
- ) {
18
+ function ensureCtor(comp: any, base) {
19
+ if (comp.__esModule || (hasSymbol && comp[Symbol.toStringTag] === 'Module')) {
23
20
  comp = comp.default
24
21
  }
25
- return isObject(comp)
26
- ? base.extend(comp)
27
- : comp
22
+ return isObject(comp) ? base.extend(comp) : comp
28
23
  }
29
24
 
30
- export function createAsyncPlaceholder (
25
+ export function createAsyncPlaceholder(
31
26
  factory: Function,
32
- data: ?VNodeData,
27
+ data: VNodeData | undefined,
33
28
  context: Component,
34
- children: ?Array<VNode>,
35
- tag: ?string
29
+ children: Array<VNode> | undefined,
30
+ tag?: string
36
31
  ): VNode {
37
32
  const node = createEmptyVNode()
38
33
  node.asyncFactory = factory
@@ -40,10 +35,10 @@ export function createAsyncPlaceholder (
40
35
  return node
41
36
  }
42
37
 
43
- export function resolveAsyncComponent (
44
- factory: Function,
45
- baseCtor: Class<Component>
46
- ): Class<Component> | void {
38
+ export function resolveAsyncComponent(
39
+ factory: { (...args: any[]): any; [keye: string]: any },
40
+ baseCtor: typeof Component
41
+ ): typeof Component | void {
47
42
  if (isTrue(factory.error) && isDef(factory.errorComp)) {
48
43
  return factory.errorComp
49
44
  }
@@ -63,16 +58,16 @@ export function resolveAsyncComponent (
63
58
  }
64
59
 
65
60
  if (owner && !isDef(factory.owners)) {
66
- const owners = factory.owners = [owner]
61
+ const owners = (factory.owners = [owner])
67
62
  let sync = true
68
- let timerLoading = null
69
- let timerTimeout = null
63
+ let timerLoading: number | null = null
64
+ let timerTimeout: number | null = null
70
65
 
71
- ;(owner: any).$on('hook:destroyed', () => remove(owners, owner))
66
+ owner.$on('hook:destroyed', () => remove(owners, owner))
72
67
 
73
68
  const forceRender = (renderCompleted: boolean) => {
74
69
  for (let i = 0, l = owners.length; i < l; i++) {
75
- (owners[i]: any).$forceUpdate()
70
+ owners[i].$forceUpdate()
76
71
  }
77
72
 
78
73
  if (renderCompleted) {
@@ -88,7 +83,7 @@ export function resolveAsyncComponent (
88
83
  }
89
84
  }
90
85
 
91
- const resolve = once((res: Object | Class<Component>) => {
86
+ const resolve = once((res: Object | Component) => {
92
87
  // cache resolved
93
88
  factory.resolved = ensureCtor(res, baseCtor)
94
89
  // invoke callbacks only if this is not a synchronous resolve
@@ -101,10 +96,11 @@ export function resolveAsyncComponent (
101
96
  })
102
97
 
103
98
  const reject = once(reason => {
104
- process.env.NODE_ENV !== 'production' && warn(
105
- `Failed to resolve async component: ${String(factory)}` +
106
- (reason ? `\nReason: ${reason}` : '')
107
- )
99
+ __DEV__ &&
100
+ warn(
101
+ `Failed to resolve async component: ${String(factory)}` +
102
+ (reason ? `\nReason: ${reason}` : '')
103
+ )
108
104
  if (isDef(factory.errorComp)) {
109
105
  factory.error = true
110
106
  forceRender(true)
@@ -131,6 +127,7 @@ export function resolveAsyncComponent (
131
127
  if (res.delay === 0) {
132
128
  factory.loading = true
133
129
  } else {
130
+ // @ts-expect-error NodeJS timeout type
134
131
  timerLoading = setTimeout(() => {
135
132
  timerLoading = null
136
133
  if (isUndef(factory.resolved) && isUndef(factory.error)) {
@@ -142,14 +139,11 @@ export function resolveAsyncComponent (
142
139
  }
143
140
 
144
141
  if (isDef(res.timeout)) {
142
+ // @ts-expect-error NodeJS timeout type
145
143
  timerTimeout = setTimeout(() => {
146
144
  timerTimeout = null
147
145
  if (isUndef(factory.resolved)) {
148
- reject(
149
- process.env.NODE_ENV !== 'production'
150
- ? `timeout (${res.timeout}ms)`
151
- : null
152
- )
146
+ reject(__DEV__ ? `timeout (${res.timeout}ms)` : null)
153
147
  }
154
148
  }, res.timeout)
155
149
  }
@@ -158,8 +152,6 @@ export function resolveAsyncComponent (
158
152
 
159
153
  sync = false
160
154
  // return in case resolved synchronously
161
- return factory.loading
162
- ? factory.loadingComp
163
- : factory.resolved
155
+ return factory.loading ? factory.loadingComp : factory.resolved
164
156
  }
165
157
  }