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,4 +1,3 @@
1
- /* @flow */
2
1
  /* globals MutationObserver */
3
2
 
4
3
  import { noop } from 'shared/util'
@@ -7,10 +6,10 @@ import { isIE, isIOS, isNative } from './env'
7
6
 
8
7
  export let isUsingMicroTask = false
9
8
 
10
- const callbacks = []
9
+ const callbacks: Array<Function> = []
11
10
  let pending = false
12
11
 
13
- function flushCallbacks () {
12
+ function flushCallbacks() {
14
13
  pending = false
15
14
  const copies = callbacks.slice(0)
16
15
  callbacks.length = 0
@@ -51,11 +50,13 @@ if (typeof Promise !== 'undefined' && isNative(Promise)) {
51
50
  if (isIOS) setTimeout(noop)
52
51
  }
53
52
  isUsingMicroTask = true
54
- } else if (!isIE && typeof MutationObserver !== 'undefined' && (
55
- isNative(MutationObserver) ||
56
- // PhantomJS and iOS 7.x
57
- MutationObserver.toString() === '[object MutationObserverConstructor]'
58
- )) {
53
+ } else if (
54
+ !isIE &&
55
+ typeof MutationObserver !== 'undefined' &&
56
+ (isNative(MutationObserver) ||
57
+ // PhantomJS and iOS 7.x
58
+ MutationObserver.toString() === '[object MutationObserverConstructor]')
59
+ ) {
59
60
  // Use MutationObserver where native Promise is not available,
60
61
  // e.g. PhantomJS, iOS7, Android 4.4
61
62
  // (#6466 MutationObserver is unreliable in IE11)
@@ -84,13 +85,18 @@ if (typeof Promise !== 'undefined' && isNative(Promise)) {
84
85
  }
85
86
  }
86
87
 
87
- export function nextTick (cb?: Function, ctx?: Object) {
88
+ export function nextTick(): Promise<void>
89
+ export function nextTick(cb: (...args: any[]) => any, ctx?: object): void
90
+ /**
91
+ * @internal
92
+ */
93
+ export function nextTick(cb?: (...args: any[]) => any, ctx?: object) {
88
94
  let _resolve
89
95
  callbacks.push(() => {
90
96
  if (cb) {
91
97
  try {
92
98
  cb.call(ctx)
93
- } catch (e) {
99
+ } catch (e: any) {
94
100
  handleError(e, ctx, 'nextTick')
95
101
  }
96
102
  } else if (_resolve) {
@@ -1,15 +1,11 @@
1
- /* @flow */
2
-
3
1
  import config from '../config'
4
2
  import { warn } from './debug'
5
3
  import { set } from '../observer/index'
6
4
  import { unicodeRegExp } from './lang'
7
5
  import { nativeWatch, hasSymbol } from './env'
6
+ import { isArray, isFunction } from 'shared/util'
8
7
 
9
- import {
10
- ASSET_TYPES,
11
- LIFECYCLE_HOOKS
12
- } from 'shared/constants'
8
+ import { ASSET_TYPES, LIFECYCLE_HOOKS } from 'shared/constants'
13
9
 
14
10
  import {
15
11
  extend,
@@ -20,6 +16,8 @@ import {
20
16
  isBuiltInTag,
21
17
  isPlainObject
22
18
  } from 'shared/util'
19
+ import type { Component } from 'types/component'
20
+ import type { ComponentOptions } from 'types/options'
23
21
 
24
22
  /**
25
23
  * Option overwriting strategies are functions that handle
@@ -31,12 +29,17 @@ const strats = config.optionMergeStrategies
31
29
  /**
32
30
  * Options with restrictions
33
31
  */
34
- if (process.env.NODE_ENV !== 'production') {
35
- strats.el = strats.propsData = function (parent, child, vm, key) {
32
+ if (__DEV__) {
33
+ strats.el = strats.propsData = function (
34
+ parent: any,
35
+ child: any,
36
+ vm: any,
37
+ key: any
38
+ ) {
36
39
  if (!vm) {
37
40
  warn(
38
41
  `option "${key}" can only be used during instance ` +
39
- 'creation with the `new` keyword.'
42
+ 'creation with the `new` keyword.'
40
43
  )
41
44
  }
42
45
  return defaultStrat(parent, child)
@@ -46,12 +49,15 @@ if (process.env.NODE_ENV !== 'production') {
46
49
  /**
47
50
  * Helper that recursively merges two data objects together.
48
51
  */
49
- function mergeData (to: Object, from: ?Object): Object {
52
+ function mergeData(
53
+ to: Record<string | symbol, any>,
54
+ from: Record<string | symbol, any> | null
55
+ ): Record<PropertyKey, any> {
50
56
  if (!from) return to
51
57
  let key, toVal, fromVal
52
58
 
53
59
  const keys = hasSymbol
54
- ? Reflect.ownKeys(from)
60
+ ? (Reflect.ownKeys(from) as string[])
55
61
  : Object.keys(from)
56
62
 
57
63
  for (let i = 0; i < keys.length; i++) {
@@ -76,11 +82,11 @@ function mergeData (to: Object, from: ?Object): Object {
76
82
  /**
77
83
  * Data
78
84
  */
79
- export function mergeDataOrFn (
85
+ export function mergeDataOrFn(
80
86
  parentVal: any,
81
87
  childVal: any,
82
88
  vm?: Component
83
- ): ?Function {
89
+ ): Function | null {
84
90
  if (!vm) {
85
91
  // in a Vue.extend merge, both should be functions
86
92
  if (!childVal) {
@@ -94,19 +100,19 @@ export function mergeDataOrFn (
94
100
  // merged result of both functions... no need to
95
101
  // check if parentVal is a function here because
96
102
  // it has to be a function to pass previous merges.
97
- return function mergedDataFn () {
103
+ return function mergedDataFn() {
98
104
  return mergeData(
99
- typeof childVal === 'function' ? childVal.call(this, this) : childVal,
100
- typeof parentVal === 'function' ? parentVal.call(this, this) : parentVal
105
+ isFunction(childVal) ? childVal.call(this, this) : childVal,
106
+ isFunction(parentVal) ? parentVal.call(this, this) : parentVal
101
107
  )
102
108
  }
103
109
  } else {
104
- return function mergedInstanceDataFn () {
110
+ return function mergedInstanceDataFn() {
105
111
  // instance merge
106
- const instanceData = typeof childVal === 'function'
112
+ const instanceData = isFunction(childVal)
107
113
  ? childVal.call(vm, vm)
108
114
  : childVal
109
- const defaultData = typeof parentVal === 'function'
115
+ const defaultData = isFunction(parentVal)
110
116
  ? parentVal.call(vm, vm)
111
117
  : parentVal
112
118
  if (instanceData) {
@@ -122,15 +128,16 @@ strats.data = function (
122
128
  parentVal: any,
123
129
  childVal: any,
124
130
  vm?: Component
125
- ): ?Function {
131
+ ): Function | null {
126
132
  if (!vm) {
127
133
  if (childVal && typeof childVal !== 'function') {
128
- process.env.NODE_ENV !== 'production' && warn(
129
- 'The "data" option should be a function ' +
130
- 'that returns a per-instance value in component ' +
131
- 'definitions.',
132
- vm
133
- )
134
+ __DEV__ &&
135
+ warn(
136
+ 'The "data" option should be a function ' +
137
+ 'that returns a per-instance value in component ' +
138
+ 'definitions.',
139
+ vm
140
+ )
134
141
 
135
142
  return parentVal
136
143
  }
@@ -143,24 +150,22 @@ strats.data = function (
143
150
  /**
144
151
  * Hooks and props are merged as arrays.
145
152
  */
146
- function mergeHook (
147
- parentVal: ?Array<Function>,
148
- childVal: ?Function | ?Array<Function>
149
- ): ?Array<Function> {
153
+ export function mergeLifecycleHook(
154
+ parentVal: Array<Function> | null,
155
+ childVal: Function | Array<Function> | null
156
+ ): Array<Function> | null {
150
157
  const res = childVal
151
158
  ? parentVal
152
159
  ? parentVal.concat(childVal)
153
- : Array.isArray(childVal)
154
- ? childVal
155
- : [childVal]
160
+ : isArray(childVal)
161
+ ? childVal
162
+ : [childVal]
156
163
  : parentVal
157
- return res
158
- ? dedupeHooks(res)
159
- : res
164
+ return res ? dedupeHooks(res) : res
160
165
  }
161
166
 
162
- function dedupeHooks (hooks) {
163
- const res = []
167
+ function dedupeHooks(hooks: any) {
168
+ const res: Array<any> = []
164
169
  for (let i = 0; i < hooks.length; i++) {
165
170
  if (res.indexOf(hooks[i]) === -1) {
166
171
  res.push(hooks[i])
@@ -170,7 +175,7 @@ function dedupeHooks (hooks) {
170
175
  }
171
176
 
172
177
  LIFECYCLE_HOOKS.forEach(hook => {
173
- strats[hook] = mergeHook
178
+ strats[hook] = mergeLifecycleHook
174
179
  })
175
180
 
176
181
  /**
@@ -180,15 +185,15 @@ LIFECYCLE_HOOKS.forEach(hook => {
180
185
  * a three-way merge between constructor options, instance
181
186
  * options and parent options.
182
187
  */
183
- function mergeAssets (
184
- parentVal: ?Object,
185
- childVal: ?Object,
186
- vm?: Component,
188
+ function mergeAssets(
189
+ parentVal: Object | null,
190
+ childVal: Object | null,
191
+ vm: Component | null,
187
192
  key: string
188
193
  ): Object {
189
194
  const res = Object.create(parentVal || null)
190
195
  if (childVal) {
191
- process.env.NODE_ENV !== 'production' && assertObjectType(key, childVal, vm)
196
+ __DEV__ && assertObjectType(key, childVal, vm)
192
197
  return extend(res, childVal)
193
198
  } else {
194
199
  return res
@@ -206,31 +211,31 @@ ASSET_TYPES.forEach(function (type) {
206
211
  * another, so we merge them as arrays.
207
212
  */
208
213
  strats.watch = function (
209
- parentVal: ?Object,
210
- childVal: ?Object,
211
- vm?: Component,
214
+ parentVal: Record<string, any> | null,
215
+ childVal: Record<string, any> | null,
216
+ vm: Component | null,
212
217
  key: string
213
- ): ?Object {
218
+ ): Object | null {
214
219
  // work around Firefox's Object.prototype.watch...
220
+ //@ts-expect-error work around
215
221
  if (parentVal === nativeWatch) parentVal = undefined
222
+ //@ts-expect-error work around
216
223
  if (childVal === nativeWatch) childVal = undefined
217
224
  /* istanbul ignore if */
218
225
  if (!childVal) return Object.create(parentVal || null)
219
- if (process.env.NODE_ENV !== 'production') {
226
+ if (__DEV__) {
220
227
  assertObjectType(key, childVal, vm)
221
228
  }
222
229
  if (!parentVal) return childVal
223
- const ret = {}
230
+ const ret: Record<string, any> = {}
224
231
  extend(ret, parentVal)
225
232
  for (const key in childVal) {
226
233
  let parent = ret[key]
227
234
  const child = childVal[key]
228
- if (parent && !Array.isArray(parent)) {
235
+ if (parent && !isArray(parent)) {
229
236
  parent = [parent]
230
237
  }
231
- ret[key] = parent
232
- ? parent.concat(child)
233
- : Array.isArray(child) ? child : [child]
238
+ ret[key] = parent ? parent.concat(child) : isArray(child) ? child : [child]
234
239
  }
235
240
  return ret
236
241
  }
@@ -239,54 +244,58 @@ strats.watch = function (
239
244
  * Other object hashes.
240
245
  */
241
246
  strats.props =
242
- strats.methods =
243
- strats.inject =
244
- strats.computed = function (
245
- parentVal: ?Object,
246
- childVal: ?Object,
247
- vm?: Component,
248
- key: string
249
- ): ?Object {
250
- if (childVal && process.env.NODE_ENV !== 'production') {
251
- assertObjectType(key, childVal, vm)
252
- }
253
- if (!parentVal) return childVal
254
- const ret = Object.create(null)
255
- extend(ret, parentVal)
256
- if (childVal) extend(ret, childVal)
257
- return ret
258
- }
247
+ strats.methods =
248
+ strats.inject =
249
+ strats.computed =
250
+ function (
251
+ parentVal: Object | null,
252
+ childVal: Object | null,
253
+ vm: Component | null,
254
+ key: string
255
+ ): Object | null {
256
+ if (childVal && __DEV__) {
257
+ assertObjectType(key, childVal, vm)
258
+ }
259
+ if (!parentVal) return childVal
260
+ const ret = Object.create(null)
261
+ extend(ret, parentVal)
262
+ if (childVal) extend(ret, childVal)
263
+ return ret
264
+ }
259
265
  strats.provide = mergeDataOrFn
260
266
 
261
267
  /**
262
268
  * Default strategy.
263
269
  */
264
270
  const defaultStrat = function (parentVal: any, childVal: any): any {
265
- return childVal === undefined
266
- ? parentVal
267
- : childVal
271
+ return childVal === undefined ? parentVal : childVal
268
272
  }
269
273
 
270
274
  /**
271
275
  * Validate component names
272
276
  */
273
- function checkComponents (options: Object) {
277
+ function checkComponents(options: Record<string, any>) {
274
278
  for (const key in options.components) {
275
279
  validateComponentName(key)
276
280
  }
277
281
  }
278
282
 
279
- export function validateComponentName (name: string) {
280
- if (!new RegExp(`^[a-zA-Z][\\-\\.0-9_${unicodeRegExp.source}]*$`).test(name)) {
283
+ export function validateComponentName(name: string) {
284
+ if (
285
+ !new RegExp(`^[a-zA-Z][\\-\\.0-9_${unicodeRegExp.source}]*$`).test(name)
286
+ ) {
281
287
  warn(
282
- 'Invalid component name: "' + name + '". Component names ' +
283
- 'should conform to valid custom element name in html5 specification.'
288
+ 'Invalid component name: "' +
289
+ name +
290
+ '". Component names ' +
291
+ 'should conform to valid custom element name in html5 specification.'
284
292
  )
285
293
  }
286
294
  if (isBuiltInTag(name) || config.isReservedTag(name)) {
287
295
  warn(
288
296
  'Do not use built-in or reserved HTML elements as component ' +
289
- 'id: ' + name
297
+ 'id: ' +
298
+ name
290
299
  )
291
300
  }
292
301
  }
@@ -295,19 +304,19 @@ export function validateComponentName (name: string) {
295
304
  * Ensure all props option syntax are normalized into the
296
305
  * Object-based format.
297
306
  */
298
- function normalizeProps (options: Object, vm: ?Component) {
307
+ function normalizeProps(options: Record<string, any>, vm?: Component | null) {
299
308
  const props = options.props
300
309
  if (!props) return
301
- const res = {}
310
+ const res: Record<string, any> = {}
302
311
  let i, val, name
303
- if (Array.isArray(props)) {
312
+ if (isArray(props)) {
304
313
  i = props.length
305
314
  while (i--) {
306
315
  val = props[i]
307
316
  if (typeof val === 'string') {
308
317
  name = camelize(val)
309
318
  res[name] = { type: null }
310
- } else if (process.env.NODE_ENV !== 'production') {
319
+ } else if (__DEV__) {
311
320
  warn('props must be strings when using array syntax.')
312
321
  }
313
322
  }
@@ -315,14 +324,12 @@ function normalizeProps (options: Object, vm: ?Component) {
315
324
  for (const key in props) {
316
325
  val = props[key]
317
326
  name = camelize(key)
318
- res[name] = isPlainObject(val)
319
- ? val
320
- : { type: val }
327
+ res[name] = isPlainObject(val) ? val : { type: val }
321
328
  }
322
- } else if (process.env.NODE_ENV !== 'production') {
329
+ } else if (__DEV__) {
323
330
  warn(
324
331
  `Invalid value for option "props": expected an Array or an Object, ` +
325
- `but got ${toRawType(props)}.`,
332
+ `but got ${toRawType(props)}.`,
326
333
  vm
327
334
  )
328
335
  }
@@ -332,11 +339,11 @@ function normalizeProps (options: Object, vm: ?Component) {
332
339
  /**
333
340
  * Normalize all injections into Object-based format
334
341
  */
335
- function normalizeInject (options: Object, vm: ?Component) {
342
+ function normalizeInject(options: Record<string, any>, vm?: Component | null) {
336
343
  const inject = options.inject
337
344
  if (!inject) return
338
- const normalized = options.inject = {}
339
- if (Array.isArray(inject)) {
345
+ const normalized: Record<string, any> = (options.inject = {})
346
+ if (isArray(inject)) {
340
347
  for (let i = 0; i < inject.length; i++) {
341
348
  normalized[inject[i]] = { from: inject[i] }
342
349
  }
@@ -347,10 +354,10 @@ function normalizeInject (options: Object, vm: ?Component) {
347
354
  ? extend({ from: key }, val)
348
355
  : { from: val }
349
356
  }
350
- } else if (process.env.NODE_ENV !== 'production') {
357
+ } else if (__DEV__) {
351
358
  warn(
352
359
  `Invalid value for option "inject": expected an Array or an Object, ` +
353
- `but got ${toRawType(inject)}.`,
360
+ `but got ${toRawType(inject)}.`,
354
361
  vm
355
362
  )
356
363
  }
@@ -359,23 +366,23 @@ function normalizeInject (options: Object, vm: ?Component) {
359
366
  /**
360
367
  * Normalize raw function directives into object format.
361
368
  */
362
- function normalizeDirectives (options: Object) {
369
+ function normalizeDirectives(options: Record<string, any>) {
363
370
  const dirs = options.directives
364
371
  if (dirs) {
365
372
  for (const key in dirs) {
366
373
  const def = dirs[key]
367
- if (typeof def === 'function') {
374
+ if (isFunction(def)) {
368
375
  dirs[key] = { bind: def, update: def }
369
376
  }
370
377
  }
371
378
  }
372
379
  }
373
380
 
374
- function assertObjectType (name: string, value: any, vm: ?Component) {
381
+ function assertObjectType(name: string, value: any, vm: Component | null) {
375
382
  if (!isPlainObject(value)) {
376
383
  warn(
377
384
  `Invalid value for option "${name}": expected an Object, ` +
378
- `but got ${toRawType(value)}.`,
385
+ `but got ${toRawType(value)}.`,
379
386
  vm
380
387
  )
381
388
  }
@@ -385,16 +392,17 @@ function assertObjectType (name: string, value: any, vm: ?Component) {
385
392
  * Merge two option objects into a new one.
386
393
  * Core utility used in both instantiation and inheritance.
387
394
  */
388
- export function mergeOptions (
389
- parent: Object,
390
- child: Object,
391
- vm?: Component
392
- ): Object {
393
- if (process.env.NODE_ENV !== 'production') {
395
+ export function mergeOptions(
396
+ parent: Record<string, any>,
397
+ child: Record<string, any>,
398
+ vm?: Component | null
399
+ ): ComponentOptions {
400
+ if (__DEV__) {
394
401
  checkComponents(child)
395
402
  }
396
403
 
397
- if (typeof child === 'function') {
404
+ if (isFunction(child)) {
405
+ // @ts-expect-error
398
406
  child = child.options
399
407
  }
400
408
 
@@ -417,7 +425,7 @@ export function mergeOptions (
417
425
  }
418
426
  }
419
427
 
420
- const options = {}
428
+ const options: ComponentOptions = {} as any
421
429
  let key
422
430
  for (key in parent) {
423
431
  mergeField(key)
@@ -427,7 +435,7 @@ export function mergeOptions (
427
435
  mergeField(key)
428
436
  }
429
437
  }
430
- function mergeField (key) {
438
+ function mergeField(key: any) {
431
439
  const strat = strats[key] || defaultStrat
432
440
  options[key] = strat(parent[key], child[key], vm, key)
433
441
  }
@@ -439,8 +447,8 @@ export function mergeOptions (
439
447
  * This function is used because child instances need access
440
448
  * to assets defined in its ancestor chain.
441
449
  */
442
- export function resolveAsset (
443
- options: Object,
450
+ export function resolveAsset(
451
+ options: Record<string, any>,
444
452
  type: string,
445
453
  id: string,
446
454
  warnMissing?: boolean
@@ -458,11 +466,8 @@ export function resolveAsset (
458
466
  if (hasOwn(assets, PascalCaseId)) return assets[PascalCaseId]
459
467
  // fallback to prototype chain
460
468
  const res = assets[id] || assets[camelizedId] || assets[PascalCaseId]
461
- if (process.env.NODE_ENV !== 'production' && warnMissing && !res) {
462
- warn(
463
- 'Failed to resolve ' + type.slice(0, -1) + ': ' + id,
464
- options
465
- )
469
+ if (__DEV__ && warnMissing && !res) {
470
+ warn('Failed to resolve ' + type.slice(0, -1) + ': ' + id, options)
466
471
  }
467
472
  return res
468
473
  }
@@ -3,14 +3,18 @@ import { inBrowser } from './env'
3
3
  export let mark
4
4
  export let measure
5
5
 
6
- if (process.env.NODE_ENV !== 'production') {
6
+ if (__DEV__) {
7
7
  const perf = inBrowser && window.performance
8
8
  /* istanbul ignore if */
9
9
  if (
10
10
  perf &&
11
+ // @ts-ignore
11
12
  perf.mark &&
13
+ // @ts-ignore
12
14
  perf.measure &&
15
+ // @ts-ignore
13
16
  perf.clearMarks &&
17
+ // @ts-ignore
14
18
  perf.clearMeasures
15
19
  ) {
16
20
  mark = tag => perf.mark(tag)