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 { cached } from 'shared/util'
4
2
  import { parseFilters } from './filter-parser'
5
3
 
@@ -13,27 +11,28 @@ const buildRegex = cached(delimiters => {
13
11
  })
14
12
 
15
13
  type TextParseResult = {
16
- expression: string,
14
+ expression: string
17
15
  tokens: Array<string | { '@binding': string }>
18
16
  }
19
17
 
20
- export function parseText (
18
+ export function parseText(
21
19
  text: string,
22
20
  delimiters?: [string, string]
23
21
  ): TextParseResult | void {
22
+ //@ts-expect-error
24
23
  const tagRE = delimiters ? buildRegex(delimiters) : defaultTagRE
25
24
  if (!tagRE.test(text)) {
26
25
  return
27
26
  }
28
- const tokens = []
29
- const rawTokens = []
30
- let lastIndex = tagRE.lastIndex = 0
27
+ const tokens: string[] = []
28
+ const rawTokens: any[] = []
29
+ let lastIndex = (tagRE.lastIndex = 0)
31
30
  let match, index, tokenValue
32
31
  while ((match = tagRE.exec(text))) {
33
32
  index = match.index
34
33
  // push text token
35
34
  if (index > lastIndex) {
36
- rawTokens.push(tokenValue = text.slice(lastIndex, index))
35
+ rawTokens.push((tokenValue = text.slice(lastIndex, index)))
37
36
  tokens.push(JSON.stringify(tokenValue))
38
37
  }
39
38
  // tag token
@@ -43,7 +42,7 @@ export function parseText (
43
42
  lastIndex = index + match[0].length
44
43
  }
45
44
  if (lastIndex < text.length) {
46
- rawTokens.push(tokenValue = text.slice(lastIndex))
45
+ rawTokens.push((tokenValue = text.slice(lastIndex)))
47
46
  tokens.push(JSON.stringify(tokenValue))
48
47
  }
49
48
  return {
@@ -1,27 +1,27 @@
1
- /* @flow */
2
-
3
1
  import { noop, extend } from 'shared/util'
4
2
  import { warn as baseWarn, tip } from 'core/util/debug'
5
3
  import { generateCodeFrame } from './codeframe'
4
+ import type { Component } from 'types/component'
5
+ import { CompilerOptions } from 'types/compiler'
6
6
 
7
7
  type CompiledFunctionResult = {
8
- render: Function;
9
- staticRenderFns: Array<Function>;
10
- };
8
+ render: Function
9
+ staticRenderFns: Array<Function>
10
+ }
11
11
 
12
- function createFunction (code, errors) {
12
+ function createFunction(code, errors) {
13
13
  try {
14
14
  return new Function(code)
15
- } catch (err) {
15
+ } catch (err: any) {
16
16
  errors.push({ err, code })
17
17
  return noop
18
18
  }
19
19
  }
20
20
 
21
- export function createCompileToFunctionFn (compile: Function): Function {
21
+ export function createCompileToFunctionFn(compile: Function): Function {
22
22
  const cache = Object.create(null)
23
23
 
24
- return function compileToFunctions (
24
+ return function compileToFunctions(
25
25
  template: string,
26
26
  options?: CompilerOptions,
27
27
  vm?: Component
@@ -31,18 +31,18 @@ export function createCompileToFunctionFn (compile: Function): Function {
31
31
  delete options.warn
32
32
 
33
33
  /* istanbul ignore if */
34
- if (process.env.NODE_ENV !== 'production') {
34
+ if (__DEV__) {
35
35
  // detect possible CSP restriction
36
36
  try {
37
37
  new Function('return 1')
38
- } catch (e) {
38
+ } catch (e: any) {
39
39
  if (e.toString().match(/unsafe-eval|CSP/)) {
40
40
  warn(
41
41
  'It seems you are using the standalone build of Vue.js in an ' +
42
- 'environment with Content Security Policy that prohibits unsafe-eval. ' +
43
- 'The template compiler cannot work in this environment. Consider ' +
44
- 'relaxing the policy to allow unsafe-eval or pre-compiling your ' +
45
- 'templates into render functions.'
42
+ 'environment with Content Security Policy that prohibits unsafe-eval. ' +
43
+ 'The template compiler cannot work in this environment. Consider ' +
44
+ 'relaxing the policy to allow unsafe-eval or pre-compiling your ' +
45
+ 'templates into render functions.'
46
46
  )
47
47
  }
48
48
  }
@@ -60,20 +60,21 @@ export function createCompileToFunctionFn (compile: Function): Function {
60
60
  const compiled = compile(template, options)
61
61
 
62
62
  // check compilation errors/tips
63
- if (process.env.NODE_ENV !== 'production') {
63
+ if (__DEV__) {
64
64
  if (compiled.errors && compiled.errors.length) {
65
65
  if (options.outputSourceRange) {
66
66
  compiled.errors.forEach(e => {
67
67
  warn(
68
68
  `Error compiling template:\n\n${e.msg}\n\n` +
69
- generateCodeFrame(template, e.start, e.end),
69
+ generateCodeFrame(template, e.start, e.end),
70
70
  vm
71
71
  )
72
72
  })
73
73
  } else {
74
74
  warn(
75
75
  `Error compiling template:\n\n${template}\n\n` +
76
- compiled.errors.map(e => `- ${e}`).join('\n') + '\n',
76
+ compiled.errors.map(e => `- ${e}`).join('\n') +
77
+ '\n',
77
78
  vm
78
79
  )
79
80
  }
@@ -88,8 +89,8 @@ export function createCompileToFunctionFn (compile: Function): Function {
88
89
  }
89
90
 
90
91
  // turn code into functions
91
- const res = {}
92
- const fnGenErrors = []
92
+ const res: any = {}
93
+ const fnGenErrors: any[] = []
93
94
  res.render = createFunction(compiled.render, fnGenErrors)
94
95
  res.staticRenderFns = compiled.staticRenderFns.map(code => {
95
96
  return createFunction(code, fnGenErrors)
@@ -99,11 +100,15 @@ export function createCompileToFunctionFn (compile: Function): Function {
99
100
  // this should only happen if there is a bug in the compiler itself.
100
101
  // mostly for codegen development use
101
102
  /* istanbul ignore if */
102
- if (process.env.NODE_ENV !== 'production') {
103
+ if (__DEV__) {
103
104
  if ((!compiled.errors || !compiled.errors.length) && fnGenErrors.length) {
104
105
  warn(
105
106
  `Failed to generate render function:\n\n` +
106
- fnGenErrors.map(({ err, code }) => `${err.toString()} in\n\n${code}\n`).join('\n'),
107
+ fnGenErrors
108
+ .map(
109
+ ({ err, code }) => `${(err as any).toString()} in\n\n${code}\n`
110
+ )
111
+ .join('\n'),
107
112
  vm
108
113
  )
109
114
  }
File without changes
@@ -1,22 +1,26 @@
1
- /* @flow */
2
-
3
- import { isRegExp, remove } from 'shared/util'
1
+ import { isRegExp, isArray, remove } from 'shared/util'
4
2
  import { getFirstComponentChild } from 'core/vdom/helpers/index'
3
+ import type VNode from 'core/vdom/vnode'
4
+ import type { VNodeComponentOptions } from 'types/vnode'
5
+ import type { Component } from 'types/component'
5
6
 
6
7
  type CacheEntry = {
7
- name: ?string;
8
- tag: ?string;
9
- componentInstance: Component;
10
- };
8
+ name?: string
9
+ tag?: string
10
+ componentInstance?: Component
11
+ }
11
12
 
12
- type CacheEntryMap = { [key: string]: ?CacheEntry };
13
+ type CacheEntryMap = Record<string, CacheEntry | null>
13
14
 
14
- function getComponentName (opts: ?VNodeComponentOptions): ?string {
15
+ function getComponentName(opts?: VNodeComponentOptions): string | null {
15
16
  return opts && (opts.Ctor.options.name || opts.tag)
16
17
  }
17
18
 
18
- function matches (pattern: string | RegExp | Array<string>, name: string): boolean {
19
- if (Array.isArray(pattern)) {
19
+ function matches(
20
+ pattern: string | RegExp | Array<string>,
21
+ name: string
22
+ ): boolean {
23
+ if (isArray(pattern)) {
20
24
  return pattern.indexOf(name) > -1
21
25
  } else if (typeof pattern === 'string') {
22
26
  return pattern.split(',').indexOf(name) > -1
@@ -27,12 +31,15 @@ function matches (pattern: string | RegExp | Array<string>, name: string): boole
27
31
  return false
28
32
  }
29
33
 
30
- function pruneCache (keepAliveInstance: any, filter: Function) {
34
+ function pruneCache(
35
+ keepAliveInstance: { cache: CacheEntryMap; keys: string[]; _vnode: VNode },
36
+ filter: Function
37
+ ) {
31
38
  const { cache, keys, _vnode } = keepAliveInstance
32
39
  for (const key in cache) {
33
- const entry: ?CacheEntry = cache[key]
40
+ const entry = cache[key]
34
41
  if (entry) {
35
- const name: ?string = entry.name
42
+ const name = entry.name
36
43
  if (name && !filter(name)) {
37
44
  pruneCacheEntry(cache, key, keys, _vnode)
38
45
  }
@@ -40,14 +47,15 @@ function pruneCache (keepAliveInstance: any, filter: Function) {
40
47
  }
41
48
  }
42
49
 
43
- function pruneCacheEntry (
50
+ function pruneCacheEntry(
44
51
  cache: CacheEntryMap,
45
52
  key: string,
46
53
  keys: Array<string>,
47
54
  current?: VNode
48
55
  ) {
49
- const entry: ?CacheEntry = cache[key]
56
+ const entry = cache[key]
50
57
  if (entry && (!current || entry.tag !== current.tag)) {
58
+ // @ts-expect-error can be undefined
51
59
  entry.componentInstance.$destroy()
52
60
  }
53
61
  cache[key] = null
@@ -56,6 +64,7 @@ function pruneCacheEntry (
56
64
 
57
65
  const patternTypes: Array<Function> = [String, RegExp, Array]
58
66
 
67
+ // TODO defineComponent
59
68
  export default {
60
69
  name: 'keep-alive',
61
70
  abstract: true,
@@ -74,7 +83,7 @@ export default {
74
83
  cache[keyToCache] = {
75
84
  name: getComponentName(componentOptions),
76
85
  tag,
77
- componentInstance,
86
+ componentInstance
78
87
  }
79
88
  keys.push(keyToCache)
80
89
  // prune oldest entry
@@ -86,18 +95,18 @@ export default {
86
95
  }
87
96
  },
88
97
 
89
- created () {
98
+ created() {
90
99
  this.cache = Object.create(null)
91
100
  this.keys = []
92
101
  },
93
102
 
94
- destroyed () {
103
+ destroyed() {
95
104
  for (const key in this.cache) {
96
105
  pruneCacheEntry(this.cache, key, this.keys)
97
106
  }
98
107
  },
99
108
 
100
- mounted () {
109
+ mounted() {
101
110
  this.cacheVNode()
102
111
  this.$watch('include', val => {
103
112
  pruneCache(this, name => matches(val, name))
@@ -107,17 +116,17 @@ export default {
107
116
  })
108
117
  },
109
118
 
110
- updated () {
119
+ updated() {
111
120
  this.cacheVNode()
112
121
  },
113
122
 
114
- render () {
123
+ render() {
115
124
  const slot = this.$slots.default
116
- const vnode: VNode = getFirstComponentChild(slot)
117
- const componentOptions: ?VNodeComponentOptions = vnode && vnode.componentOptions
125
+ const vnode = getFirstComponentChild(slot)
126
+ const componentOptions = vnode && vnode.componentOptions
118
127
  if (componentOptions) {
119
128
  // check pattern
120
- const name: ?string = getComponentName(componentOptions)
129
+ const name = getComponentName(componentOptions)
121
130
  const { include, exclude } = this
122
131
  if (
123
132
  // not included
@@ -129,11 +138,13 @@ export default {
129
138
  }
130
139
 
131
140
  const { cache, keys } = this
132
- const key: ?string = vnode.key == null
133
- // same constructor may get registered as different local components
134
- // so cid alone is not enough (#3269)
135
- ? componentOptions.Ctor.cid + (componentOptions.tag ? `::${componentOptions.tag}` : '')
136
- : vnode.key
141
+ const key =
142
+ vnode.key == null
143
+ ? // same constructor may get registered as different local components
144
+ // so cid alone is not enough (#3269)
145
+ componentOptions.Ctor.cid +
146
+ (componentOptions.tag ? `::${componentOptions.tag}` : '')
147
+ : vnode.key
137
148
  if (cache[key]) {
138
149
  vnode.componentInstance = cache[key].componentInstance
139
150
  // make current key freshest
@@ -145,6 +156,7 @@ export default {
145
156
  this.keyToCache = key
146
157
  }
147
158
 
159
+ // @ts-expect-error can vnode.data can be undefined
148
160
  vnode.data.keepAlive = true
149
161
  }
150
162
  return vnode || (slot && slot[0])
@@ -1,41 +1,39 @@
1
- /* @flow */
2
-
3
- import {
4
- no,
5
- noop,
6
- identity
7
- } from 'shared/util'
1
+ import { no, noop, identity } from 'shared/util'
8
2
 
9
3
  import { LIFECYCLE_HOOKS } from 'shared/constants'
4
+ import type { Component } from 'types/component'
10
5
 
11
- export type Config = {
6
+ /**
7
+ * @internal
8
+ */
9
+ export interface Config {
12
10
  // user
13
- optionMergeStrategies: { [key: string]: Function };
14
- silent: boolean;
15
- productionTip: boolean;
16
- performance: boolean;
17
- devtools: boolean;
18
- errorHandler: ?(err: Error, vm: Component, info: string) => void;
19
- warnHandler: ?(msg: string, vm: Component, trace: string) => void;
20
- ignoredElements: Array<string | RegExp>;
21
- keyCodes: { [key: string]: number | Array<number> };
11
+ optionMergeStrategies: { [key: string]: Function }
12
+ silent: boolean
13
+ productionTip: boolean
14
+ performance: boolean
15
+ devtools: boolean
16
+ errorHandler?: (err: Error, vm: Component, info: string) => void
17
+ warnHandler?: (msg: string, vm: Component, trace: string) => void
18
+ ignoredElements: Array<string | RegExp>
19
+ keyCodes: { [key: string]: number | Array<number> }
22
20
 
23
21
  // platform
24
- isReservedTag: (x?: string) => boolean;
25
- isReservedAttr: (x?: string) => boolean;
26
- parsePlatformTagName: (x: string) => string;
27
- isUnknownElement: (x?: string) => boolean;
28
- getTagNamespace: (x?: string) => string | void;
29
- mustUseProp: (tag: string, type: ?string, name: string) => boolean;
22
+ isReservedTag: (x: string) => boolean | undefined
23
+ isReservedAttr: (x: string) => true | undefined
24
+ parsePlatformTagName: (x: string) => string
25
+ isUnknownElement: (x: string) => boolean
26
+ getTagNamespace: (x: string) => string | undefined
27
+ mustUseProp: (tag: string, type?: string | null, name?: string) => boolean
30
28
 
31
29
  // private
32
- async: boolean;
30
+ async: boolean
33
31
 
34
32
  // legacy
35
- _lifecycleHooks: Array<string>;
36
- };
33
+ _lifecycleHooks: Array<string>
34
+ }
37
35
 
38
- export default ({
36
+ export default {
39
37
  /**
40
38
  * Option merge strategies (used in core/util/options)
41
39
  */
@@ -50,12 +48,12 @@ export default ({
50
48
  /**
51
49
  * Show production mode tip message on boot?
52
50
  */
53
- productionTip: process.env.NODE_ENV !== 'production',
51
+ productionTip: __DEV__,
54
52
 
55
53
  /**
56
54
  * Whether to enable devtools
57
55
  */
58
- devtools: process.env.NODE_ENV !== 'production',
56
+ devtools: __DEV__,
59
57
 
60
58
  /**
61
59
  * Whether to record perf
@@ -127,4 +125,4 @@ export default ({
127
125
  * Exposed for legacy reasons
128
126
  */
129
127
  _lifecycleHooks: LIFECYCLE_HOOKS
130
- }: Config)
128
+ } as unknown as Config
@@ -1,29 +1,30 @@
1
- /* @flow */
2
-
3
1
  import { ASSET_TYPES } from 'shared/constants'
4
- import { isPlainObject, validateComponentName } from '../util/index'
2
+ import type { GlobalAPI } from 'types/global-api'
3
+ import { isFunction, isPlainObject, validateComponentName } from '../util/index'
5
4
 
6
- export function initAssetRegisters (Vue: GlobalAPI) {
5
+ export function initAssetRegisters(Vue: GlobalAPI) {
7
6
  /**
8
7
  * Create asset registration methods.
9
8
  */
10
9
  ASSET_TYPES.forEach(type => {
10
+ // @ts-expect-error function is not exact same type
11
11
  Vue[type] = function (
12
12
  id: string,
13
- definition: Function | Object
13
+ definition?: Function | Object
14
14
  ): Function | Object | void {
15
15
  if (!definition) {
16
16
  return this.options[type + 's'][id]
17
17
  } else {
18
18
  /* istanbul ignore if */
19
- if (process.env.NODE_ENV !== 'production' && type === 'component') {
19
+ if (__DEV__ && type === 'component') {
20
20
  validateComponentName(id)
21
21
  }
22
22
  if (type === 'component' && isPlainObject(definition)) {
23
+ // @ts-expect-error
23
24
  definition.name = definition.name || id
24
25
  definition = this.options._base.extend(definition)
25
26
  }
26
- if (type === 'directive' && typeof definition === 'function') {
27
+ if (type === 'directive' && isFunction(definition)) {
27
28
  definition = { bind: definition, update: definition }
28
29
  }
29
30
  this.options[type + 's'][id] = definition
@@ -1,10 +1,10 @@
1
- /* @flow */
2
-
3
1
  import { ASSET_TYPES } from 'shared/constants'
2
+ import type { Component } from 'types/component'
3
+ import type { GlobalAPI } from 'types/global-api'
4
4
  import { defineComputed, proxy } from '../instance/state'
5
5
  import { extend, mergeOptions, validateComponentName } from '../util/index'
6
6
 
7
- export function initExtend (Vue: GlobalAPI) {
7
+ export function initExtend(Vue: GlobalAPI) {
8
8
  /**
9
9
  * Each instance constructor, including Vue, has a unique
10
10
  * cid. This enables us to create wrapped "child
@@ -16,7 +16,7 @@ export function initExtend (Vue: GlobalAPI) {
16
16
  /**
17
17
  * Class inheritance
18
18
  */
19
- Vue.extend = function (extendOptions: Object): Function {
19
+ Vue.extend = function (extendOptions: any): typeof Component {
20
20
  extendOptions = extendOptions || {}
21
21
  const Super = this
22
22
  const SuperId = Super.cid
@@ -26,20 +26,17 @@ export function initExtend (Vue: GlobalAPI) {
26
26
  }
27
27
 
28
28
  const name = extendOptions.name || Super.options.name
29
- if (process.env.NODE_ENV !== 'production' && name) {
29
+ if (__DEV__ && name) {
30
30
  validateComponentName(name)
31
31
  }
32
32
 
33
- const Sub = function VueComponent (options) {
33
+ const Sub = function VueComponent(this: any, options: any) {
34
34
  this._init(options)
35
- }
35
+ } as unknown as typeof Component
36
36
  Sub.prototype = Object.create(Super.prototype)
37
37
  Sub.prototype.constructor = Sub
38
38
  Sub.cid = cid++
39
- Sub.options = mergeOptions(
40
- Super.options,
41
- extendOptions
42
- )
39
+ Sub.options = mergeOptions(Super.options, extendOptions)
43
40
  Sub['super'] = Super
44
41
 
45
42
  // For props and computed properties, we define the proxy getters on
@@ -80,14 +77,14 @@ export function initExtend (Vue: GlobalAPI) {
80
77
  }
81
78
  }
82
79
 
83
- function initProps (Comp) {
80
+ function initProps(Comp: typeof Component) {
84
81
  const props = Comp.options.props
85
82
  for (const key in props) {
86
83
  proxy(Comp.prototype, `_props`, key)
87
84
  }
88
85
  }
89
86
 
90
- function initComputed (Comp) {
87
+ function initComputed(Comp: typeof Component) {
91
88
  const computed = Comp.options.computed
92
89
  for (const key in computed) {
93
90
  defineComputed(Comp.prototype, key, computed[key])
@@ -1,5 +1,3 @@
1
- /* @flow */
2
-
3
1
  import config from '../config'
4
2
  import { initUse } from './use'
5
3
  import { initMixin } from './mixin'
@@ -17,12 +15,13 @@ import {
17
15
  mergeOptions,
18
16
  defineReactive
19
17
  } from '../util/index'
18
+ import type { GlobalAPI } from 'types/global-api'
20
19
 
21
- export function initGlobalAPI (Vue: GlobalAPI) {
20
+ export function initGlobalAPI(Vue: GlobalAPI) {
22
21
  // config
23
- const configDef = {}
22
+ const configDef: Record<string, any> = {}
24
23
  configDef.get = () => config
25
- if (process.env.NODE_ENV !== 'production') {
24
+ if (__DEV__) {
26
25
  configDef.set = () => {
27
26
  warn(
28
27
  'Do not replace the Vue.config object, set individual fields instead.'
@@ -1,8 +1,7 @@
1
- /* @flow */
2
-
1
+ import type { GlobalAPI } from 'types/global-api'
3
2
  import { mergeOptions } from '../util/index'
4
3
 
5
- export function initMixin (Vue: GlobalAPI) {
4
+ export function initMixin(Vue: GlobalAPI) {
6
5
  Vue.mixin = function (mixin: Object) {
7
6
  this.options = mergeOptions(this.options, mixin)
8
7
  return this
@@ -0,0 +1,23 @@
1
+ import type { GlobalAPI } from 'types/global-api'
2
+ import { toArray, isFunction } from '../util/index'
3
+
4
+ export function initUse(Vue: GlobalAPI) {
5
+ Vue.use = function (plugin: Function | any) {
6
+ const installedPlugins =
7
+ this._installedPlugins || (this._installedPlugins = [])
8
+ if (installedPlugins.indexOf(plugin) > -1) {
9
+ return this
10
+ }
11
+
12
+ // additional parameters
13
+ const args = toArray(arguments, 1)
14
+ args.unshift(this)
15
+ if (isFunction(plugin.install)) {
16
+ plugin.install.apply(plugin, args)
17
+ } else if (isFunction(plugin)) {
18
+ plugin.apply(null, args)
19
+ }
20
+ installedPlugins.push(plugin)
21
+ return this
22
+ }
23
+ }
@@ -10,7 +10,7 @@ Object.defineProperty(Vue.prototype, '$isServer', {
10
10
  })
11
11
 
12
12
  Object.defineProperty(Vue.prototype, '$ssrContext', {
13
- get () {
13
+ get() {
14
14
  /* istanbul ignore next */
15
15
  return this.$vnode && this.$vnode.ssrContext
16
16
  }