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,11 +1,10 @@
1
- /* @flow */
2
-
3
1
  import {
4
2
  warn,
5
3
  nextTick,
6
4
  emptyObject,
7
5
  handleError,
8
- defineReactive
6
+ defineReactive,
7
+ isArray
9
8
  } from '../util/index'
10
9
 
11
10
  import { createElement } from '../vdom/create-element'
@@ -15,22 +14,27 @@ import { normalizeScopedSlots } from '../vdom/helpers/normalize-scoped-slots'
15
14
  import VNode, { createEmptyVNode } from '../vdom/vnode'
16
15
 
17
16
  import { isUpdatingChildComponent } from './lifecycle'
17
+ import type { Component } from 'types/component'
18
+ import { setCurrentInstance } from 'v3/currentInstance'
19
+ import { syncSetupSlots } from 'v3/apiSetup'
18
20
 
19
- export function initRender (vm: Component) {
21
+ export function initRender(vm: Component) {
20
22
  vm._vnode = null // the root of the child tree
21
23
  vm._staticTrees = null // v-once cached trees
22
24
  const options = vm.$options
23
- const parentVnode = vm.$vnode = options._parentVnode // the placeholder node in parent tree
24
- const renderContext = parentVnode && parentVnode.context
25
+ const parentVnode = (vm.$vnode = options._parentVnode!) // the placeholder node in parent tree
26
+ const renderContext = parentVnode && (parentVnode.context as Component)
25
27
  vm.$slots = resolveSlots(options._renderChildren, renderContext)
26
28
  vm.$scopedSlots = emptyObject
27
29
  // bind the createElement fn to this instance
28
30
  // so that we get proper render context inside it.
29
31
  // args order: tag, data, children, normalizationType, alwaysNormalize
30
32
  // internal version is used by render functions compiled from templates
33
+ // @ts-expect-error
31
34
  vm._c = (a, b, c, d) => createElement(vm, a, b, c, d, false)
32
35
  // normalization is always applied for the public version, used in
33
36
  // user-written render functions.
37
+ // @ts-expect-error
34
38
  vm.$createElement = (a, b, c, d) => createElement(vm, a, b, c, d, true)
35
39
 
36
40
  // $attrs & $listeners are exposed for easier HOC creation.
@@ -38,31 +42,55 @@ export function initRender (vm: Component) {
38
42
  const parentData = parentVnode && parentVnode.data
39
43
 
40
44
  /* istanbul ignore else */
41
- if (process.env.NODE_ENV !== 'production') {
42
- defineReactive(vm, '$attrs', parentData && parentData.attrs || emptyObject, () => {
43
- !isUpdatingChildComponent && warn(`$attrs is readonly.`, vm)
44
- }, true)
45
- defineReactive(vm, '$listeners', options._parentListeners || emptyObject, () => {
46
- !isUpdatingChildComponent && warn(`$listeners is readonly.`, vm)
47
- }, true)
45
+ if (__DEV__) {
46
+ defineReactive(
47
+ vm,
48
+ '$attrs',
49
+ (parentData && parentData.attrs) || emptyObject,
50
+ () => {
51
+ !isUpdatingChildComponent && warn(`$attrs is readonly.`, vm)
52
+ },
53
+ true
54
+ )
55
+ defineReactive(
56
+ vm,
57
+ '$listeners',
58
+ options._parentListeners || emptyObject,
59
+ () => {
60
+ !isUpdatingChildComponent && warn(`$listeners is readonly.`, vm)
61
+ },
62
+ true
63
+ )
48
64
  } else {
49
- defineReactive(vm, '$attrs', parentData && parentData.attrs || emptyObject, null, true)
50
- defineReactive(vm, '$listeners', options._parentListeners || emptyObject, null, true)
65
+ defineReactive(
66
+ vm,
67
+ '$attrs',
68
+ (parentData && parentData.attrs) || emptyObject,
69
+ null,
70
+ true
71
+ )
72
+ defineReactive(
73
+ vm,
74
+ '$listeners',
75
+ options._parentListeners || emptyObject,
76
+ null,
77
+ true
78
+ )
51
79
  }
52
80
  }
53
81
 
54
82
  export let currentRenderingInstance: Component | null = null
55
83
 
56
84
  // for testing only
57
- export function setCurrentRenderingInstance (vm: Component) {
85
+ export function setCurrentRenderingInstance(vm: Component) {
58
86
  currentRenderingInstance = vm
59
87
  }
60
88
 
61
- export function renderMixin (Vue: Class<Component>) {
89
+ export function renderMixin(Vue: typeof Component) {
62
90
  // install runtime convenience helpers
63
91
  installRenderHelpers(Vue.prototype)
64
92
 
65
- Vue.prototype.$nextTick = function (fn: Function) {
93
+ Vue.prototype.$nextTick = function (fn: (...args: any[]) => any) {
66
94
  return nextTick(fn, this)
67
95
  }
68
96
 
@@ -72,32 +100,40 @@ export function renderMixin (Vue: Class<Component>) {
72
100
 
73
101
  if (_parentVnode) {
74
102
  vm.$scopedSlots = normalizeScopedSlots(
75
- _parentVnode.data.scopedSlots,
76
- vm.$slots,
77
- vm.$scopedSlots
103
+ vm.$parent!,
104
+ _parentVnode.data!.scopedSlots,
105
+ vm.$slots
78
106
  )
107
+ if (vm._slotsProxy) {
108
+ syncSetupSlots(vm._slotsProxy, vm.$scopedSlots)
109
+ }
79
110
  }
80
111
 
81
112
  // set parent vnode. this allows render functions to have access
82
113
  // to the data on the placeholder node.
83
- vm.$vnode = _parentVnode
114
+ vm.$vnode = _parentVnode!
84
115
  // render self
85
116
  let vnode
86
117
  try {
87
118
  // There's no need to maintain a stack because all render fns are called
88
119
  // separately from one another. Nested component's render fns are called
89
120
  // when parent component is patched.
121
+ setCurrentInstance(vm)
90
122
  currentRenderingInstance = vm
91
123
  vnode = render.call(vm._renderProxy, vm.$createElement)
92
- } catch (e) {
124
+ } catch (e: any) {
93
125
  handleError(e, vm, `render`)
94
126
  // return error render result,
95
127
  // or previous vnode to prevent render error causing blank component
96
128
  /* istanbul ignore else */
97
- if (process.env.NODE_ENV !== 'production' && vm.$options.renderError) {
129
+ if (__DEV__ && vm.$options.renderError) {
98
130
  try {
99
- vnode = vm.$options.renderError.call(vm._renderProxy, vm.$createElement, e)
100
- } catch (e) {
131
+ vnode = vm.$options.renderError.call(
132
+ vm._renderProxy,
133
+ vm.$createElement,
134
+ e
135
+ )
136
+ } catch (e: any) {
101
137
  handleError(e, vm, `renderError`)
102
138
  vnode = vm._vnode
103
139
  }
@@ -106,17 +142,18 @@ export function renderMixin (Vue: Class<Component>) {
106
142
  }
107
143
  } finally {
108
144
  currentRenderingInstance = null
145
+ setCurrentInstance()
109
146
  }
110
147
  // if the returned array contains only a single node, allow it
111
- if (Array.isArray(vnode) && vnode.length === 1) {
148
+ if (isArray(vnode) && vnode.length === 1) {
112
149
  vnode = vnode[0]
113
150
  }
114
151
  // return empty vnode in case the render function errored out
115
152
  if (!(vnode instanceof VNode)) {
116
- if (process.env.NODE_ENV !== 'production' && Array.isArray(vnode)) {
153
+ if (__DEV__ && isArray(vnode)) {
117
154
  warn(
118
155
  'Multiple root nodes returned from render function. Render function ' +
119
- 'should return a single root node.',
156
+ 'should return a single root node.',
120
157
  vm
121
158
  )
122
159
  }
@@ -1,9 +1,8 @@
1
- /* @flow */
2
-
3
1
  import config from '../config'
4
2
  import Watcher from '../observer/watcher'
5
3
  import Dep, { pushTarget, popTarget } from '../observer/dep'
6
4
  import { isUpdatingChildComponent } from './lifecycle'
5
+ import { initSetup } from 'v3/apiSetup'
7
6
 
8
7
  import {
9
8
  set,
@@ -18,6 +17,7 @@ import {
18
17
  bind,
19
18
  noop,
20
19
  hasOwn,
20
+ isArray,
21
21
  hyphenate,
22
22
  isReserved,
23
23
  handleError,
@@ -26,8 +26,11 @@ import {
26
26
  isPlainObject,
27
27
  isServerRendering,
28
28
  isReservedAttribute,
29
- invokeWithErrorHandling
29
+ invokeWithErrorHandling,
30
+ isFunction
30
31
  } from '../util/index'
32
+ import type { Component } from 'types/component'
33
+ import { TrackOpTypes } from '../../v3'
31
34
 
32
35
  const sharedPropertyDefinition = {
33
36
  enumerable: true,
@@ -36,25 +39,29 @@ const sharedPropertyDefinition = {
36
39
  set: noop
37
40
  }
38
41
 
39
- export function proxy (target: Object, sourceKey: string, key: string) {
40
- sharedPropertyDefinition.get = function proxyGetter () {
42
+ export function proxy(target: Object, sourceKey: string, key: string) {
43
+ sharedPropertyDefinition.get = function proxyGetter() {
41
44
  return this[sourceKey][key]
42
45
  }
43
- sharedPropertyDefinition.set = function proxySetter (val) {
46
+ sharedPropertyDefinition.set = function proxySetter(val) {
44
47
  this[sourceKey][key] = val
45
48
  }
46
49
  Object.defineProperty(target, key, sharedPropertyDefinition)
47
50
  }
48
51
 
49
- export function initState (vm: Component) {
50
- vm._watchers = []
52
+ export function initState(vm: Component) {
51
53
  const opts = vm.$options
52
54
  if (opts.props) initProps(vm, opts.props)
55
+
56
+ // Composition API
57
+ initSetup(vm)
58
+
53
59
  if (opts.methods) initMethods(vm, opts.methods)
54
60
  if (opts.data) {
55
61
  initData(vm)
56
62
  } else {
57
- observe(vm._data = {}, true /* asRootData */)
63
+ const ob = observe((vm._data = {}))
64
+ ob && ob.vmCount++
58
65
  }
59
66
  if (opts.computed) initComputed(vm, opts.computed)
60
67
  if (opts.watch && opts.watch !== nativeWatch) {
@@ -62,12 +69,12 @@ export function initState (vm: Component) {
62
69
  }
63
70
  }
64
71
 
65
- function initProps (vm: Component, propsOptions: Object) {
72
+ function initProps(vm: Component, propsOptions: Object) {
66
73
  const propsData = vm.$options.propsData || {}
67
- const props = vm._props = {}
74
+ const props = (vm._props = {})
68
75
  // cache prop keys so that future props updates can iterate using Array
69
76
  // instead of dynamic object key enumeration.
70
- const keys = vm.$options._propKeys = []
77
+ const keys: string[] = (vm.$options._propKeys = [])
71
78
  const isRoot = !vm.$parent
72
79
  // root instance props should be converted
73
80
  if (!isRoot) {
@@ -77,10 +84,12 @@ function initProps (vm: Component, propsOptions: Object) {
77
84
  keys.push(key)
78
85
  const value = validateProp(key, propsOptions, propsData, vm)
79
86
  /* istanbul ignore else */
80
- if (process.env.NODE_ENV !== 'production') {
87
+ if (__DEV__) {
81
88
  const hyphenatedKey = hyphenate(key)
82
- if (isReservedAttribute(hyphenatedKey) ||
83
- config.isReservedAttr(hyphenatedKey)) {
89
+ if (
90
+ isReservedAttribute(hyphenatedKey) ||
91
+ config.isReservedAttr(hyphenatedKey)
92
+ ) {
84
93
  warn(
85
94
  `"${hyphenatedKey}" is a reserved attribute and cannot be used as component prop.`,
86
95
  vm
@@ -90,9 +99,9 @@ function initProps (vm: Component, propsOptions: Object) {
90
99
  if (!isRoot && !isUpdatingChildComponent) {
91
100
  warn(
92
101
  `Avoid mutating a prop directly since the value will be ` +
93
- `overwritten whenever the parent component re-renders. ` +
94
- `Instead, use a data or computed property based on the prop's ` +
95
- `value. Prop being mutated: "${key}"`,
102
+ `overwritten whenever the parent component re-renders. ` +
103
+ `Instead, use a data or computed property based on the prop's ` +
104
+ `value. Prop being mutated: "${key}"`,
96
105
  vm
97
106
  )
98
107
  }
@@ -110,18 +119,17 @@ function initProps (vm: Component, propsOptions: Object) {
110
119
  toggleObserving(true)
111
120
  }
112
121
 
113
- function initData (vm: Component) {
114
- let data = vm.$options.data
115
- data = vm._data = typeof data === 'function'
116
- ? getData(data, vm)
117
- : data || {}
122
+ function initData(vm: Component) {
123
+ let data: any = vm.$options.data
124
+ data = vm._data = isFunction(data) ? getData(data, vm) : data || {}
118
125
  if (!isPlainObject(data)) {
119
126
  data = {}
120
- process.env.NODE_ENV !== 'production' && warn(
121
- 'data functions should return an object:\n' +
122
- 'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',
123
- vm
124
- )
127
+ __DEV__ &&
128
+ warn(
129
+ 'data functions should return an object:\n' +
130
+ 'https://vuejs.org/v2/guide/components.html#data-Must-Be-a-Function',
131
+ vm
132
+ )
125
133
  }
126
134
  // proxy data on instance
127
135
  const keys = Object.keys(data)
@@ -130,34 +138,33 @@ function initData (vm: Component) {
130
138
  let i = keys.length
131
139
  while (i--) {
132
140
  const key = keys[i]
133
- if (process.env.NODE_ENV !== 'production') {
141
+ if (__DEV__) {
134
142
  if (methods && hasOwn(methods, key)) {
135
- warn(
136
- `Method "${key}" has already been defined as a data property.`,
137
- vm
138
- )
143
+ warn(`Method "${key}" has already been defined as a data property.`, vm)
139
144
  }
140
145
  }
141
146
  if (props && hasOwn(props, key)) {
142
- process.env.NODE_ENV !== 'production' && warn(
143
- `The data property "${key}" is already declared as a prop. ` +
144
- `Use prop default value instead.`,
145
- vm
146
- )
147
+ __DEV__ &&
148
+ warn(
149
+ `The data property "${key}" is already declared as a prop. ` +
150
+ `Use prop default value instead.`,
151
+ vm
152
+ )
147
153
  } else if (!isReserved(key)) {
148
154
  proxy(vm, `_data`, key)
149
155
  }
150
156
  }
151
157
  // observe data
152
- observe(data, true /* asRootData */)
158
+ const ob = observe(data)
159
+ ob && ob.vmCount++
153
160
  }
154
161
 
155
- export function getData (data: Function, vm: Component): any {
162
+ export function getData(data: Function, vm: Component): any {
156
163
  // #7573 disable dep collection when invoking data getters
157
164
  pushTarget()
158
165
  try {
159
166
  return data.call(vm, vm)
160
- } catch (e) {
167
+ } catch (e: any) {
161
168
  handleError(e, vm, `data()`)
162
169
  return {}
163
170
  } finally {
@@ -167,20 +174,17 @@ export function getData (data: Function, vm: Component): any {
167
174
 
168
175
  const computedWatcherOptions = { lazy: true }
169
176
 
170
- function initComputed (vm: Component, computed: Object) {
177
+ function initComputed(vm: Component, computed: Object) {
171
178
  // $flow-disable-line
172
- const watchers = vm._computedWatchers = Object.create(null)
179
+ const watchers = (vm._computedWatchers = Object.create(null))
173
180
  // computed properties are just getters during SSR
174
181
  const isSSR = isServerRendering()
175
182
 
176
183
  for (const key in computed) {
177
184
  const userDef = computed[key]
178
- const getter = typeof userDef === 'function' ? userDef : userDef.get
179
- if (process.env.NODE_ENV !== 'production' && getter == null) {
180
- warn(
181
- `Getter is missing for computed property "${key}".`,
182
- vm
183
- )
185
+ const getter = isFunction(userDef) ? userDef : userDef.get
186
+ if (__DEV__ && getter == null) {
187
+ warn(`Getter is missing for computed property "${key}".`, vm)
184
188
  }
185
189
 
186
190
  if (!isSSR) {
@@ -198,25 +202,28 @@ function initComputed (vm: Component, computed: Object) {
198
202
  // at instantiation here.
199
203
  if (!(key in vm)) {
200
204
  defineComputed(vm, key, userDef)
201
- } else if (process.env.NODE_ENV !== 'production') {
205
+ } else if (__DEV__) {
202
206
  if (key in vm.$data) {
203
207
  warn(`The computed property "${key}" is already defined in data.`, vm)
204
208
  } else if (vm.$options.props && key in vm.$options.props) {
205
209
  warn(`The computed property "${key}" is already defined as a prop.`, vm)
206
210
  } else if (vm.$options.methods && key in vm.$options.methods) {
207
- warn(`The computed property "${key}" is already defined as a method.`, vm)
211
+ warn(
212
+ `The computed property "${key}" is already defined as a method.`,
213
+ vm
214
+ )
208
215
  }
209
216
  }
210
217
  }
211
218
  }
212
219
 
213
- export function defineComputed (
220
+ export function defineComputed(
214
221
  target: any,
215
222
  key: string,
216
- userDef: Object | Function
223
+ userDef: Record<string, any> | (() => any)
217
224
  ) {
218
225
  const shouldCache = !isServerRendering()
219
- if (typeof userDef === 'function') {
226
+ if (isFunction(userDef)) {
220
227
  sharedPropertyDefinition.get = shouldCache
221
228
  ? createComputedGetter(key)
222
229
  : createGetterInvoker(userDef)
@@ -229,8 +236,7 @@ export function defineComputed (
229
236
  : noop
230
237
  sharedPropertyDefinition.set = userDef.set || noop
231
238
  }
232
- if (process.env.NODE_ENV !== 'production' &&
233
- sharedPropertyDefinition.set === noop) {
239
+ if (__DEV__ && sharedPropertyDefinition.set === noop) {
234
240
  sharedPropertyDefinition.set = function () {
235
241
  warn(
236
242
  `Computed property "${key}" was assigned to but it has no setter.`,
@@ -241,14 +247,22 @@ export function defineComputed (
241
247
  Object.defineProperty(target, key, sharedPropertyDefinition)
242
248
  }
243
249
 
244
- function createComputedGetter (key) {
245
- return function computedGetter () {
250
+ function createComputedGetter(key) {
251
+ return function computedGetter() {
246
252
  const watcher = this._computedWatchers && this._computedWatchers[key]
247
253
  if (watcher) {
248
254
  if (watcher.dirty) {
249
255
  watcher.evaluate()
250
256
  }
251
257
  if (Dep.target) {
258
+ if (__DEV__ && Dep.target.onTrack) {
259
+ Dep.target.onTrack({
260
+ effect: Dep.target,
261
+ target: this,
262
+ type: TrackOpTypes.GET,
263
+ key
264
+ })
265
+ }
252
266
  watcher.depend()
253
267
  }
254
268
  return watcher.value
@@ -257,32 +271,31 @@ function createComputedGetter (key) {
257
271
  }
258
272
 
259
273
  function createGetterInvoker(fn) {
260
- return function computedGetter () {
274
+ return function computedGetter() {
261
275
  return fn.call(this, this)
262
276
  }
263
277
  }
264
278
 
265
- function initMethods (vm: Component, methods: Object) {
279
+ function initMethods(vm: Component, methods: Object) {
266
280
  const props = vm.$options.props
267
281
  for (const key in methods) {
268
- if (process.env.NODE_ENV !== 'production') {
282
+ if (__DEV__) {
269
283
  if (typeof methods[key] !== 'function') {
270
284
  warn(
271
- `Method "${key}" has type "${typeof methods[key]}" in the component definition. ` +
272
- `Did you reference the function correctly?`,
285
+ `Method "${key}" has type "${typeof methods[
286
+ key
287
+ ]}" in the component definition. ` +
288
+ `Did you reference the function correctly?`,
273
289
  vm
274
290
  )
275
291
  }
276
292
  if (props && hasOwn(props, key)) {
277
- warn(
278
- `Method "${key}" has already been defined as a prop.`,
279
- vm
280
- )
293
+ warn(`Method "${key}" has already been defined as a prop.`, vm)
281
294
  }
282
- if ((key in vm) && isReserved(key)) {
295
+ if (key in vm && isReserved(key)) {
283
296
  warn(
284
297
  `Method "${key}" conflicts with an existing Vue instance method. ` +
285
- `Avoid defining component methods that start with _ or $.`
298
+ `Avoid defining component methods that start with _ or $.`
286
299
  )
287
300
  }
288
301
  }
@@ -290,10 +303,10 @@ function initMethods (vm: Component, methods: Object) {
290
303
  }
291
304
  }
292
305
 
293
- function initWatch (vm: Component, watch: Object) {
306
+ function initWatch(vm: Component, watch: Object) {
294
307
  for (const key in watch) {
295
308
  const handler = watch[key]
296
- if (Array.isArray(handler)) {
309
+ if (isArray(handler)) {
297
310
  for (let i = 0; i < handler.length; i++) {
298
311
  createWatcher(vm, key, handler[i])
299
312
  }
@@ -303,9 +316,9 @@ function initWatch (vm: Component, watch: Object) {
303
316
  }
304
317
  }
305
318
 
306
- function createWatcher (
319
+ function createWatcher(
307
320
  vm: Component,
308
- expOrFn: string | Function,
321
+ expOrFn: string | (() => any),
309
322
  handler: any,
310
323
  options?: Object
311
324
  ) {
@@ -319,19 +332,23 @@ function createWatcher (
319
332
  return vm.$watch(expOrFn, handler, options)
320
333
  }
321
334
 
322
- export function stateMixin (Vue: Class<Component>) {
335
+ export function stateMixin(Vue: typeof Component) {
323
336
  // flow somehow has problems with directly declared definition object
324
337
  // when using Object.defineProperty, so we have to procedurally build up
325
338
  // the object here.
326
- const dataDef = {}
327
- dataDef.get = function () { return this._data }
328
- const propsDef = {}
329
- propsDef.get = function () { return this._props }
330
- if (process.env.NODE_ENV !== 'production') {
339
+ const dataDef: any = {}
340
+ dataDef.get = function () {
341
+ return this._data
342
+ }
343
+ const propsDef: any = {}
344
+ propsDef.get = function () {
345
+ return this._props
346
+ }
347
+ if (__DEV__) {
331
348
  dataDef.set = function () {
332
349
  warn(
333
350
  'Avoid replacing instance root $data. ' +
334
- 'Use nested data properties instead.',
351
+ 'Use nested data properties instead.',
335
352
  this
336
353
  )
337
354
  }
@@ -346,9 +363,9 @@ export function stateMixin (Vue: Class<Component>) {
346
363
  Vue.prototype.$delete = del
347
364
 
348
365
  Vue.prototype.$watch = function (
349
- expOrFn: string | Function,
366
+ expOrFn: string | (() => any),
350
367
  cb: any,
351
- options?: Object
368
+ options?: Record<string, any>
352
369
  ): Function {
353
370
  const vm: Component = this
354
371
  if (isPlainObject(cb)) {
@@ -363,7 +380,7 @@ export function stateMixin (Vue: Class<Component>) {
363
380
  invokeWithErrorHandling(cb, vm, [watcher.value], vm, info)
364
381
  popTarget()
365
382
  }
366
- return function unwatchFn () {
383
+ return function unwatchFn() {
367
384
  watcher.teardown()
368
385
  }
369
386
  }
@@ -3,6 +3,7 @@
3
3
  * dynamically accessing methods on Array prototype
4
4
  */
5
5
 
6
+ import { TriggerOpTypes } from '../../v3'
6
7
  import { def } from '../util/index'
7
8
 
8
9
  const arrayProto = Array.prototype
@@ -24,7 +25,7 @@ const methodsToPatch = [
24
25
  methodsToPatch.forEach(function (method) {
25
26
  // cache original method
26
27
  const original = arrayProto[method]
27
- def(arrayMethods, method, function mutator (...args) {
28
+ def(arrayMethods, method, function mutator(...args) {
28
29
  const result = original.apply(this, args)
29
30
  const ob = this.__ob__
30
31
  let inserted
@@ -39,7 +40,15 @@ methodsToPatch.forEach(function (method) {
39
40
  }
40
41
  if (inserted) ob.observeArray(inserted)
41
42
  // notify change
42
- ob.dep.notify()
43
+ if (__DEV__) {
44
+ ob.dep.notify({
45
+ type: TriggerOpTypes.ARRAY_MUTATION,
46
+ target: this,
47
+ key: method
48
+ })
49
+ } else {
50
+ ob.dep.notify()
51
+ }
43
52
  return result
44
53
  })
45
54
  })