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 he from 'he'
4
2
  import { parseHTML } from './html-parser'
5
3
  import { parseText } from './text-parser'
@@ -21,6 +19,15 @@ import {
21
19
  getAndRemoveAttrByRegex
22
20
  } from '../helpers'
23
21
 
22
+ import {
23
+ ASTAttr,
24
+ ASTElement,
25
+ ASTIfCondition,
26
+ ASTNode,
27
+ ASTText,
28
+ CompilerOptions
29
+ } from 'types/compiler'
30
+
24
31
  export const onRE = /^@|^v-on:/
25
32
  export const dirRE = process.env.VBIND_PROP_SHORTHAND
26
33
  ? /^v-|^@|^:|^\.|^#/
@@ -57,7 +64,7 @@ let platformMustUseProp
57
64
  let platformGetTagNamespace
58
65
  let maybeComponent
59
66
 
60
- export function createASTElement (
67
+ export function createASTElement(
61
68
  tag: string,
62
69
  attrs: Array<ASTAttr>,
63
70
  parent: ASTElement | void
@@ -76,29 +83,27 @@ export function createASTElement (
76
83
  /**
77
84
  * Convert HTML string to AST.
78
85
  */
79
- export function parse (
80
- template: string,
81
- options: CompilerOptions
82
- ): ASTElement | void {
86
+ export function parse(template: string, options: CompilerOptions): ASTElement {
83
87
  warn = options.warn || baseWarn
84
88
 
85
89
  platformIsPreTag = options.isPreTag || no
86
90
  platformMustUseProp = options.mustUseProp || no
87
91
  platformGetTagNamespace = options.getTagNamespace || no
88
92
  const isReservedTag = options.isReservedTag || no
89
- maybeComponent = (el: ASTElement) => !!(
90
- el.component ||
91
- el.attrsMap[':is'] ||
92
- el.attrsMap['v-bind:is'] ||
93
- !(el.attrsMap.is ? isReservedTag(el.attrsMap.is) : isReservedTag(el.tag))
94
- )
93
+ maybeComponent = (el: ASTElement) =>
94
+ !!(
95
+ el.component ||
96
+ el.attrsMap[':is'] ||
97
+ el.attrsMap['v-bind:is'] ||
98
+ !(el.attrsMap.is ? isReservedTag(el.attrsMap.is) : isReservedTag(el.tag))
99
+ )
95
100
  transforms = pluckModuleFunction(options.modules, 'transformNode')
96
101
  preTransforms = pluckModuleFunction(options.modules, 'preTransformNode')
97
102
  postTransforms = pluckModuleFunction(options.modules, 'postTransformNode')
98
103
 
99
104
  delimiters = options.delimiters
100
105
 
101
- const stack = []
106
+ const stack: any[] = []
102
107
  const preserveWhitespace = options.preserveWhitespace !== false
103
108
  const whitespaceOption = options.whitespace
104
109
  let root
@@ -107,14 +112,14 @@ export function parse (
107
112
  let inPre = false
108
113
  let warned = false
109
114
 
110
- function warnOnce (msg, range) {
115
+ function warnOnce(msg, range) {
111
116
  if (!warned) {
112
117
  warned = true
113
118
  warn(msg, range)
114
119
  }
115
120
  }
116
121
 
117
- function closeElement (element) {
122
+ function closeElement(element) {
118
123
  trimEndingWhitespace(element)
119
124
  if (!inVPre && !element.processed) {
120
125
  element = processElement(element, options)
@@ -123,18 +128,18 @@ export function parse (
123
128
  if (!stack.length && element !== root) {
124
129
  // allow root elements with v-if, v-else-if and v-else
125
130
  if (root.if && (element.elseif || element.else)) {
126
- if (process.env.NODE_ENV !== 'production') {
131
+ if (__DEV__) {
127
132
  checkRootConstraints(element)
128
133
  }
129
134
  addIfCondition(root, {
130
135
  exp: element.elseif,
131
136
  block: element
132
137
  })
133
- } else if (process.env.NODE_ENV !== 'production') {
138
+ } else if (__DEV__) {
134
139
  warnOnce(
135
140
  `Component template should contain exactly one root element. ` +
136
- `If you are using v-if on multiple elements, ` +
137
- `use v-else-if to chain them instead.`,
141
+ `If you are using v-if on multiple elements, ` +
142
+ `use v-else-if to chain them instead.`,
138
143
  { start: element.start }
139
144
  )
140
145
  }
@@ -148,7 +153,9 @@ export function parse (
148
153
  // keep it in the children list so that v-else(-if) conditions can
149
154
  // find it as the prev node.
150
155
  const name = element.slotTarget || '"default"'
151
- ;(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element
156
+ ;(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[
157
+ name
158
+ ] = element
152
159
  }
153
160
  currentParent.children.push(element)
154
161
  element.parent = currentParent
@@ -157,7 +164,7 @@ export function parse (
157
164
 
158
165
  // final children cleanup
159
166
  // filter out scoped slots
160
- element.children = element.children.filter(c => !(c: any).slotScope)
167
+ element.children = element.children.filter(c => !c.slotScope)
161
168
  // remove trailing whitespace node again
162
169
  trimEndingWhitespace(element)
163
170
 
@@ -174,7 +181,7 @@ export function parse (
174
181
  }
175
182
  }
176
183
 
177
- function trimEndingWhitespace (el) {
184
+ function trimEndingWhitespace(el) {
178
185
  // remove trailing whitespace node
179
186
  if (!inPre) {
180
187
  let lastNode
@@ -188,18 +195,18 @@ export function parse (
188
195
  }
189
196
  }
190
197
 
191
- function checkRootConstraints (el) {
198
+ function checkRootConstraints(el) {
192
199
  if (el.tag === 'slot' || el.tag === 'template') {
193
200
  warnOnce(
194
201
  `Cannot use <${el.tag}> as component root element because it may ` +
195
- 'contain multiple nodes.',
202
+ 'contain multiple nodes.',
196
203
  { start: el.start }
197
204
  )
198
205
  }
199
206
  if (el.attrsMap.hasOwnProperty('v-for')) {
200
207
  warnOnce(
201
208
  'Cannot use v-for on stateful component root element because ' +
202
- 'it renders multiple elements.',
209
+ 'it renders multiple elements.',
203
210
  el.rawAttrsMap['v-for']
204
211
  )
205
212
  }
@@ -214,10 +221,11 @@ export function parse (
214
221
  shouldDecodeNewlinesForHref: options.shouldDecodeNewlinesForHref,
215
222
  shouldKeepComment: options.comments,
216
223
  outputSourceRange: options.outputSourceRange,
217
- start (tag, attrs, unary, start, end) {
224
+ start(tag, attrs, unary, start, end) {
218
225
  // check namespace.
219
226
  // inherit parent ns if there is one
220
- const ns = (currentParent && currentParent.ns) || platformGetTagNamespace(tag)
227
+ const ns =
228
+ (currentParent && currentParent.ns) || platformGetTagNamespace(tag)
221
229
 
222
230
  // handle IE svg bug
223
231
  /* istanbul ignore if */
@@ -230,7 +238,7 @@ export function parse (
230
238
  element.ns = ns
231
239
  }
232
240
 
233
- if (process.env.NODE_ENV !== 'production') {
241
+ if (__DEV__) {
234
242
  if (options.outputSourceRange) {
235
243
  element.start = start
236
244
  element.end = end
@@ -243,7 +251,7 @@ export function parse (
243
251
  if (invalidAttributeRE.test(attr.name)) {
244
252
  warn(
245
253
  `Invalid dynamic argument expression: attribute names cannot contain ` +
246
- `spaces, quotes, <, >, / or =.`,
254
+ `spaces, quotes, <, >, / or =.`,
247
255
  {
248
256
  start: attr.start + attr.name.indexOf(`[`),
249
257
  end: attr.start + attr.name.length
@@ -255,12 +263,14 @@ export function parse (
255
263
 
256
264
  if (isForbiddenTag(element) && !isServerRendering()) {
257
265
  element.forbidden = true
258
- process.env.NODE_ENV !== 'production' && warn(
259
- 'Templates should only be responsible for mapping the state to the ' +
260
- 'UI. Avoid placing tags with side-effects in your templates, such as ' +
261
- `<${tag}>` + ', as they will not be parsed.',
262
- { start: element.start }
263
- )
266
+ __DEV__ &&
267
+ warn(
268
+ 'Templates should only be responsible for mapping the state to the ' +
269
+ 'UI. Avoid placing tags with side-effects in your templates, such as ' +
270
+ `<${tag}>` +
271
+ ', as they will not be parsed.',
272
+ { start: element.start }
273
+ )
264
274
  }
265
275
 
266
276
  // apply pre-transforms
@@ -288,7 +298,7 @@ export function parse (
288
298
 
289
299
  if (!root) {
290
300
  root = element
291
- if (process.env.NODE_ENV !== 'production') {
301
+ if (__DEV__) {
292
302
  checkRootConstraints(root)
293
303
  }
294
304
  }
@@ -301,37 +311,37 @@ export function parse (
301
311
  }
302
312
  },
303
313
 
304
- end (tag, start, end) {
314
+ end(tag, start, end) {
305
315
  const element = stack[stack.length - 1]
306
316
  // pop stack
307
317
  stack.length -= 1
308
318
  currentParent = stack[stack.length - 1]
309
- if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
319
+ if (__DEV__ && options.outputSourceRange) {
310
320
  element.end = end
311
321
  }
312
322
  closeElement(element)
313
323
  },
314
324
 
315
- chars (text: string, start: number, end: number) {
325
+ chars(text: string, start: number, end: number) {
316
326
  if (!currentParent) {
317
- if (process.env.NODE_ENV !== 'production') {
327
+ if (__DEV__) {
318
328
  if (text === template) {
319
329
  warnOnce(
320
330
  'Component template requires a root element, rather than just text.',
321
331
  { start }
322
332
  )
323
333
  } else if ((text = text.trim())) {
324
- warnOnce(
325
- `text "${text}" outside root element will be ignored.`,
326
- { start }
327
- )
334
+ warnOnce(`text "${text}" outside root element will be ignored.`, {
335
+ start
336
+ })
328
337
  }
329
338
  }
330
339
  return
331
340
  }
332
341
  // IE textarea placeholder bug
333
342
  /* istanbul ignore if */
334
- if (isIE &&
343
+ if (
344
+ isIE &&
335
345
  currentParent.tag === 'textarea' &&
336
346
  currentParent.attrsMap.placeholder === text
337
347
  ) {
@@ -339,7 +349,9 @@ export function parse (
339
349
  }
340
350
  const children = currentParent.children
341
351
  if (inPre || text.trim()) {
342
- text = isTextTag(currentParent) ? text : decodeHTMLCached(text)
352
+ text = isTextTag(currentParent)
353
+ ? text
354
+ : (decodeHTMLCached(text) as string)
343
355
  } else if (!children.length) {
344
356
  // remove the whitespace-only node right after an opening tag
345
357
  text = ''
@@ -360,7 +372,7 @@ export function parse (
360
372
  text = text.replace(whitespaceRE, ' ')
361
373
  }
362
374
  let res
363
- let child: ?ASTNode
375
+ let child: ASTNode | undefined
364
376
  if (!inVPre && text !== ' ' && (res = parseText(text, delimiters))) {
365
377
  child = {
366
378
  type: 2,
@@ -368,14 +380,18 @@ export function parse (
368
380
  tokens: res.tokens,
369
381
  text
370
382
  }
371
- } else if (text !== ' ' || !children.length || children[children.length - 1].text !== ' ') {
383
+ } else if (
384
+ text !== ' ' ||
385
+ !children.length ||
386
+ children[children.length - 1].text !== ' '
387
+ ) {
372
388
  child = {
373
389
  type: 3,
374
390
  text
375
391
  }
376
392
  }
377
393
  if (child) {
378
- if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
394
+ if (__DEV__ && options.outputSourceRange) {
379
395
  child.start = start
380
396
  child.end = end
381
397
  }
@@ -383,7 +399,7 @@ export function parse (
383
399
  }
384
400
  }
385
401
  },
386
- comment (text: string, start, end) {
402
+ comment(text: string, start, end) {
387
403
  // adding anything as a sibling to the root node is forbidden
388
404
  // comments should still be allowed, but ignored
389
405
  if (currentParent) {
@@ -392,7 +408,7 @@ export function parse (
392
408
  text,
393
409
  isComment: true
394
410
  }
395
- if (process.env.NODE_ENV !== 'production' && options.outputSourceRange) {
411
+ if (__DEV__ && options.outputSourceRange) {
396
412
  child.start = start
397
413
  child.end = end
398
414
  }
@@ -403,17 +419,17 @@ export function parse (
403
419
  return root
404
420
  }
405
421
 
406
- function processPre (el) {
422
+ function processPre(el) {
407
423
  if (getAndRemoveAttr(el, 'v-pre') != null) {
408
424
  el.pre = true
409
425
  }
410
426
  }
411
427
 
412
- function processRawAttrs (el) {
428
+ function processRawAttrs(el) {
413
429
  const list = el.attrsList
414
430
  const len = list.length
415
431
  if (len) {
416
- const attrs: Array<ASTAttr> = el.attrs = new Array(len)
432
+ const attrs: Array<ASTAttr> = (el.attrs = new Array(len))
417
433
  for (let i = 0; i < len; i++) {
418
434
  attrs[i] = {
419
435
  name: list[i].name,
@@ -430,19 +446,13 @@ function processRawAttrs (el) {
430
446
  }
431
447
  }
432
448
 
433
- export function processElement (
434
- element: ASTElement,
435
- options: CompilerOptions
436
- ) {
449
+ export function processElement(element: ASTElement, options: CompilerOptions) {
437
450
  processKey(element)
438
451
 
439
452
  // determine whether this is a plain element after
440
453
  // removing structural attributes
441
- element.plain = (
442
- !element.key &&
443
- !element.scopedSlots &&
444
- !element.attrsList.length
445
- )
454
+ element.plain =
455
+ !element.key && !element.scopedSlots && !element.attrsList.length
446
456
 
447
457
  processRef(element)
448
458
  processSlotContent(element)
@@ -455,10 +465,10 @@ export function processElement (
455
465
  return element
456
466
  }
457
467
 
458
- function processKey (el) {
468
+ function processKey(el) {
459
469
  const exp = getBindingAttr(el, 'key')
460
470
  if (exp) {
461
- if (process.env.NODE_ENV !== 'production') {
471
+ if (__DEV__) {
462
472
  if (el.tag === 'template') {
463
473
  warn(
464
474
  `<template> cannot be keyed. Place the key on real elements instead.`,
@@ -468,10 +478,15 @@ function processKey (el) {
468
478
  if (el.for) {
469
479
  const iterator = el.iterator2 || el.iterator1
470
480
  const parent = el.parent
471
- if (iterator && iterator === exp && parent && parent.tag === 'transition-group') {
481
+ if (
482
+ iterator &&
483
+ iterator === exp &&
484
+ parent &&
485
+ parent.tag === 'transition-group'
486
+ ) {
472
487
  warn(
473
488
  `Do not use v-for index as key on <transition-group> children, ` +
474
- `this is the same as not using keys.`,
489
+ `this is the same as not using keys.`,
475
490
  getRawBindingAttr(el, 'key'),
476
491
  true /* tip */
477
492
  )
@@ -482,7 +497,7 @@ function processKey (el) {
482
497
  }
483
498
  }
484
499
 
485
- function processRef (el) {
500
+ function processRef(el) {
486
501
  const ref = getBindingAttr(el, 'ref')
487
502
  if (ref) {
488
503
  el.ref = ref
@@ -490,32 +505,29 @@ function processRef (el) {
490
505
  }
491
506
  }
492
507
 
493
- export function processFor (el: ASTElement) {
508
+ export function processFor(el: ASTElement) {
494
509
  let exp
495
510
  if ((exp = getAndRemoveAttr(el, 'v-for'))) {
496
511
  const res = parseFor(exp)
497
512
  if (res) {
498
513
  extend(el, res)
499
- } else if (process.env.NODE_ENV !== 'production') {
500
- warn(
501
- `Invalid v-for expression: ${exp}`,
502
- el.rawAttrsMap['v-for']
503
- )
514
+ } else if (__DEV__) {
515
+ warn(`Invalid v-for expression: ${exp}`, el.rawAttrsMap['v-for'])
504
516
  }
505
517
  }
506
518
  }
507
519
 
508
520
  type ForParseResult = {
509
- for: string;
510
- alias: string;
511
- iterator1?: string;
512
- iterator2?: string;
513
- };
521
+ for: string
522
+ alias: string
523
+ iterator1?: string
524
+ iterator2?: string
525
+ }
514
526
 
515
- export function parseFor (exp: string): ?ForParseResult {
527
+ export function parseFor(exp: string): ForParseResult | undefined {
516
528
  const inMatch = exp.match(forAliasRE)
517
529
  if (!inMatch) return
518
- const res = {}
530
+ const res: any = {}
519
531
  res.for = inMatch[2].trim()
520
532
  const alias = inMatch[1].trim().replace(stripParensRE, '')
521
533
  const iteratorMatch = alias.match(forIteratorRE)
@@ -531,7 +543,7 @@ export function parseFor (exp: string): ?ForParseResult {
531
543
  return res
532
544
  }
533
545
 
534
- function processIf (el) {
546
+ function processIf(el) {
535
547
  const exp = getAndRemoveAttr(el, 'v-if')
536
548
  if (exp) {
537
549
  el.if = exp
@@ -550,32 +562,32 @@ function processIf (el) {
550
562
  }
551
563
  }
552
564
 
553
- function processIfConditions (el, parent) {
565
+ function processIfConditions(el, parent) {
554
566
  const prev = findPrevElement(parent.children)
555
567
  if (prev && prev.if) {
556
568
  addIfCondition(prev, {
557
569
  exp: el.elseif,
558
570
  block: el
559
571
  })
560
- } else if (process.env.NODE_ENV !== 'production') {
572
+ } else if (__DEV__) {
561
573
  warn(
562
- `v-${el.elseif ? ('else-if="' + el.elseif + '"') : 'else'} ` +
563
- `used on element <${el.tag}> without corresponding v-if.`,
574
+ `v-${el.elseif ? 'else-if="' + el.elseif + '"' : 'else'} ` +
575
+ `used on element <${el.tag}> without corresponding v-if.`,
564
576
  el.rawAttrsMap[el.elseif ? 'v-else-if' : 'v-else']
565
577
  )
566
578
  }
567
579
  }
568
580
 
569
- function findPrevElement (children: Array<any>): ASTElement | void {
581
+ function findPrevElement(children: Array<any>): ASTElement | void {
570
582
  let i = children.length
571
583
  while (i--) {
572
584
  if (children[i].type === 1) {
573
585
  return children[i]
574
586
  } else {
575
- if (process.env.NODE_ENV !== 'production' && children[i].text !== ' ') {
587
+ if (__DEV__ && children[i].text !== ' ') {
576
588
  warn(
577
589
  `text "${children[i].text.trim()}" between v-if and v-else(-if) ` +
578
- `will be ignored.`,
590
+ `will be ignored.`,
579
591
  children[i]
580
592
  )
581
593
  }
@@ -584,14 +596,14 @@ function findPrevElement (children: Array<any>): ASTElement | void {
584
596
  }
585
597
  }
586
598
 
587
- export function addIfCondition (el: ASTElement, condition: ASTIfCondition) {
599
+ export function addIfCondition(el: ASTElement, condition: ASTIfCondition) {
588
600
  if (!el.ifConditions) {
589
601
  el.ifConditions = []
590
602
  }
591
603
  el.ifConditions.push(condition)
592
604
  }
593
605
 
594
- function processOnce (el) {
606
+ function processOnce(el) {
595
607
  const once = getAndRemoveAttr(el, 'v-once')
596
608
  if (once != null) {
597
609
  el.once = true
@@ -600,17 +612,17 @@ function processOnce (el) {
600
612
 
601
613
  // handle content being passed to a component as slot,
602
614
  // e.g. <template slot="xxx">, <div slot-scope="xxx">
603
- function processSlotContent (el) {
615
+ function processSlotContent(el) {
604
616
  let slotScope
605
617
  if (el.tag === 'template') {
606
618
  slotScope = getAndRemoveAttr(el, 'scope')
607
619
  /* istanbul ignore if */
608
- if (process.env.NODE_ENV !== 'production' && slotScope) {
620
+ if (__DEV__ && slotScope) {
609
621
  warn(
610
622
  `the "scope" attribute for scoped slots have been deprecated and ` +
611
- `replaced by "slot-scope" since 2.5. The new "slot-scope" attribute ` +
612
- `can also be used on plain elements in addition to <template> to ` +
613
- `denote scoped slots.`,
623
+ `replaced by "slot-scope" since 2.5. The new "slot-scope" attribute ` +
624
+ `can also be used on plain elements in addition to <template> to ` +
625
+ `denote scoped slots.`,
614
626
  el.rawAttrsMap['scope'],
615
627
  true
616
628
  )
@@ -618,11 +630,11 @@ function processSlotContent (el) {
618
630
  el.slotScope = slotScope || getAndRemoveAttr(el, 'slot-scope')
619
631
  } else if ((slotScope = getAndRemoveAttr(el, 'slot-scope'))) {
620
632
  /* istanbul ignore if */
621
- if (process.env.NODE_ENV !== 'production' && el.attrsMap['v-for']) {
633
+ if (__DEV__ && el.attrsMap['v-for']) {
622
634
  warn(
623
635
  `Ambiguous combined usage of slot-scope and v-for on <${el.tag}> ` +
624
- `(v-for takes higher priority). Use a wrapper <template> for the ` +
625
- `scoped slot to make it clearer.`,
636
+ `(v-for takes higher priority). Use a wrapper <template> for the ` +
637
+ `scoped slot to make it clearer.`,
626
638
  el.rawAttrsMap['slot-scope'],
627
639
  true
628
640
  )
@@ -634,7 +646,9 @@ function processSlotContent (el) {
634
646
  const slotTarget = getBindingAttr(el, 'slot')
635
647
  if (slotTarget) {
636
648
  el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget
637
- el.slotTargetDynamic = !!(el.attrsMap[':slot'] || el.attrsMap['v-bind:slot'])
649
+ el.slotTargetDynamic = !!(
650
+ el.attrsMap[':slot'] || el.attrsMap['v-bind:slot']
651
+ )
638
652
  // preserve slot as an attribute for native shadow DOM compat
639
653
  // only for non-scoped slots.
640
654
  if (el.tag !== 'template' && !el.slotScope) {
@@ -648,17 +662,14 @@ function processSlotContent (el) {
648
662
  // v-slot on <template>
649
663
  const slotBinding = getAndRemoveAttrByRegex(el, slotRE)
650
664
  if (slotBinding) {
651
- if (process.env.NODE_ENV !== 'production') {
665
+ if (__DEV__) {
652
666
  if (el.slotTarget || el.slotScope) {
653
- warn(
654
- `Unexpected mixed usage of different slot syntaxes.`,
655
- el
656
- )
667
+ warn(`Unexpected mixed usage of different slot syntaxes.`, el)
657
668
  }
658
669
  if (el.parent && !maybeComponent(el.parent)) {
659
670
  warn(
660
671
  `<template v-slot> can only appear at the root level inside ` +
661
- `the receiving component`,
672
+ `the receiving component`,
662
673
  el
663
674
  )
664
675
  }
@@ -672,7 +683,7 @@ function processSlotContent (el) {
672
683
  // v-slot on component, denotes default slot
673
684
  const slotBinding = getAndRemoveAttrByRegex(el, slotRE)
674
685
  if (slotBinding) {
675
- if (process.env.NODE_ENV !== 'production') {
686
+ if (__DEV__) {
676
687
  if (!maybeComponent(el)) {
677
688
  warn(
678
689
  `v-slot can only be used on components or <template>.`,
@@ -680,15 +691,12 @@ function processSlotContent (el) {
680
691
  )
681
692
  }
682
693
  if (el.slotScope || el.slotTarget) {
683
- warn(
684
- `Unexpected mixed usage of different slot syntaxes.`,
685
- el
686
- )
694
+ warn(`Unexpected mixed usage of different slot syntaxes.`, el)
687
695
  }
688
696
  if (el.scopedSlots) {
689
697
  warn(
690
698
  `To avoid scope ambiguity, the default slot should also use ` +
691
- `<template> syntax when there are other named slots.`,
699
+ `<template> syntax when there are other named slots.`,
692
700
  slotBinding
693
701
  )
694
702
  }
@@ -696,7 +704,11 @@ function processSlotContent (el) {
696
704
  // add the component's children to its default slot
697
705
  const slots = el.scopedSlots || (el.scopedSlots = {})
698
706
  const { name, dynamic } = getSlotName(slotBinding)
699
- const slotContainer = slots[name] = createASTElement('template', [], el)
707
+ const slotContainer = (slots[name] = createASTElement(
708
+ 'template',
709
+ [],
710
+ el
711
+ ))
700
712
  slotContainer.slotTarget = name
701
713
  slotContainer.slotTargetDynamic = dynamic
702
714
  slotContainer.children = el.children.filter((c: any) => {
@@ -715,41 +727,38 @@ function processSlotContent (el) {
715
727
  }
716
728
  }
717
729
 
718
- function getSlotName (binding) {
730
+ function getSlotName(binding) {
719
731
  let name = binding.name.replace(slotRE, '')
720
732
  if (!name) {
721
733
  if (binding.name[0] !== '#') {
722
734
  name = 'default'
723
- } else if (process.env.NODE_ENV !== 'production') {
724
- warn(
725
- `v-slot shorthand syntax requires a slot name.`,
726
- binding
727
- )
735
+ } else if (__DEV__) {
736
+ warn(`v-slot shorthand syntax requires a slot name.`, binding)
728
737
  }
729
738
  }
730
739
  return dynamicArgRE.test(name)
731
- // dynamic [name]
732
- ? { name: name.slice(1, -1), dynamic: true }
733
- // static name
734
- : { name: `"${name}"`, dynamic: false }
740
+ ? // dynamic [name]
741
+ { name: name.slice(1, -1), dynamic: true }
742
+ : // static name
743
+ { name: `"${name}"`, dynamic: false }
735
744
  }
736
745
 
737
746
  // handle <slot/> outlets
738
- function processSlotOutlet (el) {
747
+ function processSlotOutlet(el) {
739
748
  if (el.tag === 'slot') {
740
749
  el.slotName = getBindingAttr(el, 'name')
741
- if (process.env.NODE_ENV !== 'production' && el.key) {
750
+ if (__DEV__ && el.key) {
742
751
  warn(
743
752
  `\`key\` does not work on <slot> because slots are abstract outlets ` +
744
- `and can possibly expand into multiple elements. ` +
745
- `Use the key on a wrapping element instead.`,
753
+ `and can possibly expand into multiple elements. ` +
754
+ `Use the key on a wrapping element instead.`,
746
755
  getRawBindingAttr(el, 'key')
747
756
  )
748
757
  }
749
758
  }
750
759
  }
751
760
 
752
- function processComponent (el) {
761
+ function processComponent(el) {
753
762
  let binding
754
763
  if ((binding = getBindingAttr(el, 'is'))) {
755
764
  el.component = binding
@@ -759,7 +768,7 @@ function processComponent (el) {
759
768
  }
760
769
  }
761
770
 
762
- function processAttrs (el) {
771
+ function processAttrs(el) {
763
772
  const list = el.attrsList
764
773
  let i, l, name, rawName, value, modifiers, syncGen, isDynamic
765
774
  for (i = 0, l = list.length; i < l; i++) {
@@ -772,22 +781,20 @@ function processAttrs (el) {
772
781
  modifiers = parseModifiers(name.replace(dirRE, ''))
773
782
  // support .foo shorthand syntax for the .prop modifier
774
783
  if (process.env.VBIND_PROP_SHORTHAND && propBindRE.test(name)) {
775
- (modifiers || (modifiers = {})).prop = true
784
+ ;(modifiers || (modifiers = {})).prop = true
776
785
  name = `.` + name.slice(1).replace(modifierRE, '')
777
786
  } else if (modifiers) {
778
787
  name = name.replace(modifierRE, '')
779
788
  }
780
- if (bindRE.test(name)) { // v-bind
789
+ if (bindRE.test(name)) {
790
+ // v-bind
781
791
  name = name.replace(bindRE, '')
782
792
  value = parseFilters(value)
783
793
  isDynamic = dynamicArgRE.test(name)
784
794
  if (isDynamic) {
785
795
  name = name.slice(1, -1)
786
796
  }
787
- if (
788
- process.env.NODE_ENV !== 'production' &&
789
- value.trim().length === 0
790
- ) {
797
+ if (__DEV__ && value.trim().length === 0) {
791
798
  warn(
792
799
  `The value for a v-bind expression cannot be empty. Found in "v-bind:${name}"`
793
800
  )
@@ -838,21 +845,24 @@ function processAttrs (el) {
838
845
  }
839
846
  }
840
847
  }
841
- if ((modifiers && modifiers.prop) || (
842
- !el.component && platformMustUseProp(el.tag, el.attrsMap.type, name)
843
- )) {
848
+ if (
849
+ (modifiers && modifiers.prop) ||
850
+ (!el.component && platformMustUseProp(el.tag, el.attrsMap.type, name))
851
+ ) {
844
852
  addProp(el, name, value, list[i], isDynamic)
845
853
  } else {
846
854
  addAttr(el, name, value, list[i], isDynamic)
847
855
  }
848
- } else if (onRE.test(name)) { // v-on
856
+ } else if (onRE.test(name)) {
857
+ // v-on
849
858
  name = name.replace(onRE, '')
850
859
  isDynamic = dynamicArgRE.test(name)
851
860
  if (isDynamic) {
852
861
  name = name.slice(1, -1)
853
862
  }
854
863
  addHandler(el, name, value, modifiers, false, warn, list[i], isDynamic)
855
- } else { // normal directives
864
+ } else {
865
+ // normal directives
856
866
  name = name.replace(dirRE, '')
857
867
  // parse arg
858
868
  const argMatch = name.match(argRE)
@@ -865,21 +875,30 @@ function processAttrs (el) {
865
875
  isDynamic = true
866
876
  }
867
877
  }
868
- addDirective(el, name, rawName, value, arg, isDynamic, modifiers, list[i])
869
- if (process.env.NODE_ENV !== 'production' && name === 'model') {
878
+ addDirective(
879
+ el,
880
+ name,
881
+ rawName,
882
+ value,
883
+ arg,
884
+ isDynamic,
885
+ modifiers,
886
+ list[i]
887
+ )
888
+ if (__DEV__ && name === 'model') {
870
889
  checkForAliasModel(el, value)
871
890
  }
872
891
  }
873
892
  } else {
874
893
  // literal attribute
875
- if (process.env.NODE_ENV !== 'production') {
894
+ if (__DEV__) {
876
895
  const res = parseText(value, delimiters)
877
896
  if (res) {
878
897
  warn(
879
898
  `${name}="${value}": ` +
880
- 'Interpolation inside attributes has been removed. ' +
881
- 'Use v-bind or the colon shorthand instead. For example, ' +
882
- 'instead of <div id="{{ val }}">, use <div :id="val">.',
899
+ 'Interpolation inside attributes has been removed. ' +
900
+ 'Use v-bind or the colon shorthand instead. For example, ' +
901
+ 'instead of <div id="{{ val }}">, use <div :id="val">.',
883
902
  list[i]
884
903
  )
885
904
  }
@@ -887,17 +906,19 @@ function processAttrs (el) {
887
906
  addAttr(el, name, JSON.stringify(value), list[i])
888
907
  // #6887 firefox doesn't update muted state if set via attribute
889
908
  // even immediately after element creation
890
- if (!el.component &&
891
- name === 'muted' &&
892
- platformMustUseProp(el.tag, el.attrsMap.type, name)) {
909
+ if (
910
+ !el.component &&
911
+ name === 'muted' &&
912
+ platformMustUseProp(el.tag, el.attrsMap.type, name)
913
+ ) {
893
914
  addProp(el, name, 'true', list[i])
894
915
  }
895
916
  }
896
917
  }
897
918
  }
898
919
 
899
- function checkInFor (el: ASTElement): boolean {
900
- let parent = el
920
+ function checkInFor(el: ASTElement): boolean {
921
+ let parent: ASTElement | void = el
901
922
  while (parent) {
902
923
  if (parent.for !== undefined) {
903
924
  return true
@@ -907,22 +928,21 @@ function checkInFor (el: ASTElement): boolean {
907
928
  return false
908
929
  }
909
930
 
910
- function parseModifiers (name: string): Object | void {
931
+ function parseModifiers(name: string): Object | void {
911
932
  const match = name.match(modifierRE)
912
933
  if (match) {
913
934
  const ret = {}
914
- match.forEach(m => { ret[m.slice(1)] = true })
935
+ match.forEach(m => {
936
+ ret[m.slice(1)] = true
937
+ })
915
938
  return ret
916
939
  }
917
940
  }
918
941
 
919
- function makeAttrsMap (attrs: Array<Object>): Object {
942
+ function makeAttrsMap(attrs: Array<Record<string, any>>): Record<string, any> {
920
943
  const map = {}
921
944
  for (let i = 0, l = attrs.length; i < l; i++) {
922
- if (
923
- process.env.NODE_ENV !== 'production' &&
924
- map[attrs[i].name] && !isIE && !isEdge
925
- ) {
945
+ if (__DEV__ && map[attrs[i].name] && !isIE && !isEdge) {
926
946
  warn('duplicate attribute: ' + attrs[i].name, attrs[i])
927
947
  }
928
948
  map[attrs[i].name] = attrs[i].value
@@ -931,17 +951,15 @@ function makeAttrsMap (attrs: Array<Object>): Object {
931
951
  }
932
952
 
933
953
  // for script (e.g. type="x/template") or style, do not decode content
934
- function isTextTag (el): boolean {
954
+ function isTextTag(el): boolean {
935
955
  return el.tag === 'script' || el.tag === 'style'
936
956
  }
937
957
 
938
- function isForbiddenTag (el): boolean {
958
+ function isForbiddenTag(el): boolean {
939
959
  return (
940
960
  el.tag === 'style' ||
941
- (el.tag === 'script' && (
942
- !el.attrsMap.type ||
943
- el.attrsMap.type === 'text/javascript'
944
- ))
961
+ (el.tag === 'script' &&
962
+ (!el.attrsMap.type || el.attrsMap.type === 'text/javascript'))
945
963
  )
946
964
  }
947
965
 
@@ -949,8 +967,8 @@ const ieNSBug = /^xmlns:NS\d+/
949
967
  const ieNSPrefix = /^NS\d+:/
950
968
 
951
969
  /* istanbul ignore next */
952
- function guardIESVGBug (attrs) {
953
- const res = []
970
+ function guardIESVGBug(attrs) {
971
+ const res: any[] = []
954
972
  for (let i = 0; i < attrs.length; i++) {
955
973
  const attr = attrs[i]
956
974
  if (!ieNSBug.test(attr.name)) {
@@ -961,16 +979,16 @@ function guardIESVGBug (attrs) {
961
979
  return res
962
980
  }
963
981
 
964
- function checkForAliasModel (el, value) {
982
+ function checkForAliasModel(el, value) {
965
983
  let _el = el
966
984
  while (_el) {
967
985
  if (_el.for && _el.alias === value) {
968
986
  warn(
969
987
  `<${el.tag} v-model="${value}">: ` +
970
- `You are binding v-model directly to a v-for iteration alias. ` +
971
- `This will not be able to modify the v-for source array because ` +
972
- `writing to the alias is like modifying a function local variable. ` +
973
- `Consider using an array of objects and use v-model on an object property instead.`,
988
+ `You are binding v-model directly to a v-for iteration alias. ` +
989
+ `This will not be able to modify the v-for source array because ` +
990
+ `writing to the alias is like modifying a function local variable. ` +
991
+ `Consider using an array of objects and use v-model on an object property instead.`,
974
992
  el.rawAttrsMap['v-model']
975
993
  )
976
994
  }