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.
- package/README.md +17 -295
- package/compiler-sfc/index.d.ts +1 -0
- package/compiler-sfc/index.js +1 -0
- package/compiler-sfc/index.mjs +1 -0
- package/compiler-sfc/package.json +5 -0
- package/dist/vue.common.dev.js +11481 -11946
- package/dist/vue.common.prod.js +8 -3
- package/dist/vue.esm.browser.js +11321 -12011
- package/dist/vue.esm.browser.min.js +8 -3
- package/dist/vue.esm.js +11476 -11984
- package/dist/vue.js +11484 -11949
- package/dist/vue.min.js +8 -3
- package/dist/vue.runtime.common.dev.js +8427 -8421
- package/dist/vue.runtime.common.prod.js +8 -3
- package/dist/vue.runtime.esm.js +8436 -8454
- package/dist/vue.runtime.js +8430 -8424
- package/dist/vue.runtime.min.js +8 -3
- package/package.json +88 -111
- package/packages/compiler-sfc/dist/compiler-sfc.js +7 -0
- package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
- package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
- package/packages/compiler-sfc/package.json +30 -0
- package/src/compiler/{codeframe.js → codeframe.ts} +9 -7
- package/src/compiler/codegen/{events.js → events.ts} +21 -41
- package/src/compiler/codegen/{index.js → index.ts} +146 -136
- package/src/compiler/{create-compiler.js → create-compiler.ts} +26 -18
- package/src/compiler/directives/bind.ts +9 -0
- package/src/compiler/directives/{index.js → index.ts} +0 -2
- package/src/compiler/directives/{model.js → model.ts} +15 -18
- package/src/compiler/directives/{on.js → on.ts} +3 -4
- package/src/compiler/{error-detector.js → error-detector.ts} +61 -31
- package/src/compiler/{helpers.js → helpers.ts} +73 -61
- package/src/compiler/{index.js → index.ts} +2 -3
- package/src/compiler/{optimizer.js → optimizer.ts} +30 -23
- package/src/compiler/parser/{entity-decoder.js → entity-decoder.ts} +1 -3
- package/src/compiler/parser/{filter-parser.js → filter-parser.ts} +43 -24
- package/src/compiler/parser/{html-parser.js → html-parser.ts} +50 -29
- package/src/compiler/parser/{index.js → index.ts} +190 -172
- package/src/compiler/parser/{text-parser.js → text-parser.ts} +8 -9
- package/src/compiler/{to-function.js → to-function.ts} +27 -22
- package/src/core/components/{index.js → index.ts} +0 -0
- package/src/core/components/{keep-alive.js → keep-alive.ts} +42 -30
- package/src/core/{config.js → config.ts} +28 -30
- package/src/core/global-api/{assets.js → assets.ts} +8 -7
- package/src/core/global-api/{extend.js → extend.ts} +10 -13
- package/src/core/global-api/{index.js → index.ts} +4 -5
- package/src/core/global-api/{mixin.js → mixin.ts} +2 -3
- package/src/core/global-api/use.ts +23 -0
- package/src/core/{index.js → index.ts} +1 -1
- package/src/core/instance/{events.js → events.ts} +41 -24
- package/src/core/instance/{index.js → index.ts} +9 -5
- package/src/core/instance/{init.js → init.ts} +26 -15
- package/src/core/instance/inject.ts +72 -0
- package/src/core/instance/{lifecycle.js → lifecycle.ts} +86 -44
- package/src/core/instance/{proxy.js → proxy.ts} +29 -24
- package/src/core/instance/render-helpers/{bind-dynamic-keys.js → bind-dynamic-keys.ts} +6 -5
- package/src/core/instance/render-helpers/{bind-object-listeners.js → bind-object-listeners.ts} +4 -8
- package/src/core/instance/render-helpers/{bind-object-props.js → bind-object-props.ts} +12 -17
- package/src/core/instance/render-helpers/{check-keycodes.js → check-keycodes.ts} +5 -7
- package/src/core/instance/render-helpers/{index.js → index.ts} +1 -3
- package/src/core/instance/render-helpers/{render-list.js → render-list.ts} +12 -13
- package/src/core/instance/render-helpers/{render-slot.js → render-slot.ts} +10 -11
- package/src/core/instance/render-helpers/{render-static.js → render-static.ts} +7 -10
- package/src/core/instance/render-helpers/{resolve-filter.js → resolve-filter.ts} +1 -3
- package/src/core/instance/render-helpers/{resolve-scoped-slots.js → resolve-scoped-slots.ts} +11 -8
- package/src/core/instance/render-helpers/{resolve-slots.js → resolve-slots.ts} +12 -11
- package/src/core/instance/{render.js → render.ts} +66 -29
- package/src/core/instance/{state.js → state.ts} +100 -83
- package/src/core/observer/{array.js → array.ts} +11 -2
- package/src/core/observer/{dep.js → dep.ts} +37 -15
- package/src/core/observer/{index.js → index.ts} +137 -71
- package/src/core/observer/{scheduler.js → scheduler.ts} +42 -43
- package/src/core/observer/{traverse.js → traverse.ts} +10 -7
- package/src/core/observer/{watcher.js → watcher.ts} +88 -60
- package/src/core/util/{debug.js → debug.ts} +38 -34
- package/src/core/util/{env.js → env.ts} +27 -30
- package/src/core/util/{error.js → error.ts} +12 -14
- package/src/core/util/{index.js → index.ts} +0 -2
- package/src/core/util/{lang.js → lang.ts} +6 -7
- package/src/core/util/{next-tick.js → next-tick.ts} +16 -10
- package/src/core/util/{options.js → options.ts} +119 -114
- package/src/core/util/{perf.js → perf.ts} +5 -1
- package/src/core/util/{props.js → props.ts} +54 -50
- package/src/core/vdom/{create-component.js → create-component.ts} +51 -50
- package/src/core/vdom/{create-element.js → create-element.ts} +49 -43
- package/src/core/vdom/{create-functional-component.js → create-functional-component.ts} +52 -27
- package/src/core/vdom/helpers/{extract-props.js → extract-props.ts} +18 -18
- package/src/core/vdom/helpers/{get-first-component-child.js → get-first-component-child.ts} +6 -5
- package/src/core/vdom/helpers/{index.js → index.ts} +0 -2
- package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
- package/src/core/vdom/helpers/{merge-hook.js → merge-hook.ts} +7 -5
- package/src/core/vdom/helpers/{normalize-children.js → normalize-children.ts} +26 -16
- package/src/core/vdom/helpers/{normalize-scoped-slots.js → normalize-scoped-slots.ts} +23 -17
- package/src/core/vdom/helpers/{resolve-async-component.js → resolve-async-component.ts} +29 -37
- package/src/core/vdom/helpers/update-listeners.ts +101 -0
- package/src/core/vdom/modules/{directives.js → directives.ts} +20 -14
- package/src/core/vdom/modules/index.ts +4 -0
- package/src/core/vdom/modules/template-ref.ts +96 -0
- package/src/core/vdom/{patch.js → patch.ts} +239 -138
- package/src/core/vdom/{vnode.js → vnode.ts} +36 -31
- package/src/global.d.ts +15 -0
- package/src/platforms/web/compiler/directives/html.ts +8 -0
- package/src/platforms/web/compiler/directives/{index.js → index.ts} +0 -0
- package/src/platforms/web/compiler/directives/{model.js → model.ts} +47 -41
- package/src/platforms/web/compiler/directives/{text.js → text.ts} +2 -3
- package/src/platforms/web/compiler/{index.js → index.ts} +0 -2
- package/src/platforms/web/compiler/modules/{class.js → class.ts} +10 -15
- package/src/platforms/web/compiler/modules/{index.js → index.ts} +1 -5
- package/src/platforms/web/compiler/modules/{model.js → model.ts} +6 -11
- package/src/platforms/web/compiler/modules/{style.js → style.ts} +9 -14
- package/src/platforms/web/compiler/{options.js → options.ts} +1 -2
- package/src/platforms/web/compiler/{util.js → util.ts} +5 -7
- package/src/platforms/web/entry-compiler-sfc.ts +1 -0
- package/src/platforms/web/{entry-compiler.js → entry-compiler.ts} +1 -3
- package/src/platforms/web/{entry-runtime.js → entry-runtime-esm.ts} +2 -2
- package/src/platforms/web/entry-runtime-with-compiler-esm.ts +5 -0
- package/src/platforms/web/entry-runtime-with-compiler.ts +10 -0
- package/src/platforms/web/entry-runtime.ts +7 -0
- package/src/platforms/web/runtime/{class-util.js → class-util.ts} +2 -4
- package/src/platforms/web/runtime/components/{index.js → index.ts} +0 -0
- package/src/platforms/web/runtime/components/{transition-group.js → transition-group.ts} +59 -46
- package/src/platforms/web/runtime/components/{transition.js → transition.ts} +43 -36
- package/src/platforms/web/runtime/directives/{index.js → index.ts} +0 -0
- package/src/platforms/web/runtime/directives/{model.js → model.ts} +22 -21
- package/src/platforms/web/runtime/directives/{show.js → show.ts} +11 -10
- package/src/platforms/web/runtime/{index.js → index.ts} +9 -10
- package/src/platforms/web/runtime/modules/{attrs.js → attrs.ts} +12 -16
- package/src/platforms/web/runtime/modules/{class.js → class.ts} +7 -18
- package/src/platforms/web/runtime/modules/{dom-props.js → dom-props.ts} +24 -17
- package/src/platforms/web/runtime/modules/{events.js → events.ts} +22 -15
- package/src/platforms/web/runtime/modules/{index.js → index.ts} +1 -8
- package/src/platforms/web/runtime/modules/{style.js → style.ts} +24 -13
- package/src/platforms/web/runtime/modules/{transition.js → transition.ts} +61 -63
- package/src/platforms/web/runtime/node-ops.ts +66 -0
- package/src/platforms/web/runtime/{patch.js → patch.ts} +0 -2
- package/src/platforms/web/runtime/{transition-util.js → transition-util.ts} +63 -38
- package/src/platforms/web/{entry-runtime-with-compiler.js → runtime-with-compiler.ts} +28 -19
- package/src/platforms/web/util/{attrs.js → attrs.ts} +18 -14
- package/src/platforms/web/util/{class.js → class.ts} +23 -21
- package/src/platforms/web/util/{compat.js → compat.ts} +4 -4
- package/src/platforms/web/util/{element.js → element.ts} +21 -22
- package/src/platforms/web/util/{index.js → index.ts} +2 -6
- package/src/platforms/web/util/{style.js → style.ts} +12 -12
- package/src/sfc/{parser.js → parser.ts} +18 -15
- package/src/shared/{constants.js → constants.ts} +2 -6
- package/src/shared/{util.js → util.ts} +78 -55
- package/src/types/compiler.ts +224 -0
- package/src/types/component.ts +209 -0
- package/src/types/global-api.ts +37 -0
- package/src/types/modules.d.ts +15 -0
- package/src/types/options.ts +120 -0
- package/src/types/ssr.ts +27 -0
- package/src/types/utils.ts +3 -0
- package/src/types/vnode.ts +127 -0
- package/src/v3/apiInject.ts +66 -0
- package/src/v3/apiLifecycle.ts +53 -0
- package/src/v3/apiSetup.ts +161 -0
- package/src/v3/apiWatch.ts +355 -0
- package/src/v3/currentInstance.ts +23 -0
- package/src/v3/debug.ts +21 -0
- package/src/v3/h.ts +18 -0
- package/src/v3/index.ts +77 -0
- package/src/v3/reactivity/computed.ts +100 -0
- package/src/v3/reactivity/effect.ts +20 -0
- package/src/v3/reactivity/effectScope.ts +134 -0
- package/src/v3/reactivity/operations.ts +14 -0
- package/src/v3/reactivity/reactive.ts +123 -0
- package/src/v3/reactivity/readonly.ts +121 -0
- package/src/v3/reactivity/ref.ts +249 -0
- package/types/index.d.ts +10 -13
- package/types/options.d.ts +265 -132
- package/types/plugin.d.ts +4 -4
- package/types/umd.d.ts +47 -27
- package/types/v3-generated.d.ts +389 -0
- package/types/v3.d.ts +16 -0
- package/types/vnode.d.ts +70 -57
- package/types/vue.d.ts +292 -88
- package/dist/README.md +0 -122
- package/src/compiler/directives/bind.js +0 -11
- package/src/core/global-api/use.js +0 -23
- package/src/core/instance/inject.js +0 -73
- package/src/core/vdom/helpers/is-async-placeholder.js +0 -5
- package/src/core/vdom/helpers/update-listeners.js +0 -95
- package/src/core/vdom/modules/index.js +0 -7
- package/src/core/vdom/modules/ref.js +0 -45
- package/src/platforms/web/compiler/directives/html.js +0 -9
- package/src/platforms/web/entry-server-basic-renderer.js +0 -13
- package/src/platforms/web/entry-server-renderer.js +0 -27
- package/src/platforms/web/runtime/node-ops.js +0 -59
- package/src/platforms/web/server/compiler.js +0 -11
- package/src/platforms/web/server/directives/index.js +0 -7
- package/src/platforms/web/server/directives/model.js +0 -44
- package/src/platforms/web/server/directives/show.js +0 -12
- package/src/platforms/web/server/modules/attrs.js +0 -67
- package/src/platforms/web/server/modules/class.js +0 -11
- package/src/platforms/web/server/modules/dom-props.js +0 -50
- package/src/platforms/web/server/modules/index.js +0 -11
- package/src/platforms/web/server/modules/style.js +0 -41
- package/src/platforms/web/server/util.js +0 -101
- package/src/platforms/weex/compiler/directives/index.js +0 -5
- package/src/platforms/weex/compiler/directives/model.js +0 -33
- package/src/platforms/weex/compiler/index.js +0 -52
- package/src/platforms/weex/compiler/modules/append.js +0 -27
- package/src/platforms/weex/compiler/modules/class.js +0 -74
- package/src/platforms/weex/compiler/modules/index.js +0 -13
- package/src/platforms/weex/compiler/modules/props.js +0 -37
- package/src/platforms/weex/compiler/modules/recycle-list/component-root.js +0 -13
- package/src/platforms/weex/compiler/modules/recycle-list/component.js +0 -16
- package/src/platforms/weex/compiler/modules/recycle-list/index.js +0 -60
- package/src/platforms/weex/compiler/modules/recycle-list/recycle-list.js +0 -50
- package/src/platforms/weex/compiler/modules/recycle-list/text.js +0 -23
- package/src/platforms/weex/compiler/modules/recycle-list/v-bind.js +0 -21
- package/src/platforms/weex/compiler/modules/recycle-list/v-for.js +0 -33
- package/src/platforms/weex/compiler/modules/recycle-list/v-if.js +0 -63
- package/src/platforms/weex/compiler/modules/recycle-list/v-on.js +0 -25
- package/src/platforms/weex/compiler/modules/recycle-list/v-once.js +0 -19
- package/src/platforms/weex/compiler/modules/style.js +0 -87
- package/src/platforms/weex/entry-compiler.js +0 -2
- package/src/platforms/weex/entry-framework.js +0 -187
- package/src/platforms/weex/entry-runtime-factory.js +0 -6
- package/src/platforms/weex/runtime/components/index.js +0 -9
- package/src/platforms/weex/runtime/components/richtext.js +0 -82
- package/src/platforms/weex/runtime/components/transition-group.js +0 -148
- package/src/platforms/weex/runtime/components/transition.js +0 -9
- package/src/platforms/weex/runtime/directives/index.js +0 -2
- package/src/platforms/weex/runtime/index.js +0 -42
- package/src/platforms/weex/runtime/modules/attrs.js +0 -44
- package/src/platforms/weex/runtime/modules/class.js +0 -76
- package/src/platforms/weex/runtime/modules/events.js +0 -54
- package/src/platforms/weex/runtime/modules/index.js +0 -13
- package/src/platforms/weex/runtime/modules/style.js +0 -84
- package/src/platforms/weex/runtime/modules/transition.js +0 -270
- package/src/platforms/weex/runtime/node-ops.js +0 -91
- package/src/platforms/weex/runtime/patch.js +0 -16
- package/src/platforms/weex/runtime/recycle-list/render-component-template.js +0 -34
- package/src/platforms/weex/runtime/recycle-list/virtual-component.js +0 -136
- package/src/platforms/weex/runtime/text-node.js +0 -9
- package/src/platforms/weex/util/element.js +0 -52
- package/src/platforms/weex/util/index.js +0 -40
- package/src/platforms/weex/util/parser.js +0 -60
- package/src/server/bundle-renderer/create-bundle-renderer.js +0 -151
- package/src/server/bundle-renderer/create-bundle-runner.js +0 -150
- package/src/server/bundle-renderer/source-map-support.js +0 -45
- package/src/server/create-basic-renderer.js +0 -37
- package/src/server/create-renderer.js +0 -152
- package/src/server/optimizing-compiler/codegen.js +0 -264
- package/src/server/optimizing-compiler/index.js +0 -20
- package/src/server/optimizing-compiler/modules.js +0 -124
- package/src/server/optimizing-compiler/optimizer.js +0 -141
- package/src/server/optimizing-compiler/runtime-helpers.js +0 -150
- package/src/server/render-context.js +0 -130
- package/src/server/render-stream.js +0 -95
- package/src/server/render.js +0 -437
- package/src/server/template-renderer/create-async-file-mapper.js +0 -57
- package/src/server/template-renderer/index.js +0 -277
- package/src/server/template-renderer/parse-template.js +0 -42
- package/src/server/template-renderer/template-stream.js +0 -82
- package/src/server/util.js +0 -18
- package/src/server/webpack-plugin/client.js +0 -65
- package/src/server/webpack-plugin/server.js +0 -66
- package/src/server/webpack-plugin/util.js +0 -34
- 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
|
-
}
|