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,13 +1,13 @@
1
- /* @flow */
1
+ import { ASTElement, ASTModifiers } from 'types/compiler'
2
2
 
3
3
  /**
4
4
  * Cross-platform code generation for component v-model
5
5
  */
6
- export function genComponentModel (
6
+ export function genComponentModel(
7
7
  el: ASTElement,
8
8
  value: string,
9
- modifiers: ?ASTModifiers
10
- ): ?boolean {
9
+ modifiers: ASTModifiers | null
10
+ ): void {
11
11
  const { number, trim } = modifiers || {}
12
12
 
13
13
  const baseValueExpression = '$$v'
@@ -33,10 +33,7 @@ export function genComponentModel (
33
33
  /**
34
34
  * Cross-platform codegen helper for generating v-model value assignment code.
35
35
  */
36
- export function genAssignmentCode (
37
- value: string,
38
- assignment: string
39
- ): string {
36
+ export function genAssignmentCode(value: string, assignment: string): string {
40
37
  const res = parseModel(value)
41
38
  if (res.key === null) {
42
39
  return `${value}=${assignment}`
@@ -63,11 +60,11 @@ export function genAssignmentCode (
63
60
  let len, str, chr, index, expressionPos, expressionEndPos
64
61
 
65
62
  type ModelParseResult = {
66
- exp: string,
63
+ exp: string
67
64
  key: string | null
68
65
  }
69
66
 
70
- export function parseModel (val: string): ModelParseResult {
67
+ export function parseModel(val: string): ModelParseResult {
71
68
  // Fix https://github.com/vuejs/vue/pull/7730
72
69
  // allow v-model="obj.val " (trailing whitespace)
73
70
  val = val.trim()
@@ -96,7 +93,7 @@ export function parseModel (val: string): ModelParseResult {
96
93
  /* istanbul ignore if */
97
94
  if (isStringStart(chr)) {
98
95
  parseString(chr)
99
- } else if (chr === 0x5B) {
96
+ } else if (chr === 0x5b) {
100
97
  parseBracket(chr)
101
98
  }
102
99
  }
@@ -107,19 +104,19 @@ export function parseModel (val: string): ModelParseResult {
107
104
  }
108
105
  }
109
106
 
110
- function next (): number {
107
+ function next(): number {
111
108
  return str.charCodeAt(++index)
112
109
  }
113
110
 
114
- function eof (): boolean {
111
+ function eof(): boolean {
115
112
  return index >= len
116
113
  }
117
114
 
118
- function isStringStart (chr: number): boolean {
115
+ function isStringStart(chr: number): boolean {
119
116
  return chr === 0x22 || chr === 0x27
120
117
  }
121
118
 
122
- function parseBracket (chr: number): void {
119
+ function parseBracket(chr: number): void {
123
120
  let inBracket = 1
124
121
  expressionPos = index
125
122
  while (!eof()) {
@@ -128,8 +125,8 @@ function parseBracket (chr: number): void {
128
125
  parseString(chr)
129
126
  continue
130
127
  }
131
- if (chr === 0x5B) inBracket++
132
- if (chr === 0x5D) inBracket--
128
+ if (chr === 0x5b) inBracket++
129
+ if (chr === 0x5d) inBracket--
133
130
  if (inBracket === 0) {
134
131
  expressionEndPos = index
135
132
  break
@@ -137,7 +134,7 @@ function parseBracket (chr: number): void {
137
134
  }
138
135
  }
139
136
 
140
- function parseString (chr: number): void {
137
+ function parseString(chr: number): void {
141
138
  const stringQuote = chr
142
139
  while (!eof()) {
143
140
  chr = next()
@@ -1,9 +1,8 @@
1
- /* @flow */
2
-
3
1
  import { warn } from 'core/util/index'
2
+ import { ASTDirective, ASTElement } from 'types/compiler'
4
3
 
5
- export default function on (el: ASTElement, dir: ASTDirective) {
6
- if (process.env.NODE_ENV !== 'production' && dir.modifiers) {
4
+ export default function on(el: ASTElement, dir: ASTDirective) {
5
+ if (__DEV__ && dir.modifiers) {
7
6
  warn(`v-on without argument does not support modifiers.`)
8
7
  }
9
8
  el.wrapListeners = (code: string) => `_g(${code},${dir.value})`
@@ -1,33 +1,41 @@
1
- /* @flow */
2
-
1
+ import { ASTElement, ASTNode } from 'types/compiler'
3
2
  import { dirRE, onRE } from './parser/index'
4
3
 
5
- type Range = { start?: number, end?: number };
4
+ type Range = { start?: number; end?: number }
6
5
 
7
6
  // these keywords should not appear inside expressions, but operators like
8
7
  // typeof, instanceof and in are allowed
9
- const prohibitedKeywordRE = new RegExp('\\b' + (
10
- 'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
11
- 'super,throw,while,yield,delete,export,import,return,switch,default,' +
12
- 'extends,finally,continue,debugger,function,arguments'
13
- ).split(',').join('\\b|\\b') + '\\b')
8
+ const prohibitedKeywordRE = new RegExp(
9
+ '\\b' +
10
+ (
11
+ 'do,if,for,let,new,try,var,case,else,with,await,break,catch,class,const,' +
12
+ 'super,throw,while,yield,delete,export,import,return,switch,default,' +
13
+ 'extends,finally,continue,debugger,function,arguments'
14
+ )
15
+ .split(',')
16
+ .join('\\b|\\b') +
17
+ '\\b'
18
+ )
14
19
 
15
20
  // these unary operators should not be used as property/method names
16
- const unaryOperatorsRE = new RegExp('\\b' + (
17
- 'delete,typeof,void'
18
- ).split(',').join('\\s*\\([^\\)]*\\)|\\b') + '\\s*\\([^\\)]*\\)')
21
+ const unaryOperatorsRE = new RegExp(
22
+ '\\b' +
23
+ 'delete,typeof,void'.split(',').join('\\s*\\([^\\)]*\\)|\\b') +
24
+ '\\s*\\([^\\)]*\\)'
25
+ )
19
26
 
20
27
  // strip strings in expressions
21
- const stripStringRE = /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g
28
+ const stripStringRE =
29
+ /'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*\$\{|\}(?:[^`\\]|\\.)*`|`(?:[^`\\]|\\.)*`/g
22
30
 
23
31
  // detect problematic expressions in a template
24
- export function detectErrors (ast: ?ASTNode, warn: Function) {
32
+ export function detectErrors(ast: ASTNode | undefined, warn: Function) {
25
33
  if (ast) {
26
34
  checkNode(ast, warn)
27
35
  }
28
36
  }
29
37
 
30
- function checkNode (node: ASTNode, warn: Function) {
38
+ function checkNode(node: ASTNode, warn: Function) {
31
39
  if (node.type === 1) {
32
40
  for (const name in node.attrsMap) {
33
41
  if (dirRE.test(name)) {
@@ -37,7 +45,12 @@ function checkNode (node: ASTNode, warn: Function) {
37
45
  if (name === 'v-for') {
38
46
  checkFor(node, `v-for="${value}"`, warn, range)
39
47
  } else if (name === 'v-slot' || name[0] === '#') {
40
- checkFunctionParameterExpression(value, `${name}="${value}"`, warn, range)
48
+ checkFunctionParameterExpression(
49
+ value,
50
+ `${name}="${value}"`,
51
+ warn,
52
+ range
53
+ )
41
54
  } else if (onRE.test(name)) {
42
55
  checkEvent(value, `${name}="${value}"`, warn, range)
43
56
  } else {
@@ -56,28 +69,33 @@ function checkNode (node: ASTNode, warn: Function) {
56
69
  }
57
70
  }
58
71
 
59
- function checkEvent (exp: string, text: string, warn: Function, range?: Range) {
72
+ function checkEvent(exp: string, text: string, warn: Function, range?: Range) {
60
73
  const stripped = exp.replace(stripStringRE, '')
61
74
  const keywordMatch: any = stripped.match(unaryOperatorsRE)
62
75
  if (keywordMatch && stripped.charAt(keywordMatch.index - 1) !== '$') {
63
76
  warn(
64
77
  `avoid using JavaScript unary operator as property name: ` +
65
- `"${keywordMatch[0]}" in expression ${text.trim()}`,
78
+ `"${keywordMatch[0]}" in expression ${text.trim()}`,
66
79
  range
67
80
  )
68
81
  }
69
82
  checkExpression(exp, text, warn, range)
70
83
  }
71
84
 
72
- function checkFor (node: ASTElement, text: string, warn: Function, range?: Range) {
85
+ function checkFor(
86
+ node: ASTElement,
87
+ text: string,
88
+ warn: Function,
89
+ range?: Range
90
+ ) {
73
91
  checkExpression(node.for || '', text, warn, range)
74
92
  checkIdentifier(node.alias, 'v-for alias', text, warn, range)
75
93
  checkIdentifier(node.iterator1, 'v-for iterator', text, warn, range)
76
94
  checkIdentifier(node.iterator2, 'v-for iterator', text, warn, range)
77
95
  }
78
96
 
79
- function checkIdentifier (
80
- ident: ?string,
97
+ function checkIdentifier(
98
+ ident: string | null | undefined,
81
99
  type: string,
82
100
  text: string,
83
101
  warn: Function,
@@ -86,42 +104,54 @@ function checkIdentifier (
86
104
  if (typeof ident === 'string') {
87
105
  try {
88
106
  new Function(`var ${ident}=_`)
89
- } catch (e) {
107
+ } catch (e: any) {
90
108
  warn(`invalid ${type} "${ident}" in expression: ${text.trim()}`, range)
91
109
  }
92
110
  }
93
111
  }
94
112
 
95
- function checkExpression (exp: string, text: string, warn: Function, range?: Range) {
113
+ function checkExpression(
114
+ exp: string,
115
+ text: string,
116
+ warn: Function,
117
+ range?: Range
118
+ ) {
96
119
  try {
97
120
  new Function(`return ${exp}`)
98
- } catch (e) {
99
- const keywordMatch = exp.replace(stripStringRE, '').match(prohibitedKeywordRE)
121
+ } catch (e: any) {
122
+ const keywordMatch = exp
123
+ .replace(stripStringRE, '')
124
+ .match(prohibitedKeywordRE)
100
125
  if (keywordMatch) {
101
126
  warn(
102
127
  `avoid using JavaScript keyword as property name: ` +
103
- `"${keywordMatch[0]}"\n Raw expression: ${text.trim()}`,
128
+ `"${keywordMatch[0]}"\n Raw expression: ${text.trim()}`,
104
129
  range
105
130
  )
106
131
  } else {
107
132
  warn(
108
133
  `invalid expression: ${e.message} in\n\n` +
109
- ` ${exp}\n\n` +
110
- ` Raw expression: ${text.trim()}\n`,
134
+ ` ${exp}\n\n` +
135
+ ` Raw expression: ${text.trim()}\n`,
111
136
  range
112
137
  )
113
138
  }
114
139
  }
115
140
  }
116
141
 
117
- function checkFunctionParameterExpression (exp: string, text: string, warn: Function, range?: Range) {
142
+ function checkFunctionParameterExpression(
143
+ exp: string,
144
+ text: string,
145
+ warn: Function,
146
+ range?: Range
147
+ ) {
118
148
  try {
119
149
  new Function(exp, '')
120
- } catch (e) {
150
+ } catch (e: any) {
121
151
  warn(
122
152
  `invalid function parameter expression: ${e.message} in\n\n` +
123
- ` ${exp}\n\n` +
124
- ` Raw expression: ${text.trim()}\n`,
153
+ ` ${exp}\n\n` +
154
+ ` Raw expression: ${text.trim()}\n`,
125
155
  range
126
156
  )
127
157
  }
@@ -1,91 +1,111 @@
1
- /* @flow */
2
-
3
1
  import { emptyObject } from 'shared/util'
2
+ import { ASTElement, ASTModifiers } from 'types/compiler'
4
3
  import { parseFilters } from './parser/filter-parser'
5
4
 
6
- type Range = { start?: number, end?: number };
5
+ type Range = { start?: number; end?: number }
7
6
 
8
7
  /* eslint-disable no-unused-vars */
9
- export function baseWarn (msg: string, range?: Range) {
8
+ export function baseWarn(msg: string, range?: Range) {
10
9
  console.error(`[Vue compiler]: ${msg}`)
11
10
  }
12
11
  /* eslint-enable no-unused-vars */
13
12
 
14
- export function pluckModuleFunction<F: Function> (
15
- modules: ?Array<Object>,
16
- key: string
17
- ): Array<F> {
18
- return modules
19
- ? modules.map(m => m[key]).filter(_ => _)
20
- : []
13
+ export function pluckModuleFunction<T, K extends keyof T>(
14
+ modules: Array<T> | undefined,
15
+ key: K
16
+ ): Array<T[K]> {
17
+ return modules ? modules.map(m => m[key]).filter(_ => _) : []
21
18
  }
22
19
 
23
- export function addProp (el: ASTElement, name: string, value: string, range?: Range, dynamic?: boolean) {
24
- (el.props || (el.props = [])).push(rangeSetItem({ name, value, dynamic }, range))
20
+ export function addProp(
21
+ el: ASTElement,
22
+ name: string,
23
+ value: string,
24
+ range?: Range,
25
+ dynamic?: boolean
26
+ ) {
27
+ ;(el.props || (el.props = [])).push(
28
+ rangeSetItem({ name, value, dynamic }, range)
29
+ )
25
30
  el.plain = false
26
31
  }
27
32
 
28
- export function addAttr (el: ASTElement, name: string, value: any, range?: Range, dynamic?: boolean) {
33
+ export function addAttr(
34
+ el: ASTElement,
35
+ name: string,
36
+ value: any,
37
+ range?: Range,
38
+ dynamic?: boolean
39
+ ) {
29
40
  const attrs = dynamic
30
- ? (el.dynamicAttrs || (el.dynamicAttrs = []))
31
- : (el.attrs || (el.attrs = []))
41
+ ? el.dynamicAttrs || (el.dynamicAttrs = [])
42
+ : el.attrs || (el.attrs = [])
32
43
  attrs.push(rangeSetItem({ name, value, dynamic }, range))
33
44
  el.plain = false
34
45
  }
35
46
 
36
47
  // add a raw attr (use this in preTransforms)
37
- export function addRawAttr (el: ASTElement, name: string, value: any, range?: Range) {
48
+ export function addRawAttr(
49
+ el: ASTElement,
50
+ name: string,
51
+ value: any,
52
+ range?: Range
53
+ ) {
38
54
  el.attrsMap[name] = value
39
55
  el.attrsList.push(rangeSetItem({ name, value }, range))
40
56
  }
41
57
 
42
- export function addDirective (
58
+ export function addDirective(
43
59
  el: ASTElement,
44
60
  name: string,
45
61
  rawName: string,
46
62
  value: string,
47
- arg: ?string,
48
- isDynamicArg: boolean,
49
- modifiers: ?ASTModifiers,
63
+ arg?: string,
64
+ isDynamicArg?: boolean,
65
+ modifiers?: ASTModifiers,
50
66
  range?: Range
51
67
  ) {
52
- (el.directives || (el.directives = [])).push(rangeSetItem({
53
- name,
54
- rawName,
55
- value,
56
- arg,
57
- isDynamicArg,
58
- modifiers
59
- }, range))
68
+ ;(el.directives || (el.directives = [])).push(
69
+ rangeSetItem(
70
+ {
71
+ name,
72
+ rawName,
73
+ value,
74
+ arg,
75
+ isDynamicArg,
76
+ modifiers
77
+ },
78
+ range
79
+ )
80
+ )
60
81
  el.plain = false
61
82
  }
62
83
 
63
- function prependModifierMarker (symbol: string, name: string, dynamic?: boolean): string {
64
- return dynamic
65
- ? `_p(${name},"${symbol}")`
66
- : symbol + name // mark the event as captured
84
+ function prependModifierMarker(
85
+ symbol: string,
86
+ name: string,
87
+ dynamic?: boolean
88
+ ): string {
89
+ return dynamic ? `_p(${name},"${symbol}")` : symbol + name // mark the event as captured
67
90
  }
68
91
 
69
- export function addHandler (
92
+ export function addHandler(
70
93
  el: ASTElement,
71
94
  name: string,
72
95
  value: string,
73
- modifiers: ?ASTModifiers,
96
+ modifiers?: ASTModifiers | null,
74
97
  important?: boolean,
75
- warn?: ?Function,
98
+ warn?: Function,
76
99
  range?: Range,
77
100
  dynamic?: boolean
78
101
  ) {
79
102
  modifiers = modifiers || emptyObject
80
103
  // warn prevent and passive modifier
81
104
  /* istanbul ignore if */
82
- if (
83
- process.env.NODE_ENV !== 'production' && warn &&
84
- modifiers.prevent && modifiers.passive
85
- ) {
105
+ if (__DEV__ && warn && modifiers.prevent && modifiers.passive) {
86
106
  warn(
87
- 'passive and prevent can\'t be used together. ' +
88
- 'Passive handler can\'t prevent default event.',
107
+ "passive and prevent can't be used together. " +
108
+ "Passive handler can't prevent default event.",
89
109
  range
90
110
  )
91
111
  }
@@ -149,23 +169,21 @@ export function addHandler (
149
169
  el.plain = false
150
170
  }
151
171
 
152
- export function getRawBindingAttr (
153
- el: ASTElement,
154
- name: string
155
- ) {
156
- return el.rawAttrsMap[':' + name] ||
172
+ export function getRawBindingAttr(el: ASTElement, name: string) {
173
+ return (
174
+ el.rawAttrsMap[':' + name] ||
157
175
  el.rawAttrsMap['v-bind:' + name] ||
158
176
  el.rawAttrsMap[name]
177
+ )
159
178
  }
160
179
 
161
- export function getBindingAttr (
180
+ export function getBindingAttr(
162
181
  el: ASTElement,
163
182
  name: string,
164
183
  getStatic?: boolean
165
- ): ?string {
184
+ ): string | undefined {
166
185
  const dynamicValue =
167
- getAndRemoveAttr(el, ':' + name) ||
168
- getAndRemoveAttr(el, 'v-bind:' + name)
186
+ getAndRemoveAttr(el, ':' + name) || getAndRemoveAttr(el, 'v-bind:' + name)
169
187
  if (dynamicValue != null) {
170
188
  return parseFilters(dynamicValue)
171
189
  } else if (getStatic !== false) {
@@ -180,11 +198,11 @@ export function getBindingAttr (
180
198
  // doesn't get processed by processAttrs.
181
199
  // By default it does NOT remove it from the map (attrsMap) because the map is
182
200
  // needed during codegen.
183
- export function getAndRemoveAttr (
201
+ export function getAndRemoveAttr(
184
202
  el: ASTElement,
185
203
  name: string,
186
204
  removeFromMap?: boolean
187
- ): ?string {
205
+ ): string | undefined {
188
206
  let val
189
207
  if ((val = el.attrsMap[name]) != null) {
190
208
  const list = el.attrsList
@@ -201,10 +219,7 @@ export function getAndRemoveAttr (
201
219
  return val
202
220
  }
203
221
 
204
- export function getAndRemoveAttrByRegex (
205
- el: ASTElement,
206
- name: RegExp
207
- ) {
222
+ export function getAndRemoveAttrByRegex(el: ASTElement, name: RegExp) {
208
223
  const list = el.attrsList
209
224
  for (let i = 0, l = list.length; i < l; i++) {
210
225
  const attr = list[i]
@@ -215,10 +230,7 @@ export function getAndRemoveAttrByRegex (
215
230
  }
216
231
  }
217
232
 
218
- function rangeSetItem (
219
- item: any,
220
- range?: { start?: number, end?: number }
221
- ) {
233
+ function rangeSetItem(item: any, range?: { start?: number; end?: number }) {
222
234
  if (range) {
223
235
  if (range.start != null) {
224
236
  item.start = range.start
@@ -1,14 +1,13 @@
1
- /* @flow */
2
-
3
1
  import { parse } from './parser/index'
4
2
  import { optimize } from './optimizer'
5
3
  import { generate } from './codegen/index'
6
4
  import { createCompilerCreator } from './create-compiler'
5
+ import { CompilerOptions, CompiledResult } from 'types/compiler'
7
6
 
8
7
  // `createCompilerCreator` allows creating compilers that use alternative
9
8
  // parser/optimizer/codegen, e.g the SSR optimizing compiler.
10
9
  // Here we just export a default compiler using the default parts.
11
- export const createCompiler = createCompilerCreator(function baseCompile (
10
+ export const createCompiler = createCompilerCreator(function baseCompile(
12
11
  template: string,
13
12
  options: CompilerOptions
14
13
  ): CompiledResult {
@@ -1,6 +1,5 @@
1
- /* @flow */
2
-
3
1
  import { makeMap, isBuiltInTag, cached, no } from 'shared/util'
2
+ import { ASTElement, CompilerOptions, ASTNode } from 'types/compiler'
4
3
 
5
4
  let isStaticKey
6
5
  let isPlatformReservedTag
@@ -18,7 +17,10 @@ const genStaticKeysCached = cached(genStaticKeys)
18
17
  * create fresh nodes for them on each re-render;
19
18
  * 2. Completely skip them in the patching process.
20
19
  */
21
- export function optimize (root: ?ASTElement, options: CompilerOptions) {
20
+ export function optimize(
21
+ root: ASTElement | null | undefined,
22
+ options: CompilerOptions
23
+ ) {
22
24
  if (!root) return
23
25
  isStaticKey = genStaticKeysCached(options.staticKeys || '')
24
26
  isPlatformReservedTag = options.isReservedTag || no
@@ -28,14 +30,14 @@ export function optimize (root: ?ASTElement, options: CompilerOptions) {
28
30
  markStaticRoots(root, false)
29
31
  }
30
32
 
31
- function genStaticKeys (keys: string): Function {
33
+ function genStaticKeys(keys: string): Function {
32
34
  return makeMap(
33
35
  'type,tag,attrsList,attrsMap,plain,parent,children,attrs,start,end,rawAttrsMap' +
34
- (keys ? ',' + keys : '')
36
+ (keys ? ',' + keys : '')
35
37
  )
36
38
  }
37
39
 
38
- function markStatic (node: ASTNode) {
40
+ function markStatic(node: ASTNode) {
39
41
  node.static = isStatic(node)
40
42
  if (node.type === 1) {
41
43
  // do not make component slot content static. this avoids
@@ -67,7 +69,7 @@ function markStatic (node: ASTNode) {
67
69
  }
68
70
  }
69
71
 
70
- function markStaticRoots (node: ASTNode, isInFor: boolean) {
72
+ function markStaticRoots(node: ASTNode, isInFor: boolean) {
71
73
  if (node.type === 1) {
72
74
  if (node.static || node.once) {
73
75
  node.staticInFor = isInFor
@@ -75,10 +77,11 @@ function markStaticRoots (node: ASTNode, isInFor: boolean) {
75
77
  // For a node to qualify as a static root, it should have children that
76
78
  // are not just static text. Otherwise the cost of hoisting out will
77
79
  // outweigh the benefits and it's better off to just always render it fresh.
78
- if (node.static && node.children.length && !(
79
- node.children.length === 1 &&
80
- node.children[0].type === 3
81
- )) {
80
+ if (
81
+ node.static &&
82
+ node.children.length &&
83
+ !(node.children.length === 1 && node.children[0].type === 3)
84
+ ) {
82
85
  node.staticRoot = true
83
86
  return
84
87
  } else {
@@ -97,24 +100,28 @@ function markStaticRoots (node: ASTNode, isInFor: boolean) {
97
100
  }
98
101
  }
99
102
 
100
- function isStatic (node: ASTNode): boolean {
101
- if (node.type === 2) { // expression
103
+ function isStatic(node: ASTNode): boolean {
104
+ if (node.type === 2) {
105
+ // expression
102
106
  return false
103
107
  }
104
- if (node.type === 3) { // text
108
+ if (node.type === 3) {
109
+ // text
105
110
  return true
106
111
  }
107
- return !!(node.pre || (
108
- !node.hasBindings && // no dynamic bindings
109
- !node.if && !node.for && // not v-if or v-for or v-else
110
- !isBuiltInTag(node.tag) && // not a built-in
111
- isPlatformReservedTag(node.tag) && // not a component
112
- !isDirectChildOfTemplateFor(node) &&
113
- Object.keys(node).every(isStaticKey)
114
- ))
112
+ return !!(
113
+ node.pre ||
114
+ (!node.hasBindings && // no dynamic bindings
115
+ !node.if &&
116
+ !node.for && // not v-if or v-for or v-else
117
+ !isBuiltInTag(node.tag) && // not a built-in
118
+ isPlatformReservedTag(node.tag) && // not a component
119
+ !isDirectChildOfTemplateFor(node) &&
120
+ Object.keys(node).every(isStaticKey))
121
+ )
115
122
  }
116
123
 
117
- function isDirectChildOfTemplateFor (node: ASTElement): boolean {
124
+ function isDirectChildOfTemplateFor(node: ASTElement): boolean {
118
125
  while (node.parent) {
119
126
  node = node.parent
120
127
  if (node.tag !== 'template') {
@@ -1,9 +1,7 @@
1
- /* @flow */
2
-
3
1
  let decoder
4
2
 
5
3
  export default {
6
- decode (html: string): string {
4
+ decode(html: string): string {
7
5
  decoder = decoder || document.createElement('div')
8
6
  decoder.innerHTML = html
9
7
  return decoder.textContent