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 {
4
2
  warn,
5
3
  remove,
@@ -8,53 +6,76 @@ import {
8
6
  _Set as Set,
9
7
  handleError,
10
8
  invokeWithErrorHandling,
11
- noop
9
+ noop,
10
+ isFunction
12
11
  } from '../util/index'
13
12
 
14
13
  import { traverse } from './traverse'
15
14
  import { queueWatcher } from './scheduler'
16
- import Dep, { pushTarget, popTarget } from './dep'
15
+ import Dep, { pushTarget, popTarget, DepTarget } from './dep'
16
+ import { DebuggerEvent, DebuggerOptions } from 'v3/debug'
17
17
 
18
18
  import type { SimpleSet } from '../util/index'
19
+ import type { Component } from 'types/component'
20
+ import { activeEffectScope, recordEffectScope } from 'v3/reactivity/effectScope'
19
21
 
20
22
  let uid = 0
21
23
 
24
+ /**
25
+ * @internal
26
+ */
27
+ export interface WatcherOptions extends DebuggerOptions {
28
+ deep?: boolean
29
+ user?: boolean
30
+ lazy?: boolean
31
+ sync?: boolean
32
+ before?: Function
33
+ }
34
+
22
35
  /**
23
36
  * A watcher parses an expression, collects dependencies,
24
37
  * and fires callback when the expression value changes.
25
38
  * This is used for both the $watch() api and directives.
39
+ * @internal
26
40
  */
27
- export default class Watcher {
28
- vm: Component;
29
- expression: string;
30
- cb: Function;
31
- id: number;
32
- deep: boolean;
33
- user: boolean;
34
- lazy: boolean;
35
- sync: boolean;
36
- dirty: boolean;
37
- active: boolean;
38
- deps: Array<Dep>;
39
- newDeps: Array<Dep>;
40
- depIds: SimpleSet;
41
- newDepIds: SimpleSet;
42
- before: ?Function;
43
- getter: Function;
44
- value: any;
41
+ export default class Watcher implements DepTarget {
42
+ vm?: Component | null
43
+ expression: string
44
+ cb: Function
45
+ id: number
46
+ deep: boolean
47
+ user: boolean
48
+ lazy: boolean
49
+ sync: boolean
50
+ dirty: boolean
51
+ active: boolean
52
+ deps: Array<Dep>
53
+ newDeps: Array<Dep>
54
+ depIds: SimpleSet
55
+ newDepIds: SimpleSet
56
+ before?: Function
57
+ onStop?: Function
58
+ noRecurse?: boolean
59
+ getter: Function
60
+ value: any
61
+
62
+ // dev only
63
+ onTrack?: ((event: DebuggerEvent) => void) | undefined
64
+ onTrigger?: ((event: DebuggerEvent) => void) | undefined
45
65
 
46
- constructor (
47
- vm: Component,
48
- expOrFn: string | Function,
66
+ constructor(
67
+ vm: Component | null,
68
+ expOrFn: string | (() => any),
49
69
  cb: Function,
50
- options?: ?Object,
70
+ options?: WatcherOptions | null,
51
71
  isRenderWatcher?: boolean
52
72
  ) {
53
- this.vm = vm
54
- if (isRenderWatcher) {
55
- vm._watcher = this
73
+ recordEffectScope(this, activeEffectScope || (vm ? vm._scope : undefined))
74
+ if ((this.vm = vm)) {
75
+ if (isRenderWatcher) {
76
+ vm._watcher = this
77
+ }
56
78
  }
57
- vm._watchers.push(this)
58
79
  // options
59
80
  if (options) {
60
81
  this.deep = !!options.deep
@@ -62,6 +83,10 @@ export default class Watcher {
62
83
  this.lazy = !!options.lazy
63
84
  this.sync = !!options.sync
64
85
  this.before = options.before
86
+ if (__DEV__) {
87
+ this.onTrack = options.onTrack
88
+ this.onTrigger = options.onTrigger
89
+ }
65
90
  } else {
66
91
  this.deep = this.user = this.lazy = this.sync = false
67
92
  }
@@ -73,39 +98,36 @@ export default class Watcher {
73
98
  this.newDeps = []
74
99
  this.depIds = new Set()
75
100
  this.newDepIds = new Set()
76
- this.expression = process.env.NODE_ENV !== 'production'
77
- ? expOrFn.toString()
78
- : ''
101
+ this.expression = __DEV__ ? expOrFn.toString() : ''
79
102
  // parse expression for getter
80
- if (typeof expOrFn === 'function') {
103
+ if (isFunction(expOrFn)) {
81
104
  this.getter = expOrFn
82
105
  } else {
83
106
  this.getter = parsePath(expOrFn)
84
107
  if (!this.getter) {
85
108
  this.getter = noop
86
- process.env.NODE_ENV !== 'production' && warn(
87
- `Failed watching path: "${expOrFn}" ` +
88
- 'Watcher only accepts simple dot-delimited paths. ' +
89
- 'For full control, use a function instead.',
90
- vm
91
- )
109
+ __DEV__ &&
110
+ warn(
111
+ `Failed watching path: "${expOrFn}" ` +
112
+ 'Watcher only accepts simple dot-delimited paths. ' +
113
+ 'For full control, use a function instead.',
114
+ vm
115
+ )
92
116
  }
93
117
  }
94
- this.value = this.lazy
95
- ? undefined
96
- : this.get()
118
+ this.value = this.lazy ? undefined : this.get()
97
119
  }
98
120
 
99
121
  /**
100
122
  * Evaluate the getter, and re-collect dependencies.
101
123
  */
102
- get () {
124
+ get() {
103
125
  pushTarget(this)
104
126
  let value
105
127
  const vm = this.vm
106
128
  try {
107
129
  value = this.getter.call(vm, vm)
108
- } catch (e) {
130
+ } catch (e: any) {
109
131
  if (this.user) {
110
132
  handleError(e, vm, `getter for watcher "${this.expression}"`)
111
133
  } else {
@@ -126,7 +148,7 @@ export default class Watcher {
126
148
  /**
127
149
  * Add a dependency to this directive.
128
150
  */
129
- addDep (dep: Dep) {
151
+ addDep(dep: Dep) {
130
152
  const id = dep.id
131
153
  if (!this.newDepIds.has(id)) {
132
154
  this.newDepIds.add(id)
@@ -140,7 +162,7 @@ export default class Watcher {
140
162
  /**
141
163
  * Clean up for dependency collection.
142
164
  */
143
- cleanupDeps () {
165
+ cleanupDeps() {
144
166
  let i = this.deps.length
145
167
  while (i--) {
146
168
  const dep = this.deps[i]
@@ -148,7 +170,7 @@ export default class Watcher {
148
170
  dep.removeSub(this)
149
171
  }
150
172
  }
151
- let tmp = this.depIds
173
+ let tmp: any = this.depIds
152
174
  this.depIds = this.newDepIds
153
175
  this.newDepIds = tmp
154
176
  this.newDepIds.clear()
@@ -162,7 +184,7 @@ export default class Watcher {
162
184
  * Subscriber interface.
163
185
  * Will be called when a dependency changes.
164
186
  */
165
- update () {
187
+ update() {
166
188
  /* istanbul ignore else */
167
189
  if (this.lazy) {
168
190
  this.dirty = true
@@ -177,7 +199,7 @@ export default class Watcher {
177
199
  * Scheduler job interface.
178
200
  * Will be called by the scheduler.
179
201
  */
180
- run () {
202
+ run() {
181
203
  if (this.active) {
182
204
  const value = this.get()
183
205
  if (
@@ -193,7 +215,13 @@ export default class Watcher {
193
215
  this.value = value
194
216
  if (this.user) {
195
217
  const info = `callback for watcher "${this.expression}"`
196
- invokeWithErrorHandling(this.cb, this.vm, [value, oldValue], this.vm, info)
218
+ invokeWithErrorHandling(
219
+ this.cb,
220
+ this.vm,
221
+ [value, oldValue],
222
+ this.vm,
223
+ info
224
+ )
197
225
  } else {
198
226
  this.cb.call(this.vm, value, oldValue)
199
227
  }
@@ -205,7 +233,7 @@ export default class Watcher {
205
233
  * Evaluate the value of the watcher.
206
234
  * This only gets called for lazy watchers.
207
235
  */
208
- evaluate () {
236
+ evaluate() {
209
237
  this.value = this.get()
210
238
  this.dirty = false
211
239
  }
@@ -213,7 +241,7 @@ export default class Watcher {
213
241
  /**
214
242
  * Depend on all deps collected by this watcher.
215
243
  */
216
- depend () {
244
+ depend() {
217
245
  let i = this.deps.length
218
246
  while (i--) {
219
247
  this.deps[i].depend()
@@ -223,19 +251,19 @@ export default class Watcher {
223
251
  /**
224
252
  * Remove self from all dependencies' subscriber list.
225
253
  */
226
- teardown () {
254
+ teardown() {
255
+ if (this.vm && !this.vm._isBeingDestroyed) {
256
+ remove(this.vm._scope.effects, this)
257
+ }
227
258
  if (this.active) {
228
- // remove self from vm's watcher list
229
- // this is a somewhat expensive operation so we skip it
230
- // if the vm is being destroyed.
231
- if (!this.vm._isBeingDestroyed) {
232
- remove(this.vm._watchers, this)
233
- }
234
259
  let i = this.deps.length
235
260
  while (i--) {
236
261
  this.deps[i].removeSub(this)
237
262
  }
238
263
  this.active = false
264
+ if (this.onStop) {
265
+ this.onStop()
266
+ }
239
267
  }
240
268
  }
241
269
  }
@@ -1,35 +1,32 @@
1
- /* @flow */
2
-
3
1
  import config from '../config'
4
- import { noop } from 'shared/util'
2
+ import { noop, isArray, isFunction } from 'shared/util'
3
+ import type { Component } from 'types/component'
4
+ import { currentInstance } from 'v3/currentInstance'
5
5
 
6
6
  export let warn = noop
7
7
  export let tip = noop
8
- export let generateComponentTrace = (noop: any) // work around flow check
9
- export let formatComponentName = (noop: any)
8
+ export let generateComponentTrace: (vm: Component) => string // work around flow check
9
+ export let formatComponentName: (vm: Component, includeFile?: false) => string
10
10
 
11
- if (process.env.NODE_ENV !== 'production') {
11
+ if (__DEV__) {
12
12
  const hasConsole = typeof console !== 'undefined'
13
13
  const classifyRE = /(?:^|[-_])(\w)/g
14
- const classify = str => str
15
- .replace(classifyRE, c => c.toUpperCase())
16
- .replace(/[-_]/g, '')
14
+ const classify = str =>
15
+ str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, '')
17
16
 
18
- warn = (msg, vm) => {
17
+ warn = (msg, vm = currentInstance) => {
19
18
  const trace = vm ? generateComponentTrace(vm) : ''
20
19
 
21
20
  if (config.warnHandler) {
22
21
  config.warnHandler.call(null, msg, vm, trace)
23
- } else if (hasConsole && (!config.silent)) {
22
+ } else if (hasConsole && !config.silent) {
24
23
  console.error(`[Vue warn]: ${msg}${trace}`)
25
24
  }
26
25
  }
27
26
 
28
27
  tip = (msg, vm) => {
29
- if (hasConsole && (!config.silent)) {
30
- console.warn(`[Vue tip]: ${msg}` + (
31
- vm ? generateComponentTrace(vm) : ''
32
- ))
28
+ if (hasConsole && !config.silent) {
29
+ console.warn(`[Vue tip]: ${msg}` + (vm ? generateComponentTrace(vm) : ''))
33
30
  }
34
31
  }
35
32
 
@@ -37,10 +34,11 @@ if (process.env.NODE_ENV !== 'production') {
37
34
  if (vm.$root === vm) {
38
35
  return '<Root>'
39
36
  }
40
- const options = typeof vm === 'function' && vm.cid != null
41
- ? vm.options
42
- : vm._isVue
43
- ? vm.$options || vm.constructor.options
37
+ const options =
38
+ isFunction(vm) && (vm as any).cid != null
39
+ ? (vm as any).options
40
+ : vm._isVue
41
+ ? vm.$options || (vm.constructor as any).options
44
42
  : vm
45
43
  let name = options.name || options._componentTag
46
44
  const file = options.__file
@@ -65,16 +63,16 @@ if (process.env.NODE_ENV !== 'production') {
65
63
  return res
66
64
  }
67
65
 
68
- generateComponentTrace = vm => {
69
- if (vm._isVue && vm.$parent) {
70
- const tree = []
66
+ generateComponentTrace = (vm: Component | undefined) => {
67
+ if ((vm as any)._isVue && vm!.$parent) {
68
+ const tree: any[] = []
71
69
  let currentRecursiveSequence = 0
72
70
  while (vm) {
73
71
  if (tree.length > 0) {
74
72
  const last = tree[tree.length - 1]
75
73
  if (last.constructor === vm.constructor) {
76
74
  currentRecursiveSequence++
77
- vm = vm.$parent
75
+ vm = vm.$parent!
78
76
  continue
79
77
  } else if (currentRecursiveSequence > 0) {
80
78
  tree[tree.length - 1] = [last, currentRecursiveSequence]
@@ -82,19 +80,25 @@ if (process.env.NODE_ENV !== 'production') {
82
80
  }
83
81
  }
84
82
  tree.push(vm)
85
- vm = vm.$parent
83
+ vm = vm.$parent!
86
84
  }
87
- return '\n\nfound in\n\n' + tree
88
- .map((vm, i) => `${
89
- i === 0 ? '---> ' : repeat(' ', 5 + i * 2)
90
- }${
91
- Array.isArray(vm)
92
- ? `${formatComponentName(vm[0])}... (${vm[1]} recursive calls)`
93
- : formatComponentName(vm)
94
- }`)
95
- .join('\n')
85
+ return (
86
+ '\n\nfound in\n\n' +
87
+ tree
88
+ .map(
89
+ (vm, i) =>
90
+ `${i === 0 ? '---> ' : repeat(' ', 5 + i * 2)}${
91
+ isArray(vm)
92
+ ? `${formatComponentName(vm[0])}... (${
93
+ vm[1]
94
+ } recursive calls)`
95
+ : formatComponentName(vm)
96
+ }`
97
+ )
98
+ .join('\n')
99
+ )
96
100
  } else {
97
- return `\n\n(found in ${formatComponentName(vm)})`
101
+ return `\n\n(found in ${formatComponentName(vm!)})`
98
102
  }
99
103
  }
100
104
  }
@@ -1,37 +1,34 @@
1
- /* @flow */
2
-
3
1
  // can we use __proto__?
4
2
  export const hasProto = '__proto__' in {}
5
3
 
6
4
  // Browser environment sniffing
7
5
  export const inBrowser = typeof window !== 'undefined'
8
- export const inWeex = typeof WXEnvironment !== 'undefined' && !!WXEnvironment.platform
9
- export const weexPlatform = inWeex && WXEnvironment.platform.toLowerCase()
10
6
  export const UA = inBrowser && window.navigator.userAgent.toLowerCase()
11
7
  export const isIE = UA && /msie|trident/.test(UA)
12
8
  export const isIE9 = UA && UA.indexOf('msie 9.0') > 0
13
9
  export const isEdge = UA && UA.indexOf('edge/') > 0
14
- export const isAndroid = (UA && UA.indexOf('android') > 0) || (weexPlatform === 'android')
15
- export const isIOS = (UA && /iphone|ipad|ipod|ios/.test(UA)) || (weexPlatform === 'ios')
10
+ export const isAndroid = UA && UA.indexOf('android') > 0
11
+ export const isIOS = UA && /iphone|ipad|ipod|ios/.test(UA)
16
12
  export const isChrome = UA && /chrome\/\d+/.test(UA) && !isEdge
17
13
  export const isPhantomJS = UA && /phantomjs/.test(UA)
18
14
  export const isFF = UA && UA.match(/firefox\/(\d+)/)
19
15
 
20
16
  // Firefox has a "watch" function on Object.prototype...
21
- export const nativeWatch = ({}).watch
17
+ // @ts-expect-error firebox support
18
+ export const nativeWatch = {}.watch
22
19
 
23
20
  export let supportsPassive = false
24
21
  if (inBrowser) {
25
22
  try {
26
23
  const opts = {}
27
- Object.defineProperty(opts, 'passive', ({
28
- get () {
24
+ Object.defineProperty(opts, 'passive', {
25
+ get() {
29
26
  /* istanbul ignore next */
30
27
  supportsPassive = true
31
28
  }
32
- }: Object)) // https://github.com/facebook/flow/issues/285
33
- window.addEventListener('test-passive', null, opts)
34
- } catch (e) {}
29
+ } as object) // https://github.com/facebook/flow/issues/285
30
+ window.addEventListener('test-passive', null as any, opts)
31
+ } catch (e: any) {}
35
32
  }
36
33
 
37
34
  // this needs to be lazy-evaled because vue may be required before
@@ -40,10 +37,11 @@ let _isServer
40
37
  export const isServerRendering = () => {
41
38
  if (_isServer === undefined) {
42
39
  /* istanbul ignore if */
43
- if (!inBrowser && !inWeex && typeof global !== 'undefined') {
40
+ if (!inBrowser && typeof global !== 'undefined') {
44
41
  // detect presence of vue-server-renderer and avoid
45
42
  // Webpack shimming the process
46
- _isServer = global['process'] && global['process'].env.VUE_ENV === 'server'
43
+ _isServer =
44
+ global['process'] && global['process'].env.VUE_ENV === 'server'
47
45
  } else {
48
46
  _isServer = false
49
47
  }
@@ -55,42 +53,41 @@ export const isServerRendering = () => {
55
53
  export const devtools = inBrowser && window.__VUE_DEVTOOLS_GLOBAL_HOOK__
56
54
 
57
55
  /* istanbul ignore next */
58
- export function isNative (Ctor: any): boolean {
56
+ export function isNative(Ctor: any): boolean {
59
57
  return typeof Ctor === 'function' && /native code/.test(Ctor.toString())
60
58
  }
61
59
 
62
60
  export const hasSymbol =
63
- typeof Symbol !== 'undefined' && isNative(Symbol) &&
64
- typeof Reflect !== 'undefined' && isNative(Reflect.ownKeys)
61
+ typeof Symbol !== 'undefined' &&
62
+ isNative(Symbol) &&
63
+ typeof Reflect !== 'undefined' &&
64
+ isNative(Reflect.ownKeys)
65
65
 
66
- let _Set
67
- /* istanbul ignore if */ // $flow-disable-line
68
- if (typeof Set !== 'undefined' && isNative(Set)) {
66
+ let _Set // $flow-disable-line
67
+ /* istanbul ignore if */ if (typeof Set !== 'undefined' && isNative(Set)) {
69
68
  // use native Set when available.
70
69
  _Set = Set
71
70
  } else {
72
71
  // a non-standard Set polyfill that only works with primitive keys.
73
72
  _Set = class Set implements SimpleSet {
74
- set: Object;
75
- constructor () {
76
- this.set = Object.create(null)
77
- }
78
- has (key: string | number) {
73
+ set: Record<string, boolean> = Object.create(null)
74
+
75
+ has(key: string | number) {
79
76
  return this.set[key] === true
80
77
  }
81
- add (key: string | number) {
78
+ add(key: string | number) {
82
79
  this.set[key] = true
83
80
  }
84
- clear () {
81
+ clear() {
85
82
  this.set = Object.create(null)
86
83
  }
87
84
  }
88
85
  }
89
86
 
90
87
  export interface SimpleSet {
91
- has(key: string | number): boolean;
92
- add(key: string | number): mixed;
93
- clear(): void;
88
+ has(key: string | number): boolean
89
+ add(key: string | number): any
90
+ clear(): void
94
91
  }
95
92
 
96
93
  export { _Set }
@@ -1,12 +1,10 @@
1
- /* @flow */
2
-
3
1
  import config from '../config'
4
2
  import { warn } from './debug'
5
- import { inBrowser, inWeex } from './env'
3
+ import { inBrowser } from './env'
6
4
  import { isPromise } from 'shared/util'
7
5
  import { pushTarget, popTarget } from '../observer/dep'
8
6
 
9
- export function handleError (err: Error, vm: any, info: string) {
7
+ export function handleError(err: Error, vm: any, info: string) {
10
8
  // Deactivate deps tracking while processing error handler to avoid possible infinite rendering.
11
9
  // See: https://github.com/vuejs/vuex/issues/1505
12
10
  pushTarget()
@@ -20,7 +18,7 @@ export function handleError (err: Error, vm: any, info: string) {
20
18
  try {
21
19
  const capture = hooks[i].call(cur, err, vm, info) === false
22
20
  if (capture) return
23
- } catch (e) {
21
+ } catch (e: any) {
24
22
  globalHandleError(e, cur, 'errorCaptured hook')
25
23
  }
26
24
  }
@@ -33,7 +31,7 @@ export function handleError (err: Error, vm: any, info: string) {
33
31
  }
34
32
  }
35
33
 
36
- export function invokeWithErrorHandling (
34
+ export function invokeWithErrorHandling(
37
35
  handler: Function,
38
36
  context: any,
39
37
  args: null | any[],
@@ -43,23 +41,23 @@ export function invokeWithErrorHandling (
43
41
  let res
44
42
  try {
45
43
  res = args ? handler.apply(context, args) : handler.call(context)
46
- if (res && !res._isVue && isPromise(res) && !res._handled) {
44
+ if (res && !res._isVue && isPromise(res) && !(res as any)._handled) {
47
45
  res.catch(e => handleError(e, vm, info + ` (Promise/async)`))
48
46
  // issue #9511
49
47
  // avoid catch triggering multiple times when nested calls
50
- res._handled = true
48
+ ;(res as any)._handled = true
51
49
  }
52
- } catch (e) {
50
+ } catch (e: any) {
53
51
  handleError(e, vm, info)
54
52
  }
55
53
  return res
56
54
  }
57
55
 
58
- function globalHandleError (err, vm, info) {
56
+ function globalHandleError(err, vm, info) {
59
57
  if (config.errorHandler) {
60
58
  try {
61
59
  return config.errorHandler.call(null, err, vm, info)
62
- } catch (e) {
60
+ } catch (e: any) {
63
61
  // if the user intentionally throws the original error in the handler,
64
62
  // do not log it twice
65
63
  if (e !== err) {
@@ -70,12 +68,12 @@ function globalHandleError (err, vm, info) {
70
68
  logError(err, vm, info)
71
69
  }
72
70
 
73
- function logError (err, vm, info) {
74
- if (process.env.NODE_ENV !== 'production') {
71
+ function logError(err, vm, info) {
72
+ if (__DEV__) {
75
73
  warn(`Error in ${info}: "${err.toString()}"`, vm)
76
74
  }
77
75
  /* istanbul ignore else */
78
- if ((inBrowser || inWeex) && typeof console !== 'undefined') {
76
+ if (inBrowser && typeof console !== 'undefined') {
79
77
  console.error(err)
80
78
  } else {
81
79
  throw err
@@ -1,5 +1,3 @@
1
- /* @flow */
2
-
3
1
  export * from 'shared/util'
4
2
  export * from './lang'
5
3
  export * from './env'
@@ -1,24 +1,23 @@
1
- /* @flow */
2
-
3
1
  /**
4
2
  * unicode letters used for parsing html tags, component names and property paths.
5
3
  * using https://www.w3.org/TR/html53/semantics-scripting.html#potentialcustomelementname
6
4
  * skipping \u10000-\uEFFFF due to it freezing up PhantomJS
7
5
  */
8
- export const unicodeRegExp = /a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD/
6
+ export const unicodeRegExp =
7
+ /a-zA-Z\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD/
9
8
 
10
9
  /**
11
10
  * Check if a string starts with $ or _
12
11
  */
13
- export function isReserved (str: string): boolean {
12
+ export function isReserved(str: string): boolean {
14
13
  const c = (str + '').charCodeAt(0)
15
- return c === 0x24 || c === 0x5F
14
+ return c === 0x24 || c === 0x5f
16
15
  }
17
16
 
18
17
  /**
19
18
  * Define a property.
20
19
  */
21
- export function def (obj: Object, key: string, val: any, enumerable?: boolean) {
20
+ export function def(obj: Object, key: string, val: any, enumerable?: boolean) {
22
21
  Object.defineProperty(obj, key, {
23
22
  value: val,
24
23
  enumerable: !!enumerable,
@@ -31,7 +30,7 @@ export function def (obj: Object, key: string, val: any, enumerable?: boolean) {
31
30
  * Parse simple path.
32
31
  */
33
32
  const bailRE = new RegExp(`[^${unicodeRegExp.source}.$_\\d]`)
34
- export function parsePath (path: string): any {
33
+ export function parsePath(path: string): any {
35
34
  if (bailRE.test(path)) {
36
35
  return
37
36
  }