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,264 +0,0 @@
1
- /* @flow */
2
-
3
- // The SSR codegen is essentially extending the default codegen to handle
4
- // SSR-optimizable nodes and turn them into string render fns. In cases where
5
- // a node is not optimizable it simply falls back to the default codegen.
6
-
7
- import {
8
- genIf,
9
- genFor,
10
- genData,
11
- genText,
12
- genElement,
13
- genChildren,
14
- CodegenState
15
- } from 'compiler/codegen/index'
16
-
17
- import {
18
- genAttrSegments,
19
- genDOMPropSegments,
20
- genClassSegments,
21
- genStyleSegments,
22
- applyModelTransform
23
- } from './modules'
24
-
25
- import { escape } from 'web/server/util'
26
- import { optimizability } from './optimizer'
27
- import type { CodegenResult } from 'compiler/codegen/index'
28
-
29
- export type StringSegment = {
30
- type: number;
31
- value: string;
32
- };
33
-
34
- // segment types
35
- export const RAW = 0
36
- export const INTERPOLATION = 1
37
- export const EXPRESSION = 2
38
-
39
- export function generate (
40
- ast: ASTElement | void,
41
- options: CompilerOptions
42
- ): CodegenResult {
43
- const state = new CodegenState(options)
44
- const code = ast ? genSSRElement(ast, state) : '_c("div")'
45
- return {
46
- render: `with(this){return ${code}}`,
47
- staticRenderFns: state.staticRenderFns
48
- }
49
- }
50
-
51
- function genSSRElement (el: ASTElement, state: CodegenState): string {
52
- if (el.for && !el.forProcessed) {
53
- return genFor(el, state, genSSRElement)
54
- } else if (el.if && !el.ifProcessed) {
55
- return genIf(el, state, genSSRElement)
56
- } else if (el.tag === 'template' && !el.slotTarget) {
57
- return el.ssrOptimizability === optimizability.FULL
58
- ? genChildrenAsStringNode(el, state)
59
- : genSSRChildren(el, state) || 'void 0'
60
- }
61
-
62
- switch (el.ssrOptimizability) {
63
- case optimizability.FULL:
64
- // stringify whole tree
65
- return genStringElement(el, state)
66
- case optimizability.SELF:
67
- // stringify self and check children
68
- return genStringElementWithChildren(el, state)
69
- case optimizability.CHILDREN:
70
- // generate self as VNode and stringify children
71
- return genNormalElement(el, state, true)
72
- case optimizability.PARTIAL:
73
- // generate self as VNode and check children
74
- return genNormalElement(el, state, false)
75
- default:
76
- // bail whole tree
77
- return genElement(el, state)
78
- }
79
- }
80
-
81
- function genNormalElement (el, state, stringifyChildren) {
82
- const data = el.plain ? undefined : genData(el, state)
83
- const children = stringifyChildren
84
- ? `[${genChildrenAsStringNode(el, state)}]`
85
- : genSSRChildren(el, state, true)
86
- return `_c('${el.tag}'${
87
- data ? `,${data}` : ''
88
- }${
89
- children ? `,${children}` : ''
90
- })`
91
- }
92
-
93
- function genSSRChildren (el, state, checkSkip) {
94
- return genChildren(el, state, checkSkip, genSSRElement, genSSRNode)
95
- }
96
-
97
- function genSSRNode (el, state) {
98
- return el.type === 1
99
- ? genSSRElement(el, state)
100
- : genText(el)
101
- }
102
-
103
- function genChildrenAsStringNode (el, state) {
104
- return el.children.length
105
- ? `_ssrNode(${flattenSegments(childrenToSegments(el, state))})`
106
- : ''
107
- }
108
-
109
- function genStringElement (el, state) {
110
- return `_ssrNode(${elementToString(el, state)})`
111
- }
112
-
113
- function genStringElementWithChildren (el, state) {
114
- const children = genSSRChildren(el, state, true)
115
- return `_ssrNode(${
116
- flattenSegments(elementToOpenTagSegments(el, state))
117
- },"</${el.tag}>"${
118
- children ? `,${children}` : ''
119
- })`
120
- }
121
-
122
- function elementToString (el, state) {
123
- return `(${flattenSegments(elementToSegments(el, state))})`
124
- }
125
-
126
- function elementToSegments (el, state): Array<StringSegment> {
127
- // v-for / v-if
128
- if (el.for && !el.forProcessed) {
129
- el.forProcessed = true
130
- return [{
131
- type: EXPRESSION,
132
- value: genFor(el, state, elementToString, '_ssrList')
133
- }]
134
- } else if (el.if && !el.ifProcessed) {
135
- el.ifProcessed = true
136
- return [{
137
- type: EXPRESSION,
138
- value: genIf(el, state, elementToString, '"<!---->"')
139
- }]
140
- } else if (el.tag === 'template') {
141
- return childrenToSegments(el, state)
142
- }
143
-
144
- const openSegments = elementToOpenTagSegments(el, state)
145
- const childrenSegments = childrenToSegments(el, state)
146
- const { isUnaryTag } = state.options
147
- const close = (isUnaryTag && isUnaryTag(el.tag))
148
- ? []
149
- : [{ type: RAW, value: `</${el.tag}>` }]
150
- return openSegments.concat(childrenSegments, close)
151
- }
152
-
153
- function elementToOpenTagSegments (el, state): Array<StringSegment> {
154
- applyModelTransform(el, state)
155
- let binding
156
- const segments = [{ type: RAW, value: `<${el.tag}` }]
157
- // attrs
158
- if (el.attrs) {
159
- segments.push.apply(segments, genAttrSegments(el.attrs))
160
- }
161
- // domProps
162
- if (el.props) {
163
- segments.push.apply(segments, genDOMPropSegments(el.props, el.attrs))
164
- }
165
- // v-bind="object"
166
- if ((binding = el.attrsMap['v-bind'])) {
167
- segments.push({ type: EXPRESSION, value: `_ssrAttrs(${binding})` })
168
- }
169
- // v-bind.prop="object"
170
- if ((binding = el.attrsMap['v-bind.prop'])) {
171
- segments.push({ type: EXPRESSION, value: `_ssrDOMProps(${binding})` })
172
- }
173
- // class
174
- if (el.staticClass || el.classBinding) {
175
- segments.push.apply(
176
- segments,
177
- genClassSegments(el.staticClass, el.classBinding)
178
- )
179
- }
180
- // style & v-show
181
- if (el.staticStyle || el.styleBinding || el.attrsMap['v-show']) {
182
- segments.push.apply(
183
- segments,
184
- genStyleSegments(
185
- el.attrsMap.style,
186
- el.staticStyle,
187
- el.styleBinding,
188
- el.attrsMap['v-show']
189
- )
190
- )
191
- }
192
- // _scopedId
193
- if (state.options.scopeId) {
194
- segments.push({ type: RAW, value: ` ${state.options.scopeId}` })
195
- }
196
- segments.push({ type: RAW, value: `>` })
197
- return segments
198
- }
199
-
200
- function childrenToSegments (el, state): Array<StringSegment> {
201
- let binding
202
- if ((binding = el.attrsMap['v-html'])) {
203
- return [{ type: EXPRESSION, value: `_s(${binding})` }]
204
- }
205
- if ((binding = el.attrsMap['v-text'])) {
206
- return [{ type: INTERPOLATION, value: `_s(${binding})` }]
207
- }
208
- if (el.tag === 'textarea' && (binding = el.attrsMap['v-model'])) {
209
- return [{ type: INTERPOLATION, value: `_s(${binding})` }]
210
- }
211
- return el.children
212
- ? nodesToSegments(el.children, state)
213
- : []
214
- }
215
-
216
- function nodesToSegments (
217
- children: Array<ASTNode>,
218
- state: CodegenState
219
- ): Array<StringSegment> {
220
- const segments = []
221
- for (let i = 0; i < children.length; i++) {
222
- const c = children[i]
223
- if (c.type === 1) {
224
- segments.push.apply(segments, elementToSegments(c, state))
225
- } else if (c.type === 2) {
226
- segments.push({ type: INTERPOLATION, value: c.expression })
227
- } else if (c.type === 3) {
228
- let text = escape(c.text)
229
- if (c.isComment) {
230
- text = '<!--' + text + '-->'
231
- }
232
- segments.push({ type: RAW, value: text })
233
- }
234
- }
235
- return segments
236
- }
237
-
238
- function flattenSegments (segments: Array<StringSegment>): string {
239
- const mergedSegments = []
240
- let textBuffer = ''
241
-
242
- const pushBuffer = () => {
243
- if (textBuffer) {
244
- mergedSegments.push(JSON.stringify(textBuffer))
245
- textBuffer = ''
246
- }
247
- }
248
-
249
- for (let i = 0; i < segments.length; i++) {
250
- const s = segments[i]
251
- if (s.type === RAW) {
252
- textBuffer += s.value
253
- } else if (s.type === INTERPOLATION) {
254
- pushBuffer()
255
- mergedSegments.push(`_ssrEscape(${s.value})`)
256
- } else if (s.type === EXPRESSION) {
257
- pushBuffer()
258
- mergedSegments.push(`(${s.value})`)
259
- }
260
- }
261
- pushBuffer()
262
-
263
- return mergedSegments.join('+')
264
- }
@@ -1,20 +0,0 @@
1
- /* @flow */
2
-
3
- import { parse } from 'compiler/parser/index'
4
- import { generate } from './codegen'
5
- import { optimize } from './optimizer'
6
- import { createCompilerCreator } from 'compiler/create-compiler'
7
-
8
- export const createCompiler = createCompilerCreator(function baseCompile (
9
- template: string,
10
- options: CompilerOptions
11
- ): CompiledResult {
12
- const ast = parse(template.trim(), options)
13
- optimize(ast, options)
14
- const code = generate(ast, options)
15
- return {
16
- ast,
17
- render: code.render,
18
- staticRenderFns: code.staticRenderFns
19
- }
20
- })
@@ -1,124 +0,0 @@
1
- /* @flow */
2
-
3
- import {
4
- RAW,
5
- // INTERPOLATION,
6
- EXPRESSION
7
- } from './codegen'
8
-
9
- import {
10
- propsToAttrMap,
11
- isRenderableAttr
12
- } from 'web/server/util'
13
-
14
- import {
15
- isBooleanAttr,
16
- isEnumeratedAttr
17
- } from 'web/util/attrs'
18
-
19
- import type { StringSegment } from './codegen'
20
- import type { CodegenState } from 'compiler/codegen/index'
21
-
22
- const plainStringRE = /^"(?:[^"\\]|\\.)*"$|^'(?:[^'\\]|\\.)*'$/
23
-
24
- // let the model AST transform translate v-model into appropriate
25
- // props bindings
26
- export function applyModelTransform (el: ASTElement, state: CodegenState) {
27
- if (el.directives) {
28
- for (let i = 0; i < el.directives.length; i++) {
29
- const dir = el.directives[i]
30
- if (dir.name === 'model') {
31
- state.directives.model(el, dir, state.warn)
32
- // remove value for textarea as its converted to text
33
- if (el.tag === 'textarea' && el.props) {
34
- el.props = el.props.filter(p => p.name !== 'value')
35
- }
36
- break
37
- }
38
- }
39
- }
40
- }
41
-
42
- export function genAttrSegments (
43
- attrs: Array<ASTAttr>
44
- ): Array<StringSegment> {
45
- return attrs.map(({ name, value }) => genAttrSegment(name, value))
46
- }
47
-
48
- export function genDOMPropSegments (
49
- props: Array<ASTAttr>,
50
- attrs: ?Array<ASTAttr>
51
- ): Array<StringSegment> {
52
- const segments = []
53
- props.forEach(({ name, value }) => {
54
- name = propsToAttrMap[name] || name.toLowerCase()
55
- if (isRenderableAttr(name) &&
56
- !(attrs && attrs.some(a => a.name === name))
57
- ) {
58
- segments.push(genAttrSegment(name, value))
59
- }
60
- })
61
- return segments
62
- }
63
-
64
- function genAttrSegment (name: string, value: string): StringSegment {
65
- if (plainStringRE.test(value)) {
66
- // force double quote
67
- value = value.replace(/^'|'$/g, '"')
68
- // force enumerated attr to "true"
69
- if (isEnumeratedAttr(name) && value !== `"false"`) {
70
- value = `"true"`
71
- }
72
- return {
73
- type: RAW,
74
- value: isBooleanAttr(name)
75
- ? ` ${name}="${name}"`
76
- : value === '""'
77
- ? ` ${name}`
78
- : ` ${name}="${JSON.parse(value)}"`
79
- }
80
- } else {
81
- return {
82
- type: EXPRESSION,
83
- value: `_ssrAttr(${JSON.stringify(name)},${value})`
84
- }
85
- }
86
- }
87
-
88
- export function genClassSegments (
89
- staticClass: ?string,
90
- classBinding: ?string
91
- ): Array<StringSegment> {
92
- if (staticClass && !classBinding) {
93
- return [{ type: RAW, value: ` class="${JSON.parse(staticClass)}"` }]
94
- } else {
95
- return [{
96
- type: EXPRESSION,
97
- value: `_ssrClass(${staticClass || 'null'},${classBinding || 'null'})`
98
- }]
99
- }
100
- }
101
-
102
- export function genStyleSegments (
103
- staticStyle: ?string,
104
- parsedStaticStyle: ?string,
105
- styleBinding: ?string,
106
- vShowExpression: ?string
107
- ): Array<StringSegment> {
108
- if (staticStyle && !styleBinding && !vShowExpression) {
109
- return [{ type: RAW, value: ` style=${JSON.stringify(staticStyle)}` }]
110
- } else {
111
- return [{
112
- type: EXPRESSION,
113
- value: `_ssrStyle(${
114
- parsedStaticStyle || 'null'
115
- },${
116
- styleBinding || 'null'
117
- }, ${
118
- vShowExpression
119
- ? `{ display: (${vShowExpression}) ? '' : 'none' }`
120
- : 'null'
121
- })`
122
- }]
123
- }
124
- }
@@ -1,141 +0,0 @@
1
- /* @flow */
2
-
3
- /**
4
- * In SSR, the vdom tree is generated only once and never patched, so
5
- * we can optimize most element / trees into plain string render functions.
6
- * The SSR optimizer walks the AST tree to detect optimizable elements and trees.
7
- *
8
- * The criteria for SSR optimizability is quite a bit looser than static tree
9
- * detection (which is designed for client re-render). In SSR we bail only for
10
- * components/slots/custom directives.
11
- */
12
-
13
- import { no, makeMap, isBuiltInTag } from 'shared/util'
14
-
15
- // optimizability constants
16
- export const optimizability = {
17
- FALSE: 0, // whole sub tree un-optimizable
18
- FULL: 1, // whole sub tree optimizable
19
- SELF: 2, // self optimizable but has some un-optimizable children
20
- CHILDREN: 3, // self un-optimizable but have fully optimizable children
21
- PARTIAL: 4 // self un-optimizable with some un-optimizable children
22
- }
23
-
24
- let isPlatformReservedTag
25
-
26
- export function optimize (root: ?ASTElement, options: CompilerOptions) {
27
- if (!root) return
28
- isPlatformReservedTag = options.isReservedTag || no
29
- walk(root, true)
30
- }
31
-
32
- function walk (node: ASTNode, isRoot?: boolean) {
33
- if (isUnOptimizableTree(node)) {
34
- node.ssrOptimizability = optimizability.FALSE
35
- return
36
- }
37
- // root node or nodes with custom directives should always be a VNode
38
- const selfUnoptimizable = isRoot || hasCustomDirective(node)
39
- const check = child => {
40
- if (child.ssrOptimizability !== optimizability.FULL) {
41
- node.ssrOptimizability = selfUnoptimizable
42
- ? optimizability.PARTIAL
43
- : optimizability.SELF
44
- }
45
- }
46
- if (selfUnoptimizable) {
47
- node.ssrOptimizability = optimizability.CHILDREN
48
- }
49
- if (node.type === 1) {
50
- for (let i = 0, l = node.children.length; i < l; i++) {
51
- const child = node.children[i]
52
- walk(child)
53
- check(child)
54
- }
55
- if (node.ifConditions) {
56
- for (let i = 1, l = node.ifConditions.length; i < l; i++) {
57
- const block = node.ifConditions[i].block
58
- walk(block, isRoot)
59
- check(block)
60
- }
61
- }
62
- if (node.ssrOptimizability == null ||
63
- (!isRoot && (node.attrsMap['v-html'] || node.attrsMap['v-text']))
64
- ) {
65
- node.ssrOptimizability = optimizability.FULL
66
- } else {
67
- node.children = optimizeSiblings(node)
68
- }
69
- } else {
70
- node.ssrOptimizability = optimizability.FULL
71
- }
72
- }
73
-
74
- function optimizeSiblings (el) {
75
- const children = el.children
76
- const optimizedChildren = []
77
-
78
- let currentOptimizableGroup = []
79
- const pushGroup = () => {
80
- if (currentOptimizableGroup.length) {
81
- optimizedChildren.push({
82
- type: 1,
83
- parent: el,
84
- tag: 'template',
85
- attrsList: [],
86
- attrsMap: {},
87
- rawAttrsMap: {},
88
- children: currentOptimizableGroup,
89
- ssrOptimizability: optimizability.FULL
90
- })
91
- }
92
- currentOptimizableGroup = []
93
- }
94
-
95
- for (let i = 0; i < children.length; i++) {
96
- const c = children[i]
97
- if (c.ssrOptimizability === optimizability.FULL) {
98
- currentOptimizableGroup.push(c)
99
- } else {
100
- // wrap fully-optimizable adjacent siblings inside a template tag
101
- // so that they can be optimized into a single ssrNode by codegen
102
- pushGroup()
103
- optimizedChildren.push(c)
104
- }
105
- }
106
- pushGroup()
107
- return optimizedChildren
108
- }
109
-
110
- function isUnOptimizableTree (node: ASTNode): boolean {
111
- if (node.type === 2 || node.type === 3) { // text or expression
112
- return false
113
- }
114
- return (
115
- isBuiltInTag(node.tag) || // built-in (slot, component)
116
- !isPlatformReservedTag(node.tag) || // custom component
117
- !!node.component || // "is" component
118
- isSelectWithModel(node) // <select v-model> requires runtime inspection
119
- )
120
- }
121
-
122
- const isBuiltInDir = makeMap('text,html,show,on,bind,model,pre,cloak,once')
123
-
124
- function hasCustomDirective (node: ASTNode): ?boolean {
125
- return (
126
- node.type === 1 &&
127
- node.directives &&
128
- node.directives.some(d => !isBuiltInDir(d.name))
129
- )
130
- }
131
-
132
- // <select v-model> cannot be optimized because it requires a runtime check
133
- // to determine proper selected option
134
- function isSelectWithModel (node: ASTNode): boolean {
135
- return (
136
- node.type === 1 &&
137
- node.tag === 'select' &&
138
- node.directives != null &&
139
- node.directives.some(d => d.name === 'model')
140
- )
141
- }
@@ -1,150 +0,0 @@
1
- /* @flow */
2
-
3
- import { escape, isSSRUnsafeAttr } from 'web/server/util'
4
- import { isObject, extend } from 'shared/util'
5
- import { renderAttr } from 'web/server/modules/attrs'
6
- import { renderClass } from 'web/util/class'
7
- import { genStyle } from 'web/server/modules/style'
8
- import { normalizeStyleBinding } from 'web/util/style'
9
-
10
- import {
11
- normalizeChildren,
12
- simpleNormalizeChildren
13
- } from 'core/vdom/helpers/normalize-children'
14
-
15
- import {
16
- propsToAttrMap,
17
- isRenderableAttr
18
- } from 'web/server/util'
19
-
20
- const ssrHelpers = {
21
- _ssrEscape: escape,
22
- _ssrNode: renderStringNode,
23
- _ssrList: renderStringList,
24
- _ssrAttr: renderAttr,
25
- _ssrAttrs: renderAttrs,
26
- _ssrDOMProps: renderDOMProps,
27
- _ssrClass: renderSSRClass,
28
- _ssrStyle: renderSSRStyle
29
- }
30
-
31
- export function installSSRHelpers (vm: Component) {
32
- if (vm._ssrNode) {
33
- return
34
- }
35
- let Vue = vm.constructor
36
- while (Vue.super) {
37
- Vue = Vue.super
38
- }
39
- extend(Vue.prototype, ssrHelpers)
40
- if (Vue.FunctionalRenderContext) {
41
- extend(Vue.FunctionalRenderContext.prototype, ssrHelpers)
42
- }
43
- }
44
-
45
- class StringNode {
46
- isString: boolean;
47
- open: string;
48
- close: ?string;
49
- children: ?Array<any>;
50
-
51
- constructor (
52
- open: string,
53
- close?: string,
54
- children?: Array<any>,
55
- normalizationType?: number
56
- ) {
57
- this.isString = true
58
- this.open = open
59
- this.close = close
60
- if (children) {
61
- this.children = normalizationType === 1
62
- ? simpleNormalizeChildren(children)
63
- : normalizationType === 2
64
- ? normalizeChildren(children)
65
- : children
66
- } else {
67
- this.children = void 0
68
- }
69
- }
70
- }
71
-
72
- function renderStringNode (
73
- open: string,
74
- close?: string,
75
- children?: Array<any>,
76
- normalizationType?: number
77
- ): StringNode {
78
- return new StringNode(open, close, children, normalizationType)
79
- }
80
-
81
- function renderStringList (
82
- val: any,
83
- render: (
84
- val: any,
85
- keyOrIndex: string | number,
86
- index?: number
87
- ) => string
88
- ): string {
89
- let ret = ''
90
- let i, l, keys, key
91
- if (Array.isArray(val) || typeof val === 'string') {
92
- for (i = 0, l = val.length; i < l; i++) {
93
- ret += render(val[i], i)
94
- }
95
- } else if (typeof val === 'number') {
96
- for (i = 0; i < val; i++) {
97
- ret += render(i + 1, i)
98
- }
99
- } else if (isObject(val)) {
100
- keys = Object.keys(val)
101
- for (i = 0, l = keys.length; i < l; i++) {
102
- key = keys[i]
103
- ret += render(val[key], key, i)
104
- }
105
- }
106
- return ret
107
- }
108
-
109
- function renderAttrs (obj: Object): string {
110
- let res = ''
111
- for (const key in obj) {
112
- if (isSSRUnsafeAttr(key)) {
113
- continue
114
- }
115
- res += renderAttr(key, obj[key])
116
- }
117
- return res
118
- }
119
-
120
- function renderDOMProps (obj: Object): string {
121
- let res = ''
122
- for (const key in obj) {
123
- const attr = propsToAttrMap[key] || key.toLowerCase()
124
- if (isRenderableAttr(attr)) {
125
- res += renderAttr(attr, obj[key])
126
- }
127
- }
128
- return res
129
- }
130
-
131
- function renderSSRClass (
132
- staticClass: ?string,
133
- dynamic: any
134
- ): string {
135
- const res = renderClass(staticClass, dynamic)
136
- return res === '' ? res : ` class="${escape(res)}"`
137
- }
138
-
139
- function renderSSRStyle (
140
- staticStyle: ?Object,
141
- dynamic: any,
142
- extra: ?Object
143
- ): string {
144
- const style = {}
145
- if (staticStyle) extend(style, staticStyle)
146
- if (dynamic) extend(style, normalizeStyleBinding(dynamic))
147
- if (extra) extend(style, extra)
148
- const res = genStyle(style)
149
- return res === '' ? res : ` style=${JSON.stringify(escape(res))}`
150
- }