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,34 +1,48 @@
1
- /* @flow */
2
-
3
1
  import { genHandlers } from './events'
4
2
  import baseDirectives from '../directives/index'
5
3
  import { camelize, no, extend } from 'shared/util'
6
4
  import { baseWarn, pluckModuleFunction } from '../helpers'
7
5
  import { emptySlotScopeToken } from '../parser/index'
8
-
9
- type TransformFunction = (el: ASTElement, code: string) => string;
10
- type DataGenFunction = (el: ASTElement) => string;
11
- type DirectiveFunction = (el: ASTElement, dir: ASTDirective, warn: Function) => boolean;
6
+ import {
7
+ ASTAttr,
8
+ ASTDirective,
9
+ ASTElement,
10
+ ASTExpression,
11
+ ASTIfConditions,
12
+ ASTNode,
13
+ ASTText,
14
+ CompilerOptions
15
+ } from 'types/compiler'
16
+
17
+ type TransformFunction = (el: ASTElement, code: string) => string
18
+ type DataGenFunction = (el: ASTElement) => string
19
+ type DirectiveFunction = (
20
+ el: ASTElement,
21
+ dir: ASTDirective,
22
+ warn: Function
23
+ ) => boolean
12
24
 
13
25
  export class CodegenState {
14
- options: CompilerOptions;
15
- warn: Function;
16
- transforms: Array<TransformFunction>;
17
- dataGenFns: Array<DataGenFunction>;
18
- directives: { [key: string]: DirectiveFunction };
19
- maybeComponent: (el: ASTElement) => boolean;
20
- onceId: number;
21
- staticRenderFns: Array<string>;
22
- pre: boolean;
23
-
24
- constructor (options: CompilerOptions) {
26
+ options: CompilerOptions
27
+ warn: Function
28
+ transforms: Array<TransformFunction>
29
+ dataGenFns: Array<DataGenFunction>
30
+ directives: { [key: string]: DirectiveFunction }
31
+ maybeComponent: (el: ASTElement) => boolean
32
+ onceId: number
33
+ staticRenderFns: Array<string>
34
+ pre: boolean
35
+
36
+ constructor(options: CompilerOptions) {
25
37
  this.options = options
26
38
  this.warn = options.warn || baseWarn
39
+ //@ts-expect-error `this.transforms ` is a different type than `options.modules.transformCode`
27
40
  this.transforms = pluckModuleFunction(options.modules, 'transformCode')
28
41
  this.dataGenFns = pluckModuleFunction(options.modules, 'genData')
29
42
  this.directives = extend(extend({}, baseDirectives), options.directives)
30
43
  const isReservedTag = options.isReservedTag || no
31
- this.maybeComponent = (el: ASTElement) => !!el.component || !isReservedTag(el.tag)
44
+ this.maybeComponent = (el: ASTElement) =>
45
+ !!el.component || !isReservedTag(el.tag)
32
46
  this.onceId = 0
33
47
  this.staticRenderFns = []
34
48
  this.pre = false
@@ -36,24 +50,28 @@ export class CodegenState {
36
50
  }
37
51
 
38
52
  export type CodegenResult = {
39
- render: string,
53
+ render: string
40
54
  staticRenderFns: Array<string>
41
- };
55
+ }
42
56
 
43
- export function generate (
57
+ export function generate(
44
58
  ast: ASTElement | void,
45
59
  options: CompilerOptions
46
60
  ): CodegenResult {
47
61
  const state = new CodegenState(options)
48
62
  // fix #11483, Root level <script> tags should not be rendered.
49
- const code = ast ? (ast.tag === 'script' ? 'null' : genElement(ast, state)) : '_c("div")'
63
+ const code = ast
64
+ ? ast.tag === 'script'
65
+ ? 'null'
66
+ : genElement(ast, state)
67
+ : '_c("div")'
50
68
  return {
51
69
  render: `with(this){return ${code}}`,
52
70
  staticRenderFns: state.staticRenderFns
53
71
  }
54
72
  }
55
73
 
56
- export function genElement (el: ASTElement, state: CodegenState): string {
74
+ export function genElement(el: ASTElement, state: CodegenState): string {
57
75
  if (el.parent) {
58
76
  el.pre = el.pre || el.parent.pre
59
77
  }
@@ -97,7 +115,7 @@ export function genElement (el: ASTElement, state: CodegenState): string {
97
115
  }
98
116
 
99
117
  // hoist static sub-trees out
100
- function genStatic (el: ASTElement, state: CodegenState): string {
118
+ function genStatic(el: ASTElement, state: CodegenState): string {
101
119
  el.staticProcessed = true
102
120
  // Some elements (templates) need to behave differently inside of a v-pre
103
121
  // node. All pre nodes are static roots, so we can use this as a location to
@@ -108,15 +126,13 @@ function genStatic (el: ASTElement, state: CodegenState): string {
108
126
  }
109
127
  state.staticRenderFns.push(`with(this){return ${genElement(el, state)}}`)
110
128
  state.pre = originalPreState
111
- return `_m(${
112
- state.staticRenderFns.length - 1
113
- }${
129
+ return `_m(${state.staticRenderFns.length - 1}${
114
130
  el.staticInFor ? ',true' : ''
115
131
  })`
116
132
  }
117
133
 
118
134
  // v-once
119
- function genOnce (el: ASTElement, state: CodegenState): string {
135
+ function genOnce(el: ASTElement, state: CodegenState): string {
120
136
  el.onceProcessed = true
121
137
  if (el.if && !el.ifProcessed) {
122
138
  return genIf(el, state)
@@ -125,16 +141,17 @@ function genOnce (el: ASTElement, state: CodegenState): string {
125
141
  let parent = el.parent
126
142
  while (parent) {
127
143
  if (parent.for) {
128
- key = parent.key
144
+ key = parent.key!
129
145
  break
130
146
  }
131
147
  parent = parent.parent
132
148
  }
133
149
  if (!key) {
134
- process.env.NODE_ENV !== 'production' && state.warn(
135
- `v-once can only be used inside v-for that is keyed. `,
136
- el.rawAttrsMap['v-once']
137
- )
150
+ __DEV__ &&
151
+ state.warn(
152
+ `v-once can only be used inside v-for that is keyed. `,
153
+ el.rawAttrsMap['v-once']
154
+ )
138
155
  return genElement(el, state)
139
156
  }
140
157
  return `_o(${genElement(el, state)},${state.onceId++},${key})`
@@ -143,7 +160,7 @@ function genOnce (el: ASTElement, state: CodegenState): string {
143
160
  }
144
161
  }
145
162
 
146
- export function genIf (
163
+ export function genIf(
147
164
  el: any,
148
165
  state: CodegenState,
149
166
  altGen?: Function,
@@ -153,7 +170,7 @@ export function genIf (
153
170
  return genIfConditions(el.ifConditions.slice(), state, altGen, altEmpty)
154
171
  }
155
172
 
156
- function genIfConditions (
173
+ function genIfConditions(
157
174
  conditions: ASTIfConditions,
158
175
  state: CodegenState,
159
176
  altGen?: Function,
@@ -163,28 +180,26 @@ function genIfConditions (
163
180
  return altEmpty || '_e()'
164
181
  }
165
182
 
166
- const condition = conditions.shift()
183
+ const condition = conditions.shift()!
167
184
  if (condition.exp) {
168
- return `(${condition.exp})?${
169
- genTernaryExp(condition.block)
170
- }:${
171
- genIfConditions(conditions, state, altGen, altEmpty)
172
- }`
185
+ return `(${condition.exp})?${genTernaryExp(
186
+ condition.block
187
+ )}:${genIfConditions(conditions, state, altGen, altEmpty)}`
173
188
  } else {
174
189
  return `${genTernaryExp(condition.block)}`
175
190
  }
176
191
 
177
192
  // v-if with v-once should generate code like (a)?_m(0):_m(1)
178
- function genTernaryExp (el) {
193
+ function genTernaryExp(el) {
179
194
  return altGen
180
195
  ? altGen(el, state)
181
196
  : el.once
182
- ? genOnce(el, state)
183
- : genElement(el, state)
197
+ ? genOnce(el, state)
198
+ : genElement(el, state)
184
199
  }
185
200
  }
186
201
 
187
- export function genFor (
202
+ export function genFor(
188
203
  el: any,
189
204
  state: CodegenState,
190
205
  altGen?: Function,
@@ -195,7 +210,8 @@ export function genFor (
195
210
  const iterator1 = el.iterator1 ? `,${el.iterator1}` : ''
196
211
  const iterator2 = el.iterator2 ? `,${el.iterator2}` : ''
197
212
 
198
- if (process.env.NODE_ENV !== 'production' &&
213
+ if (
214
+ __DEV__ &&
199
215
  state.maybeComponent(el) &&
200
216
  el.tag !== 'slot' &&
201
217
  el.tag !== 'template' &&
@@ -203,21 +219,23 @@ export function genFor (
203
219
  ) {
204
220
  state.warn(
205
221
  `<${el.tag} v-for="${alias} in ${exp}">: component lists rendered with ` +
206
- `v-for should have explicit keys. ` +
207
- `See https://vuejs.org/guide/list.html#key for more info.`,
222
+ `v-for should have explicit keys. ` +
223
+ `See https://vuejs.org/guide/list.html#key for more info.`,
208
224
  el.rawAttrsMap['v-for'],
209
225
  true /* tip */
210
226
  )
211
227
  }
212
228
 
213
229
  el.forProcessed = true // avoid recursion
214
- return `${altHelper || '_l'}((${exp}),` +
230
+ return (
231
+ `${altHelper || '_l'}((${exp}),` +
215
232
  `function(${alias}${iterator1}${iterator2}){` +
216
- `return ${(altGen || genElement)(el, state)}` +
233
+ `return ${(altGen || genElement)(el, state)}` +
217
234
  '})'
235
+ )
218
236
  }
219
237
 
220
- export function genData (el: ASTElement, state: CodegenState): string {
238
+ export function genData(el: ASTElement, state: CodegenState): string {
221
239
  let data = '{'
222
240
 
223
241
  // directives first.
@@ -274,13 +292,7 @@ export function genData (el: ASTElement, state: CodegenState): string {
274
292
  }
275
293
  // component v-model
276
294
  if (el.model) {
277
- data += `model:{value:${
278
- el.model.value
279
- },callback:${
280
- el.model.callback
281
- },expression:${
282
- el.model.expression
283
- }},`
295
+ data += `model:{value:${el.model.value},callback:${el.model.callback},expression:${el.model.expression}},`
284
296
  }
285
297
  // inline-template
286
298
  if (el.inlineTemplate) {
@@ -307,7 +319,7 @@ export function genData (el: ASTElement, state: CodegenState): string {
307
319
  return data
308
320
  }
309
321
 
310
- function genDirectives (el: ASTElement, state: CodegenState): string | void {
322
+ function genDirectives(el: ASTElement, state: CodegenState): string | void {
311
323
  const dirs = el.directives
312
324
  if (!dirs) return
313
325
  let res = 'directives:['
@@ -325,10 +337,10 @@ function genDirectives (el: ASTElement, state: CodegenState): string | void {
325
337
  if (needRuntime) {
326
338
  hasRuntime = true
327
339
  res += `{name:"${dir.name}",rawName:"${dir.rawName}"${
328
- dir.value ? `,value:(${dir.value}),expression:${JSON.stringify(dir.value)}` : ''
329
- }${
330
- dir.arg ? `,arg:${dir.isDynamicArg ? dir.arg : `"${dir.arg}"`}` : ''
331
- }${
340
+ dir.value
341
+ ? `,value:(${dir.value}),expression:${JSON.stringify(dir.value)}`
342
+ : ''
343
+ }${dir.arg ? `,arg:${dir.isDynamicArg ? dir.arg : `"${dir.arg}"`}` : ''}${
332
344
  dir.modifiers ? `,modifiers:${JSON.stringify(dir.modifiers)}` : ''
333
345
  }},`
334
346
  }
@@ -338,11 +350,12 @@ function genDirectives (el: ASTElement, state: CodegenState): string | void {
338
350
  }
339
351
  }
340
352
 
341
- function genInlineTemplate (el: ASTElement, state: CodegenState): ?string {
353
+ function genInlineTemplate(
354
+ el: ASTElement,
355
+ state: CodegenState
356
+ ): string | undefined {
342
357
  const ast = el.children[0]
343
- if (process.env.NODE_ENV !== 'production' && (
344
- el.children.length !== 1 || ast.type !== 1
345
- )) {
358
+ if (__DEV__ && (el.children.length !== 1 || ast.type !== 1)) {
346
359
  state.warn(
347
360
  'Inline-template components must have exactly one child element.',
348
361
  { start: el.start }
@@ -352,13 +365,13 @@ function genInlineTemplate (el: ASTElement, state: CodegenState): ?string {
352
365
  const inlineRenderFns = generate(ast, state.options)
353
366
  return `inlineTemplate:{render:function(){${
354
367
  inlineRenderFns.render
355
- }},staticRenderFns:[${
356
- inlineRenderFns.staticRenderFns.map(code => `function(){${code}}`).join(',')
357
- }]}`
368
+ }},staticRenderFns:[${inlineRenderFns.staticRenderFns
369
+ .map(code => `function(){${code}}`)
370
+ .join(',')}]}`
358
371
  }
359
372
  }
360
373
 
361
- function genScopedSlots (
374
+ function genScopedSlots(
362
375
  el: ASTElement,
363
376
  slots: { [key: string]: ASTElement },
364
377
  state: CodegenState
@@ -367,15 +380,14 @@ function genScopedSlots (
367
380
  // components with only scoped slots to skip forced updates from parent.
368
381
  // but in some cases we have to bail-out of this optimization
369
382
  // for example if the slot contains dynamic names, has v-if or v-for on them...
370
- let needsForceUpdate = el.for || Object.keys(slots).some(key => {
371
- const slot = slots[key]
372
- return (
373
- slot.slotTargetDynamic ||
374
- slot.if ||
375
- slot.for ||
376
- containsSlotChild(slot) // is passing down slot from parent which may be dynamic
377
- )
378
- })
383
+ let needsForceUpdate =
384
+ el.for ||
385
+ Object.keys(slots).some(key => {
386
+ const slot = slots[key]
387
+ return (
388
+ slot.slotTargetDynamic || slot.if || slot.for || containsSlotChild(slot) // is passing down slot from parent which may be dynamic
389
+ )
390
+ })
379
391
 
380
392
  // #9534: if a component with scoped slots is inside a conditional branch,
381
393
  // it's possible for the same component to be reused but with different
@@ -419,13 +431,13 @@ function genScopedSlots (
419
431
  function hash(str) {
420
432
  let hash = 5381
421
433
  let i = str.length
422
- while(i) {
434
+ while (i) {
423
435
  hash = (hash * 33) ^ str.charCodeAt(--i)
424
436
  }
425
437
  return hash >>> 0
426
438
  }
427
439
 
428
- function containsSlotChild (el: ASTNode): boolean {
440
+ function containsSlotChild(el: ASTNode): boolean {
429
441
  if (el.type === 1) {
430
442
  if (el.tag === 'slot') {
431
443
  return true
@@ -435,10 +447,7 @@ function containsSlotChild (el: ASTNode): boolean {
435
447
  return false
436
448
  }
437
449
 
438
- function genScopedSlot (
439
- el: ASTElement,
440
- state: CodegenState
441
- ): string {
450
+ function genScopedSlot(el: ASTElement, state: CodegenState): string {
442
451
  const isLegacySyntax = el.attrsMap['slot-scope']
443
452
  if (el.if && !el.ifProcessed && !isLegacySyntax) {
444
453
  return genIf(el, state, genScopedSlot, `null`)
@@ -446,22 +455,23 @@ function genScopedSlot (
446
455
  if (el.for && !el.forProcessed) {
447
456
  return genFor(el, state, genScopedSlot)
448
457
  }
449
- const slotScope = el.slotScope === emptySlotScopeToken
450
- ? ``
451
- : String(el.slotScope)
452
- const fn = `function(${slotScope}){` +
453
- `return ${el.tag === 'template'
454
- ? el.if && isLegacySyntax
455
- ? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined`
456
- : genChildren(el, state) || 'undefined'
457
- : genElement(el, state)
458
+ const slotScope =
459
+ el.slotScope === emptySlotScopeToken ? `` : String(el.slotScope)
460
+ const fn =
461
+ `function(${slotScope}){` +
462
+ `return ${
463
+ el.tag === 'template'
464
+ ? el.if && isLegacySyntax
465
+ ? `(${el.if})?${genChildren(el, state) || 'undefined'}:undefined`
466
+ : genChildren(el, state) || 'undefined'
467
+ : genElement(el, state)
458
468
  }}`
459
469
  // reverse proxy v-slot without scope on this.$slots
460
470
  const reverseProxy = slotScope ? `` : `,proxy:true`
461
471
  return `{key:${el.slotTarget || `"default"`},fn:${fn}${reverseProxy}}`
462
472
  }
463
473
 
464
- export function genChildren (
474
+ export function genChildren(
465
475
  el: ASTElement,
466
476
  state: CodegenState,
467
477
  checkSkip?: boolean,
@@ -472,13 +482,16 @@ export function genChildren (
472
482
  if (children.length) {
473
483
  const el: any = children[0]
474
484
  // optimize single v-for
475
- if (children.length === 1 &&
485
+ if (
486
+ children.length === 1 &&
476
487
  el.for &&
477
488
  el.tag !== 'template' &&
478
489
  el.tag !== 'slot'
479
490
  ) {
480
491
  const normalizationType = checkSkip
481
- ? state.maybeComponent(el) ? `,1` : `,0`
492
+ ? state.maybeComponent(el)
493
+ ? `,1`
494
+ : `,0`
482
495
  : ``
483
496
  return `${(altGenElement || genElement)(el, state)}${normalizationType}`
484
497
  }
@@ -496,7 +509,7 @@ export function genChildren (
496
509
  // 0: no normalization needed
497
510
  // 1: simple normalization needed (possible 1-level deep nested array)
498
511
  // 2: full normalization needed
499
- function getNormalizationType (
512
+ function getNormalizationType(
500
513
  children: Array<ASTNode>,
501
514
  maybeComponent: (el: ASTElement) => boolean
502
515
  ): number {
@@ -506,24 +519,29 @@ function getNormalizationType (
506
519
  if (el.type !== 1) {
507
520
  continue
508
521
  }
509
- if (needsNormalization(el) ||
510
- (el.ifConditions && el.ifConditions.some(c => needsNormalization(c.block)))) {
522
+ if (
523
+ needsNormalization(el) ||
524
+ (el.ifConditions &&
525
+ el.ifConditions.some(c => needsNormalization(c.block)))
526
+ ) {
511
527
  res = 2
512
528
  break
513
529
  }
514
- if (maybeComponent(el) ||
515
- (el.ifConditions && el.ifConditions.some(c => maybeComponent(c.block)))) {
530
+ if (
531
+ maybeComponent(el) ||
532
+ (el.ifConditions && el.ifConditions.some(c => maybeComponent(c.block)))
533
+ ) {
516
534
  res = 1
517
535
  }
518
536
  }
519
537
  return res
520
538
  }
521
539
 
522
- function needsNormalization (el: ASTElement): boolean {
540
+ function needsNormalization(el: ASTElement): boolean {
523
541
  return el.for !== undefined || el.tag === 'template' || el.tag === 'slot'
524
542
  }
525
543
 
526
- function genNode (node: ASTNode, state: CodegenState): string {
544
+ function genNode(node: ASTNode, state: CodegenState): string {
527
545
  if (node.type === 1) {
528
546
  return genElement(node, state)
529
547
  } else if (node.type === 3 && node.isComment) {
@@ -533,29 +551,33 @@ function genNode (node: ASTNode, state: CodegenState): string {
533
551
  }
534
552
  }
535
553
 
536
- export function genText (text: ASTText | ASTExpression): string {
537
- return `_v(${text.type === 2
538
- ? text.expression // no need for () because already wrapped in _s()
539
- : transformSpecialNewlines(JSON.stringify(text.text))
554
+ export function genText(text: ASTText | ASTExpression): string {
555
+ return `_v(${
556
+ text.type === 2
557
+ ? text.expression // no need for () because already wrapped in _s()
558
+ : transformSpecialNewlines(JSON.stringify(text.text))
540
559
  })`
541
560
  }
542
561
 
543
- export function genComment (comment: ASTText): string {
562
+ export function genComment(comment: ASTText): string {
544
563
  return `_e(${JSON.stringify(comment.text)})`
545
564
  }
546
565
 
547
- function genSlot (el: ASTElement, state: CodegenState): string {
566
+ function genSlot(el: ASTElement, state: CodegenState): string {
548
567
  const slotName = el.slotName || '"default"'
549
568
  const children = genChildren(el, state)
550
569
  let res = `_t(${slotName}${children ? `,function(){return ${children}}` : ''}`
551
- const attrs = el.attrs || el.dynamicAttrs
552
- ? genProps((el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
553
- // slot props are camelized
554
- name: camelize(attr.name),
555
- value: attr.value,
556
- dynamic: attr.dynamic
557
- })))
558
- : null
570
+ const attrs =
571
+ el.attrs || el.dynamicAttrs
572
+ ? genProps(
573
+ (el.attrs || []).concat(el.dynamicAttrs || []).map(attr => ({
574
+ // slot props are camelized
575
+ name: camelize(attr.name),
576
+ value: attr.value,
577
+ dynamic: attr.dynamic
578
+ }))
579
+ )
580
+ : null
559
581
  const bind = el.attrsMap['v-bind']
560
582
  if ((attrs || bind) && !children) {
561
583
  res += `,null`
@@ -570,7 +592,7 @@ function genSlot (el: ASTElement, state: CodegenState): string {
570
592
  }
571
593
 
572
594
  // componentName is el.component, take it as argument to shun flow's pessimistic refinement
573
- function genComponent (
595
+ function genComponent(
574
596
  componentName: string,
575
597
  el: ASTElement,
576
598
  state: CodegenState
@@ -581,14 +603,12 @@ function genComponent (
581
603
  })`
582
604
  }
583
605
 
584
- function genProps (props: Array<ASTAttr>): string {
606
+ function genProps(props: Array<ASTAttr>): string {
585
607
  let staticProps = ``
586
608
  let dynamicProps = ``
587
609
  for (let i = 0; i < props.length; i++) {
588
610
  const prop = props[i]
589
- const value = __WEEX__
590
- ? generateValue(prop.value)
591
- : transformSpecialNewlines(prop.value)
611
+ const value = transformSpecialNewlines(prop.value)
592
612
  if (prop.dynamic) {
593
613
  dynamicProps += `${prop.name},${value},`
594
614
  } else {
@@ -603,17 +623,7 @@ function genProps (props: Array<ASTAttr>): string {
603
623
  }
604
624
  }
605
625
 
606
- /* istanbul ignore next */
607
- function generateValue (value) {
608
- if (typeof value === 'string') {
609
- return transformSpecialNewlines(value)
610
- }
611
- return JSON.stringify(value)
612
- }
613
-
614
626
  // #3895, #4268
615
- function transformSpecialNewlines (text: string): string {
616
- return text
617
- .replace(/\u2028/g, '\\u2028')
618
- .replace(/\u2029/g, '\\u2029')
627
+ function transformSpecialNewlines(text: string): string {
628
+ return text.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029')
619
629
  }
@@ -1,30 +1,37 @@
1
- /* @flow */
2
-
3
1
  import { extend } from 'shared/util'
2
+ import { CompilerOptions, CompiledResult, WarningMessage } from 'types/compiler'
4
3
  import { detectErrors } from './error-detector'
5
4
  import { createCompileToFunctionFn } from './to-function'
6
5
 
7
- export function createCompilerCreator (baseCompile: Function): Function {
8
- return function createCompiler (baseOptions: CompilerOptions) {
9
- function compile (
6
+ export function createCompilerCreator(baseCompile: Function): Function {
7
+ return function createCompiler(baseOptions: CompilerOptions) {
8
+ function compile(
10
9
  template: string,
11
10
  options?: CompilerOptions
12
11
  ): CompiledResult {
13
12
  const finalOptions = Object.create(baseOptions)
14
- const errors = []
15
- const tips = []
13
+ const errors: WarningMessage[] = []
14
+ const tips: WarningMessage[] = []
16
15
 
17
- let warn = (msg, range, tip) => {
18
- (tip ? tips : errors).push(msg)
16
+ let warn = (
17
+ msg: WarningMessage,
18
+ range: { start: number; end: number },
19
+ tip: string
20
+ ) => {
21
+ ;(tip ? tips : errors).push(msg)
19
22
  }
20
23
 
21
24
  if (options) {
22
- if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
25
+ if (__DEV__ && options.outputSourceRange) {
23
26
  // $flow-disable-line
24
- const leadingSpaceLength = template.match(/^\s*/)[0].length
27
+ const leadingSpaceLength = template.match(/^\s*/)![0].length
25
28
 
26
- warn = (msg, range, tip) => {
27
- const data: WarningMessage = { msg }
29
+ warn = (
30
+ msg: WarningMessage | string,
31
+ range: { start: number; end: number },
32
+ tip: string
33
+ ) => {
34
+ const data: WarningMessage = typeof msg === 'string' ? { msg } : msg
28
35
  if (range) {
29
36
  if (range.start != null) {
30
37
  data.start = range.start + leadingSpaceLength
@@ -33,13 +40,14 @@ export function createCompilerCreator (baseCompile: Function): Function {
33
40
  data.end = range.end + leadingSpaceLength
34
41
  }
35
42
  }
36
- (tip ? tips : errors).push(data)
43
+ ;(tip ? tips : errors).push(data)
37
44
  }
38
45
  }
39
46
  // merge custom modules
40
47
  if (options.modules) {
41
- finalOptions.modules =
42
- (baseOptions.modules || []).concat(options.modules)
48
+ finalOptions.modules = (baseOptions.modules || []).concat(
49
+ options.modules
50
+ )
43
51
  }
44
52
  // merge custom directives
45
53
  if (options.directives) {
@@ -51,7 +59,7 @@ export function createCompilerCreator (baseCompile: Function): Function {
51
59
  // copy other options
52
60
  for (const key in options) {
53
61
  if (key !== 'modules' && key !== 'directives') {
54
- finalOptions[key] = options[key]
62
+ finalOptions[key] = options[key as keyof CompilerOptions]
55
63
  }
56
64
  }
57
65
  }
@@ -59,7 +67,7 @@ export function createCompilerCreator (baseCompile: Function): Function {
59
67
  finalOptions.warn = warn
60
68
 
61
69
  const compiled = baseCompile(template.trim(), finalOptions)
62
- if (process.env.NODE_ENV !== 'production') {
70
+ if (__DEV__) {
63
71
  detectErrors(compiled.ast, warn)
64
72
  }
65
73
  compiled.errors = errors
@@ -0,0 +1,9 @@
1
+ import { ASTDirective, ASTElement } from 'types/compiler'
2
+
3
+ export default function bind(el: ASTElement, dir: ASTDirective) {
4
+ el.wrapData = (code: string) => {
5
+ return `_b(${code},'${el.tag}',${dir.value},${
6
+ dir.modifiers && dir.modifiers.prop ? 'true' : 'false'
7
+ }${dir.modifiers && dir.modifiers.sync ? ',true' : ''})`
8
+ }
9
+ }
@@ -1,5 +1,3 @@
1
- /* @flow */
2
-
3
1
  import on from './on'
4
2
  import bind from './bind'
5
3
  import { noop } from 'shared/util'