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,40 +0,0 @@
1
- /* @flow */
2
- declare var document: WeexDocument;
3
-
4
- import { warn } from 'core/util/index'
5
-
6
- export const RECYCLE_LIST_MARKER = '@inRecycleList'
7
-
8
- // Register the component hook to weex native render engine.
9
- // The hook will be triggered by native, not javascript.
10
- export function registerComponentHook (
11
- componentId: string,
12
- type: string, // hook type, could be "lifecycle" or "instance"
13
- hook: string, // hook name
14
- fn: Function
15
- ) {
16
- if (!document || !document.taskCenter) {
17
- warn(`Can't find available "document" or "taskCenter".`)
18
- return
19
- }
20
- if (typeof document.taskCenter.registerHook === 'function') {
21
- return document.taskCenter.registerHook(componentId, type, hook, fn)
22
- }
23
- warn(`Failed to register component hook "${type}@${hook}#${componentId}".`)
24
- }
25
-
26
- // Updates the state of the component to weex native render engine.
27
- export function updateComponentData (
28
- componentId: string,
29
- newData: Object | void,
30
- callback?: Function
31
- ) {
32
- if (!document || !document.taskCenter) {
33
- warn(`Can't find available "document" or "taskCenter".`)
34
- return
35
- }
36
- if (typeof document.taskCenter.updateData === 'function') {
37
- return document.taskCenter.updateData(componentId, newData, callback)
38
- }
39
- warn(`Failed to update component data (${componentId}).`)
40
- }
@@ -1,60 +0,0 @@
1
- /* @flow */
2
-
3
- // import { warn } from 'core/util/index'
4
-
5
- // this will be preserved during build
6
- // $flow-disable-line
7
- const acorn = require('acorn') // $flow-disable-line
8
- const walk = require('acorn/dist/walk') // $flow-disable-line
9
- const escodegen = require('escodegen')
10
-
11
- export function nodeToBinding (node: Object): any {
12
- switch (node.type) {
13
- case 'Literal': return node.value
14
- case 'Identifier':
15
- case 'UnaryExpression':
16
- case 'BinaryExpression':
17
- case 'LogicalExpression':
18
- case 'ConditionalExpression':
19
- case 'MemberExpression': return { '@binding': escodegen.generate(node) }
20
- case 'ArrayExpression': return node.elements.map(_ => nodeToBinding(_))
21
- case 'ObjectExpression': {
22
- const object = {}
23
- node.properties.forEach(prop => {
24
- if (!prop.key || prop.key.type !== 'Identifier') {
25
- return
26
- }
27
- const key = escodegen.generate(prop.key)
28
- const value = nodeToBinding(prop.value)
29
- if (key && value) {
30
- object[key] = value
31
- }
32
- })
33
- return object
34
- }
35
- default: {
36
- // warn(`Not support ${node.type}: "${escodegen.generate(node)}"`)
37
- return ''
38
- }
39
- }
40
- }
41
-
42
- export function generateBinding (exp: ?string): any {
43
- if (exp && typeof exp === 'string') {
44
- let ast = null
45
- try {
46
- ast = acorn.parse(`(${exp})`)
47
- } catch (e) {
48
- // warn(`Failed to parse the expression: "${exp}"`)
49
- return ''
50
- }
51
-
52
- let output = ''
53
- walk.simple(ast, {
54
- Expression (node) {
55
- output = nodeToBinding(node)
56
- }
57
- })
58
- return output
59
- }
60
- }
@@ -1,151 +0,0 @@
1
- /* @flow */
2
-
3
- import { createPromiseCallback } from '../util'
4
- import { createBundleRunner } from './create-bundle-runner'
5
- import type { Renderer, RenderOptions } from '../create-renderer'
6
- import { createSourceMapConsumers, rewriteErrorTrace } from './source-map-support'
7
-
8
- const fs = require('fs')
9
- const path = require('path')
10
- const PassThrough = require('stream').PassThrough
11
-
12
- const INVALID_MSG =
13
- 'Invalid server-rendering bundle format. Should be a string ' +
14
- 'or a bundle Object of type:\n\n' +
15
- `{
16
- entry: string;
17
- files: { [filename: string]: string; };
18
- maps: { [filename: string]: string; };
19
- }\n`
20
-
21
- // The render bundle can either be a string (single bundled file)
22
- // or a bundle manifest object generated by vue-ssr-webpack-plugin.
23
- type RenderBundle = {
24
- basedir?: string;
25
- entry: string;
26
- files: { [filename: string]: string; };
27
- maps: { [filename: string]: string; };
28
- modules?: { [filename: string]: Array<string> };
29
- };
30
-
31
- export function createBundleRendererCreator (
32
- createRenderer: (options?: RenderOptions) => Renderer
33
- ) {
34
- return function createBundleRenderer (
35
- bundle: string | RenderBundle,
36
- rendererOptions?: RenderOptions = {}
37
- ) {
38
- let files, entry, maps
39
- let basedir = rendererOptions.basedir
40
-
41
- // load bundle if given filepath
42
- if (
43
- typeof bundle === 'string' &&
44
- /\.js(on)?$/.test(bundle) &&
45
- path.isAbsolute(bundle)
46
- ) {
47
- if (fs.existsSync(bundle)) {
48
- const isJSON = /\.json$/.test(bundle)
49
- basedir = basedir || path.dirname(bundle)
50
- bundle = fs.readFileSync(bundle, 'utf-8')
51
- if (isJSON) {
52
- try {
53
- bundle = JSON.parse(bundle)
54
- } catch (e) {
55
- throw new Error(`Invalid JSON bundle file: ${bundle}`)
56
- }
57
- }
58
- } else {
59
- throw new Error(`Cannot locate bundle file: ${bundle}`)
60
- }
61
- }
62
-
63
- if (typeof bundle === 'object') {
64
- entry = bundle.entry
65
- files = bundle.files
66
- basedir = basedir || bundle.basedir
67
- maps = createSourceMapConsumers(bundle.maps)
68
- if (typeof entry !== 'string' || typeof files !== 'object') {
69
- throw new Error(INVALID_MSG)
70
- }
71
- } else if (typeof bundle === 'string') {
72
- entry = '__vue_ssr_bundle__'
73
- files = { '__vue_ssr_bundle__': bundle }
74
- maps = {}
75
- } else {
76
- throw new Error(INVALID_MSG)
77
- }
78
-
79
- const renderer = createRenderer(rendererOptions)
80
-
81
- const run = createBundleRunner(
82
- entry,
83
- files,
84
- basedir,
85
- rendererOptions.runInNewContext
86
- )
87
-
88
- return {
89
- renderToString: (context?: Object, cb: any) => {
90
- if (typeof context === 'function') {
91
- cb = context
92
- context = {}
93
- }
94
-
95
- let promise
96
- if (!cb) {
97
- ({ promise, cb } = createPromiseCallback())
98
- }
99
-
100
- run(context).catch(err => {
101
- rewriteErrorTrace(err, maps)
102
- cb(err)
103
- }).then(app => {
104
- if (app) {
105
- renderer.renderToString(app, context, (err, res) => {
106
- rewriteErrorTrace(err, maps)
107
- cb(err, res)
108
- })
109
- }
110
- })
111
-
112
- return promise
113
- },
114
-
115
- renderToStream: (context?: Object) => {
116
- const res = new PassThrough()
117
- run(context).catch(err => {
118
- rewriteErrorTrace(err, maps)
119
- // avoid emitting synchronously before user can
120
- // attach error listener
121
- process.nextTick(() => {
122
- res.emit('error', err)
123
- })
124
- }).then(app => {
125
- if (app) {
126
- const renderStream = renderer.renderToStream(app, context)
127
-
128
- renderStream.on('error', err => {
129
- rewriteErrorTrace(err, maps)
130
- res.emit('error', err)
131
- })
132
-
133
- // relay HTMLStream special events
134
- if (rendererOptions && rendererOptions.template) {
135
- renderStream.on('beforeStart', () => {
136
- res.emit('beforeStart')
137
- })
138
- renderStream.on('beforeEnd', () => {
139
- res.emit('beforeEnd')
140
- })
141
- }
142
-
143
- renderStream.pipe(res)
144
- }
145
- })
146
-
147
- return res
148
- }
149
- }
150
- }
151
- }
@@ -1,150 +0,0 @@
1
- import { isPlainObject } from 'shared/util'
2
-
3
- const vm = require('vm')
4
- const path = require('path')
5
- const resolve = require('resolve')
6
- const NativeModule = require('module')
7
-
8
- function createSandbox (context) {
9
- const sandbox = {
10
- Buffer,
11
- console,
12
- process,
13
- setTimeout,
14
- setInterval,
15
- setImmediate,
16
- clearTimeout,
17
- clearInterval,
18
- clearImmediate,
19
- __VUE_SSR_CONTEXT__: context
20
- }
21
- sandbox.global = sandbox
22
- return sandbox
23
- }
24
-
25
- function compileModule (files, basedir, runInNewContext) {
26
- const compiledScripts = {}
27
- const resolvedModules = {}
28
-
29
- function getCompiledScript (filename) {
30
- if (compiledScripts[filename]) {
31
- return compiledScripts[filename]
32
- }
33
- const code = files[filename]
34
- const wrapper = NativeModule.wrap(code)
35
- const script = new vm.Script(wrapper, {
36
- filename,
37
- displayErrors: true
38
- })
39
- compiledScripts[filename] = script
40
- return script
41
- }
42
-
43
- function evaluateModule (filename, sandbox, evaluatedFiles = {}) {
44
- if (evaluatedFiles[filename]) {
45
- return evaluatedFiles[filename]
46
- }
47
-
48
- const script = getCompiledScript(filename)
49
- const compiledWrapper = runInNewContext === false
50
- ? script.runInThisContext()
51
- : script.runInNewContext(sandbox)
52
- const m = { exports: {}}
53
- const r = file => {
54
- file = path.posix.join('.', file)
55
- if (files[file]) {
56
- return evaluateModule(file, sandbox, evaluatedFiles)
57
- } else if (basedir) {
58
- return require(
59
- resolvedModules[file] ||
60
- (resolvedModules[file] = resolve.sync(file, { basedir }))
61
- )
62
- } else {
63
- return require(file)
64
- }
65
- }
66
- compiledWrapper.call(m.exports, m.exports, r, m)
67
-
68
- const res = Object.prototype.hasOwnProperty.call(m.exports, 'default')
69
- ? m.exports.default
70
- : m.exports
71
- evaluatedFiles[filename] = res
72
- return res
73
- }
74
- return evaluateModule
75
- }
76
-
77
- function deepClone (val) {
78
- if (isPlainObject(val)) {
79
- const res = {}
80
- for (const key in val) {
81
- res[key] = deepClone(val[key])
82
- }
83
- return res
84
- } else if (Array.isArray(val)) {
85
- return val.slice()
86
- } else {
87
- return val
88
- }
89
- }
90
-
91
- export function createBundleRunner (entry, files, basedir, runInNewContext) {
92
- const evaluate = compileModule(files, basedir, runInNewContext)
93
- if (runInNewContext !== false && runInNewContext !== 'once') {
94
- // new context mode: creates a fresh context and re-evaluate the bundle
95
- // on each render. Ensures entire application state is fresh for each
96
- // render, but incurs extra evaluation cost.
97
- return (userContext = {}) => new Promise(resolve => {
98
- userContext._registeredComponents = new Set()
99
- const res = evaluate(entry, createSandbox(userContext))
100
- resolve(typeof res === 'function' ? res(userContext) : res)
101
- })
102
- } else {
103
- // direct mode: instead of re-evaluating the whole bundle on
104
- // each render, it simply calls the exported function. This avoids the
105
- // module evaluation costs but requires the source code to be structured
106
- // slightly differently.
107
- let runner // lazy creation so that errors can be caught by user
108
- let initialContext
109
- return (userContext = {}) => new Promise(resolve => {
110
- if (!runner) {
111
- const sandbox = runInNewContext === 'once'
112
- ? createSandbox()
113
- : global
114
- // the initial context is only used for collecting possible non-component
115
- // styles injected by vue-style-loader.
116
- initialContext = sandbox.__VUE_SSR_CONTEXT__ = {}
117
- runner = evaluate(entry, sandbox)
118
- // On subsequent renders, __VUE_SSR_CONTEXT__ will not be available
119
- // to prevent cross-request pollution.
120
- delete sandbox.__VUE_SSR_CONTEXT__
121
- if (typeof runner !== 'function') {
122
- throw new Error(
123
- 'bundle export should be a function when using ' +
124
- '{ runInNewContext: false }.'
125
- )
126
- }
127
- }
128
- userContext._registeredComponents = new Set()
129
-
130
- // vue-style-loader styles imported outside of component lifecycle hooks
131
- if (initialContext._styles) {
132
- userContext._styles = deepClone(initialContext._styles)
133
- // #6353 ensure "styles" is exposed even if no styles are injected
134
- // in component lifecycles.
135
- // the renderStyles fn is exposed by vue-style-loader >= 3.0.3
136
- const renderStyles = initialContext._renderStyles
137
- if (renderStyles) {
138
- Object.defineProperty(userContext, 'styles', {
139
- enumerable: true,
140
- get () {
141
- return renderStyles(userContext._styles)
142
- }
143
- })
144
- }
145
- }
146
-
147
- resolve(runner(userContext))
148
- })
149
- }
150
- }
@@ -1,45 +0,0 @@
1
- /* @flow */
2
-
3
- const SourceMapConsumer = require('source-map').SourceMapConsumer
4
-
5
- const filenameRE = /\(([^)]+\.js):(\d+):(\d+)\)$/
6
-
7
- export function createSourceMapConsumers (rawMaps: Object) {
8
- const maps = {}
9
- Object.keys(rawMaps).forEach(file => {
10
- maps[file] = new SourceMapConsumer(rawMaps[file])
11
- })
12
- return maps
13
- }
14
-
15
- export function rewriteErrorTrace (e: any, mapConsumers: {
16
- [key: string]: SourceMapConsumer
17
- }) {
18
- if (e && typeof e.stack === 'string') {
19
- e.stack = e.stack.split('\n').map(line => {
20
- return rewriteTraceLine(line, mapConsumers)
21
- }).join('\n')
22
- }
23
- }
24
-
25
- function rewriteTraceLine (trace: string, mapConsumers: {
26
- [key: string]: SourceMapConsumer
27
- }) {
28
- const m = trace.match(filenameRE)
29
- const map = m && mapConsumers[m[1]]
30
- if (m != null && map) {
31
- const originalPosition = map.originalPositionFor({
32
- line: Number(m[2]),
33
- column: Number(m[3])
34
- })
35
- if (originalPosition.source != null) {
36
- const { source, line, column } = originalPosition
37
- const mappedPosition = `(${source.replace(/^webpack:\/\/\//, '')}:${String(line)}:${String(column)})`
38
- return trace.replace(filenameRE, mappedPosition)
39
- } else {
40
- return trace
41
- }
42
- } else {
43
- return trace
44
- }
45
- }
@@ -1,37 +0,0 @@
1
- /* @flow */
2
-
3
- import { createWriteFunction } from './write'
4
- import { createRenderFunction } from './render'
5
- import type { RenderOptions } from './create-renderer'
6
-
7
- export function createBasicRenderer ({
8
- modules = [],
9
- directives = {},
10
- isUnaryTag = (() => false),
11
- cache
12
- }: RenderOptions = {}) {
13
- const render = createRenderFunction(modules, directives, isUnaryTag, cache)
14
-
15
- return function renderToString (
16
- component: Component,
17
- context: any,
18
- done: any
19
- ): void {
20
- if (typeof context === 'function') {
21
- done = context
22
- context = {}
23
- }
24
- let result = ''
25
- const write = createWriteFunction(text => {
26
- result += text
27
- return false
28
- }, done)
29
- try {
30
- render(component, write, context, () => {
31
- done(null, result)
32
- })
33
- } catch (e) {
34
- done(e)
35
- }
36
- }
37
- }
@@ -1,152 +0,0 @@
1
- /* @flow */
2
-
3
- import RenderStream from './render-stream'
4
- import { createWriteFunction } from './write'
5
- import { createRenderFunction } from './render'
6
- import { createPromiseCallback } from './util'
7
- import TemplateRenderer from './template-renderer/index'
8
- import type { ClientManifest } from './template-renderer/index'
9
-
10
- export type Renderer = {
11
- renderToString: (component: Component, context: any, cb: any) => ?Promise<string>;
12
- renderToStream: (component: Component, context?: Object) => stream$Readable;
13
- };
14
-
15
- type RenderCache = {
16
- get: (key: string, cb?: Function) => string | void;
17
- set: (key: string, val: string) => void;
18
- has?: (key: string, cb?: Function) => boolean | void;
19
- };
20
-
21
- export type RenderOptions = {
22
- modules?: Array<(vnode: VNode) => ?string>;
23
- directives?: Object;
24
- isUnaryTag?: Function;
25
- cache?: RenderCache;
26
- template?: string | (content: string, context: any) => string;
27
- inject?: boolean;
28
- basedir?: string;
29
- shouldPreload?: Function;
30
- shouldPrefetch?: Function;
31
- clientManifest?: ClientManifest;
32
- serializer?: Function;
33
- runInNewContext?: boolean | 'once';
34
- };
35
-
36
- export function createRenderer ({
37
- modules = [],
38
- directives = {},
39
- isUnaryTag = (() => false),
40
- template,
41
- inject,
42
- cache,
43
- shouldPreload,
44
- shouldPrefetch,
45
- clientManifest,
46
- serializer
47
- }: RenderOptions = {}): Renderer {
48
- const render = createRenderFunction(modules, directives, isUnaryTag, cache)
49
- const templateRenderer = new TemplateRenderer({
50
- template,
51
- inject,
52
- shouldPreload,
53
- shouldPrefetch,
54
- clientManifest,
55
- serializer
56
- })
57
-
58
- return {
59
- renderToString (
60
- component: Component,
61
- context: any,
62
- cb: any
63
- ): ?Promise<string> {
64
- if (typeof context === 'function') {
65
- cb = context
66
- context = {}
67
- }
68
- if (context) {
69
- templateRenderer.bindRenderFns(context)
70
- }
71
-
72
- // no callback, return Promise
73
- let promise
74
- if (!cb) {
75
- ({ promise, cb } = createPromiseCallback())
76
- }
77
-
78
- let result = ''
79
- const write = createWriteFunction(text => {
80
- result += text
81
- return false
82
- }, cb)
83
- try {
84
- render(component, write, context, err => {
85
- if (err) {
86
- return cb(err)
87
- }
88
- if (context && context.rendered) {
89
- context.rendered(context)
90
- }
91
- if (template) {
92
- try {
93
- const res = templateRenderer.render(result, context)
94
- if (typeof res !== 'string') {
95
- // function template returning promise
96
- res
97
- .then(html => cb(null, html))
98
- .catch(cb)
99
- } else {
100
- cb(null, res)
101
- }
102
- } catch (e) {
103
- cb(e)
104
- }
105
- } else {
106
- cb(null, result)
107
- }
108
- })
109
- } catch (e) {
110
- cb(e)
111
- }
112
-
113
- return promise
114
- },
115
-
116
- renderToStream (
117
- component: Component,
118
- context?: Object
119
- ): stream$Readable {
120
- if (context) {
121
- templateRenderer.bindRenderFns(context)
122
- }
123
- const renderStream = new RenderStream((write, done) => {
124
- render(component, write, context, done)
125
- })
126
- if (!template) {
127
- if (context && context.rendered) {
128
- const rendered = context.rendered
129
- renderStream.once('beforeEnd', () => {
130
- rendered(context)
131
- })
132
- }
133
- return renderStream
134
- } else if (typeof template === 'function') {
135
- throw new Error(`function template is only supported in renderToString.`)
136
- } else {
137
- const templateStream = templateRenderer.createStream(context)
138
- renderStream.on('error', err => {
139
- templateStream.emit('error', err)
140
- })
141
- renderStream.pipe(templateStream)
142
- if (context && context.rendered) {
143
- const rendered = context.rendered
144
- renderStream.once('beforeEnd', () => {
145
- rendered(context)
146
- })
147
- }
148
- return templateStream
149
- }
150
- }
151
- }
152
- }