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,130 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
import { isUndef } from 'shared/util'
|
|
4
|
-
|
|
5
|
-
type RenderState = {
|
|
6
|
-
type: 'Element';
|
|
7
|
-
rendered: number;
|
|
8
|
-
total: number;
|
|
9
|
-
children: Array<VNode>;
|
|
10
|
-
endTag: string;
|
|
11
|
-
} | {
|
|
12
|
-
type: 'Fragment';
|
|
13
|
-
rendered: number;
|
|
14
|
-
total: number;
|
|
15
|
-
children: Array<VNode>;
|
|
16
|
-
} | {
|
|
17
|
-
type: 'Component';
|
|
18
|
-
prevActive: Component;
|
|
19
|
-
} | {
|
|
20
|
-
type: 'ComponentWithCache';
|
|
21
|
-
buffer: Array<string>;
|
|
22
|
-
bufferIndex: number;
|
|
23
|
-
componentBuffer: Array<Set<Class<Component>>>;
|
|
24
|
-
key: string;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export class RenderContext {
|
|
28
|
-
userContext: ?Object;
|
|
29
|
-
activeInstance: Component;
|
|
30
|
-
renderStates: Array<RenderState>;
|
|
31
|
-
write: (text: string, next: Function) => void;
|
|
32
|
-
renderNode: (node: VNode, isRoot: boolean, context: RenderContext) => void;
|
|
33
|
-
next: () => void;
|
|
34
|
-
done: (err: ?Error) => void;
|
|
35
|
-
|
|
36
|
-
modules: Array<(node: VNode) => ?string>;
|
|
37
|
-
directives: Object;
|
|
38
|
-
isUnaryTag: (tag: string) => boolean;
|
|
39
|
-
|
|
40
|
-
cache: any;
|
|
41
|
-
get: ?(key: string, cb: Function) => void;
|
|
42
|
-
has: ?(key: string, cb: Function) => void;
|
|
43
|
-
|
|
44
|
-
constructor (options: Object) {
|
|
45
|
-
this.userContext = options.userContext
|
|
46
|
-
this.activeInstance = options.activeInstance
|
|
47
|
-
this.renderStates = []
|
|
48
|
-
|
|
49
|
-
this.write = options.write
|
|
50
|
-
this.done = options.done
|
|
51
|
-
this.renderNode = options.renderNode
|
|
52
|
-
|
|
53
|
-
this.isUnaryTag = options.isUnaryTag
|
|
54
|
-
this.modules = options.modules
|
|
55
|
-
this.directives = options.directives
|
|
56
|
-
|
|
57
|
-
const cache = options.cache
|
|
58
|
-
if (cache && (!cache.get || !cache.set)) {
|
|
59
|
-
throw new Error('renderer cache must implement at least get & set.')
|
|
60
|
-
}
|
|
61
|
-
this.cache = cache
|
|
62
|
-
this.get = cache && normalizeAsync(cache, 'get')
|
|
63
|
-
this.has = cache && normalizeAsync(cache, 'has')
|
|
64
|
-
|
|
65
|
-
this.next = this.next.bind(this)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
next () {
|
|
69
|
-
// eslint-disable-next-line
|
|
70
|
-
while (true) {
|
|
71
|
-
const lastState = this.renderStates[this.renderStates.length - 1]
|
|
72
|
-
if (isUndef(lastState)) {
|
|
73
|
-
return this.done()
|
|
74
|
-
}
|
|
75
|
-
/* eslint-disable no-case-declarations */
|
|
76
|
-
switch (lastState.type) {
|
|
77
|
-
case 'Element':
|
|
78
|
-
case 'Fragment':
|
|
79
|
-
const { children, total } = lastState
|
|
80
|
-
const rendered = lastState.rendered++
|
|
81
|
-
if (rendered < total) {
|
|
82
|
-
return this.renderNode(children[rendered], false, this)
|
|
83
|
-
} else {
|
|
84
|
-
this.renderStates.pop()
|
|
85
|
-
if (lastState.type === 'Element') {
|
|
86
|
-
return this.write(lastState.endTag, this.next)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
break
|
|
90
|
-
case 'Component':
|
|
91
|
-
this.renderStates.pop()
|
|
92
|
-
this.activeInstance = lastState.prevActive
|
|
93
|
-
break
|
|
94
|
-
case 'ComponentWithCache':
|
|
95
|
-
this.renderStates.pop()
|
|
96
|
-
const { buffer, bufferIndex, componentBuffer, key } = lastState
|
|
97
|
-
const result = {
|
|
98
|
-
html: buffer[bufferIndex],
|
|
99
|
-
components: componentBuffer[bufferIndex]
|
|
100
|
-
}
|
|
101
|
-
this.cache.set(key, result)
|
|
102
|
-
if (bufferIndex === 0) {
|
|
103
|
-
// this is a top-level cached component,
|
|
104
|
-
// exit caching mode.
|
|
105
|
-
this.write.caching = false
|
|
106
|
-
} else {
|
|
107
|
-
// parent component is also being cached,
|
|
108
|
-
// merge self into parent's result
|
|
109
|
-
buffer[bufferIndex - 1] += result.html
|
|
110
|
-
const prev = componentBuffer[bufferIndex - 1]
|
|
111
|
-
result.components.forEach(c => prev.add(c))
|
|
112
|
-
}
|
|
113
|
-
buffer.length = bufferIndex
|
|
114
|
-
componentBuffer.length = bufferIndex
|
|
115
|
-
break
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function normalizeAsync (cache, method) {
|
|
122
|
-
const fn = cache[method]
|
|
123
|
-
if (isUndef(fn)) {
|
|
124
|
-
return
|
|
125
|
-
} else if (fn.length > 1) {
|
|
126
|
-
return (key, cb) => fn.call(cache, key, cb)
|
|
127
|
-
} else {
|
|
128
|
-
return (key, cb) => cb(fn.call(cache, key))
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Original RenderStream implementation by Sasha Aickin (@aickin)
|
|
5
|
-
* Licensed under the Apache License, Version 2.0
|
|
6
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
*
|
|
8
|
-
* Modified by Evan You (@yyx990803)
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
const stream = require('stream')
|
|
12
|
-
|
|
13
|
-
import { isTrue, isUndef } from 'shared/util'
|
|
14
|
-
import { createWriteFunction } from './write'
|
|
15
|
-
|
|
16
|
-
export default class RenderStream extends stream.Readable {
|
|
17
|
-
buffer: string;
|
|
18
|
-
render: (write: Function, done: Function) => void;
|
|
19
|
-
expectedSize: number;
|
|
20
|
-
write: Function;
|
|
21
|
-
next: Function;
|
|
22
|
-
end: Function;
|
|
23
|
-
done: boolean;
|
|
24
|
-
|
|
25
|
-
constructor (render: Function) {
|
|
26
|
-
super()
|
|
27
|
-
this.buffer = ''
|
|
28
|
-
this.render = render
|
|
29
|
-
this.expectedSize = 0
|
|
30
|
-
|
|
31
|
-
this.write = createWriteFunction((text, next) => {
|
|
32
|
-
const n = this.expectedSize
|
|
33
|
-
this.buffer += text
|
|
34
|
-
if (this.buffer.length >= n) {
|
|
35
|
-
this.next = next
|
|
36
|
-
this.pushBySize(n)
|
|
37
|
-
return true // we will decide when to call next
|
|
38
|
-
}
|
|
39
|
-
return false
|
|
40
|
-
}, err => {
|
|
41
|
-
this.emit('error', err)
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
this.end = () => {
|
|
45
|
-
this.emit('beforeEnd')
|
|
46
|
-
// the rendering is finished; we should push out the last of the buffer.
|
|
47
|
-
this.done = true
|
|
48
|
-
this.push(this.buffer)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
pushBySize (n: number) {
|
|
53
|
-
const bufferToPush = this.buffer.substring(0, n)
|
|
54
|
-
this.buffer = this.buffer.substring(n)
|
|
55
|
-
this.push(bufferToPush)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
tryRender () {
|
|
59
|
-
try {
|
|
60
|
-
this.render(this.write, this.end)
|
|
61
|
-
} catch (e) {
|
|
62
|
-
this.emit('error', e)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
tryNext () {
|
|
67
|
-
try {
|
|
68
|
-
this.next()
|
|
69
|
-
} catch (e) {
|
|
70
|
-
this.emit('error', e)
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
_read (n: number) {
|
|
75
|
-
this.expectedSize = n
|
|
76
|
-
// it's possible that the last chunk added bumped the buffer up to > 2 * n,
|
|
77
|
-
// which means we will need to go through multiple read calls to drain it
|
|
78
|
-
// down to < n.
|
|
79
|
-
if (isTrue(this.done)) {
|
|
80
|
-
this.push(null)
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
if (this.buffer.length >= n) {
|
|
84
|
-
this.pushBySize(n)
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
if (isUndef(this.next)) {
|
|
88
|
-
// start the rendering chain.
|
|
89
|
-
this.tryRender()
|
|
90
|
-
} else {
|
|
91
|
-
// continue with the rendering.
|
|
92
|
-
this.tryNext()
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
package/src/server/render.js
DELETED
|
@@ -1,437 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
import { escape } from 'web/server/util'
|
|
4
|
-
import { SSR_ATTR } from 'shared/constants'
|
|
5
|
-
import { RenderContext } from './render-context'
|
|
6
|
-
import { resolveAsset } from 'core/util/options'
|
|
7
|
-
import { generateComponentTrace } from 'core/util/debug'
|
|
8
|
-
import { ssrCompileToFunctions } from 'web/server/compiler'
|
|
9
|
-
import { installSSRHelpers } from './optimizing-compiler/runtime-helpers'
|
|
10
|
-
|
|
11
|
-
import { isDef, isUndef, isTrue } from 'shared/util'
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
createComponent,
|
|
15
|
-
createComponentInstanceForVnode
|
|
16
|
-
} from 'core/vdom/create-component'
|
|
17
|
-
|
|
18
|
-
let warned = Object.create(null)
|
|
19
|
-
const warnOnce = msg => {
|
|
20
|
-
if (!warned[msg]) {
|
|
21
|
-
warned[msg] = true
|
|
22
|
-
// eslint-disable-next-line no-console
|
|
23
|
-
console.warn(`\n\u001b[31m${msg}\u001b[39m\n`)
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const onCompilationError = (err, vm) => {
|
|
28
|
-
const trace = vm ? generateComponentTrace(vm) : ''
|
|
29
|
-
throw new Error(`\n\u001b[31m${err}${trace}\u001b[39m\n`)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const normalizeRender = vm => {
|
|
33
|
-
const { render, template, _scopeId } = vm.$options
|
|
34
|
-
if (isUndef(render)) {
|
|
35
|
-
if (template) {
|
|
36
|
-
const compiled = ssrCompileToFunctions(template, {
|
|
37
|
-
scopeId: _scopeId,
|
|
38
|
-
warn: onCompilationError
|
|
39
|
-
}, vm)
|
|
40
|
-
|
|
41
|
-
vm.$options.render = compiled.render
|
|
42
|
-
vm.$options.staticRenderFns = compiled.staticRenderFns
|
|
43
|
-
} else {
|
|
44
|
-
throw new Error(
|
|
45
|
-
`render function or template not defined in component: ${
|
|
46
|
-
vm.$options.name || vm.$options._componentTag || 'anonymous'
|
|
47
|
-
}`
|
|
48
|
-
)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function waitForServerPrefetch (vm, resolve, reject) {
|
|
54
|
-
let handlers = vm.$options.serverPrefetch
|
|
55
|
-
if (isDef(handlers)) {
|
|
56
|
-
if (!Array.isArray(handlers)) handlers = [handlers]
|
|
57
|
-
try {
|
|
58
|
-
const promises = []
|
|
59
|
-
for (let i = 0, j = handlers.length; i < j; i++) {
|
|
60
|
-
const result = handlers[i].call(vm, vm)
|
|
61
|
-
if (result && typeof result.then === 'function') {
|
|
62
|
-
promises.push(result)
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
Promise.all(promises).then(resolve).catch(reject)
|
|
66
|
-
return
|
|
67
|
-
} catch (e) {
|
|
68
|
-
reject(e)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
resolve()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function renderNode (node, isRoot, context) {
|
|
75
|
-
if (node.isString) {
|
|
76
|
-
renderStringNode(node, context)
|
|
77
|
-
} else if (isDef(node.componentOptions)) {
|
|
78
|
-
renderComponent(node, isRoot, context)
|
|
79
|
-
} else if (isDef(node.tag)) {
|
|
80
|
-
renderElement(node, isRoot, context)
|
|
81
|
-
} else if (isTrue(node.isComment)) {
|
|
82
|
-
if (isDef(node.asyncFactory)) {
|
|
83
|
-
// async component
|
|
84
|
-
renderAsyncComponent(node, isRoot, context)
|
|
85
|
-
} else {
|
|
86
|
-
context.write(`<!--${node.text}-->`, context.next)
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
context.write(
|
|
90
|
-
node.raw ? node.text : escape(String(node.text)),
|
|
91
|
-
context.next
|
|
92
|
-
)
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function registerComponentForCache (options, write) {
|
|
97
|
-
// exposed by vue-loader, need to call this if cache hit because
|
|
98
|
-
// component lifecycle hooks will not be called.
|
|
99
|
-
const register = options._ssrRegister
|
|
100
|
-
if (write.caching && isDef(register)) {
|
|
101
|
-
write.componentBuffer[write.componentBuffer.length - 1].add(register)
|
|
102
|
-
}
|
|
103
|
-
return register
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function renderComponent (node, isRoot, context) {
|
|
107
|
-
const { write, next, userContext } = context
|
|
108
|
-
|
|
109
|
-
// check cache hit
|
|
110
|
-
const Ctor = node.componentOptions.Ctor
|
|
111
|
-
const getKey = Ctor.options.serverCacheKey
|
|
112
|
-
const name = Ctor.options.name
|
|
113
|
-
const cache = context.cache
|
|
114
|
-
const registerComponent = registerComponentForCache(Ctor.options, write)
|
|
115
|
-
|
|
116
|
-
if (isDef(getKey) && isDef(cache) && isDef(name)) {
|
|
117
|
-
const rawKey = getKey(node.componentOptions.propsData)
|
|
118
|
-
if (rawKey === false) {
|
|
119
|
-
renderComponentInner(node, isRoot, context)
|
|
120
|
-
return
|
|
121
|
-
}
|
|
122
|
-
const key = name + '::' + rawKey
|
|
123
|
-
const { has, get } = context
|
|
124
|
-
if (isDef(has)) {
|
|
125
|
-
has(key, hit => {
|
|
126
|
-
if (hit === true && isDef(get)) {
|
|
127
|
-
get(key, res => {
|
|
128
|
-
if (isDef(registerComponent)) {
|
|
129
|
-
registerComponent(userContext)
|
|
130
|
-
}
|
|
131
|
-
res.components.forEach(register => register(userContext))
|
|
132
|
-
write(res.html, next)
|
|
133
|
-
})
|
|
134
|
-
} else {
|
|
135
|
-
renderComponentWithCache(node, isRoot, key, context)
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
} else if (isDef(get)) {
|
|
139
|
-
get(key, res => {
|
|
140
|
-
if (isDef(res)) {
|
|
141
|
-
if (isDef(registerComponent)) {
|
|
142
|
-
registerComponent(userContext)
|
|
143
|
-
}
|
|
144
|
-
res.components.forEach(register => register(userContext))
|
|
145
|
-
write(res.html, next)
|
|
146
|
-
} else {
|
|
147
|
-
renderComponentWithCache(node, isRoot, key, context)
|
|
148
|
-
}
|
|
149
|
-
})
|
|
150
|
-
}
|
|
151
|
-
} else {
|
|
152
|
-
if (isDef(getKey) && isUndef(cache)) {
|
|
153
|
-
warnOnce(
|
|
154
|
-
`[vue-server-renderer] Component ${
|
|
155
|
-
Ctor.options.name || '(anonymous)'
|
|
156
|
-
} implemented serverCacheKey, ` +
|
|
157
|
-
'but no cache was provided to the renderer.'
|
|
158
|
-
)
|
|
159
|
-
}
|
|
160
|
-
if (isDef(getKey) && isUndef(name)) {
|
|
161
|
-
warnOnce(
|
|
162
|
-
`[vue-server-renderer] Components that implement "serverCacheKey" ` +
|
|
163
|
-
`must also define a unique "name" option.`
|
|
164
|
-
)
|
|
165
|
-
}
|
|
166
|
-
renderComponentInner(node, isRoot, context)
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function renderComponentWithCache (node, isRoot, key, context) {
|
|
171
|
-
const write = context.write
|
|
172
|
-
write.caching = true
|
|
173
|
-
const buffer = write.cacheBuffer
|
|
174
|
-
const bufferIndex = buffer.push('') - 1
|
|
175
|
-
const componentBuffer = write.componentBuffer
|
|
176
|
-
componentBuffer.push(new Set())
|
|
177
|
-
context.renderStates.push({
|
|
178
|
-
type: 'ComponentWithCache',
|
|
179
|
-
key,
|
|
180
|
-
buffer,
|
|
181
|
-
bufferIndex,
|
|
182
|
-
componentBuffer
|
|
183
|
-
})
|
|
184
|
-
renderComponentInner(node, isRoot, context)
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function renderComponentInner (node, isRoot, context) {
|
|
188
|
-
const prevActive = context.activeInstance
|
|
189
|
-
// expose userContext on vnode
|
|
190
|
-
node.ssrContext = context.userContext
|
|
191
|
-
const child = context.activeInstance = createComponentInstanceForVnode(
|
|
192
|
-
node,
|
|
193
|
-
context.activeInstance
|
|
194
|
-
)
|
|
195
|
-
normalizeRender(child)
|
|
196
|
-
|
|
197
|
-
const resolve = () => {
|
|
198
|
-
const childNode = child._render()
|
|
199
|
-
childNode.parent = node
|
|
200
|
-
context.renderStates.push({
|
|
201
|
-
type: 'Component',
|
|
202
|
-
prevActive
|
|
203
|
-
})
|
|
204
|
-
renderNode(childNode, isRoot, context)
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
const reject = context.done
|
|
208
|
-
|
|
209
|
-
waitForServerPrefetch(child, resolve, reject)
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
function renderAsyncComponent (node, isRoot, context) {
|
|
213
|
-
const factory = node.asyncFactory
|
|
214
|
-
|
|
215
|
-
const resolve = comp => {
|
|
216
|
-
if (comp.__esModule && comp.default) {
|
|
217
|
-
comp = comp.default
|
|
218
|
-
}
|
|
219
|
-
const { data, children, tag } = node.asyncMeta
|
|
220
|
-
const nodeContext = node.asyncMeta.context
|
|
221
|
-
const resolvedNode: any = createComponent(
|
|
222
|
-
comp,
|
|
223
|
-
data,
|
|
224
|
-
nodeContext,
|
|
225
|
-
children,
|
|
226
|
-
tag
|
|
227
|
-
)
|
|
228
|
-
if (resolvedNode) {
|
|
229
|
-
if (resolvedNode.componentOptions) {
|
|
230
|
-
// normal component
|
|
231
|
-
renderComponent(resolvedNode, isRoot, context)
|
|
232
|
-
} else if (!Array.isArray(resolvedNode)) {
|
|
233
|
-
// single return node from functional component
|
|
234
|
-
renderNode(resolvedNode, isRoot, context)
|
|
235
|
-
} else {
|
|
236
|
-
// multiple return nodes from functional component
|
|
237
|
-
context.renderStates.push({
|
|
238
|
-
type: 'Fragment',
|
|
239
|
-
children: resolvedNode,
|
|
240
|
-
rendered: 0,
|
|
241
|
-
total: resolvedNode.length
|
|
242
|
-
})
|
|
243
|
-
context.next()
|
|
244
|
-
}
|
|
245
|
-
} else {
|
|
246
|
-
// invalid component, but this does not throw on the client
|
|
247
|
-
// so render empty comment node
|
|
248
|
-
context.write(`<!---->`, context.next)
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
if (factory.resolved) {
|
|
253
|
-
resolve(factory.resolved)
|
|
254
|
-
return
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
const reject = context.done
|
|
258
|
-
let res
|
|
259
|
-
try {
|
|
260
|
-
res = factory(resolve, reject)
|
|
261
|
-
} catch (e) {
|
|
262
|
-
reject(e)
|
|
263
|
-
}
|
|
264
|
-
if (res) {
|
|
265
|
-
if (typeof res.then === 'function') {
|
|
266
|
-
res.then(resolve, reject).catch(reject)
|
|
267
|
-
} else {
|
|
268
|
-
// new syntax in 2.3
|
|
269
|
-
const comp = res.component
|
|
270
|
-
if (comp && typeof comp.then === 'function') {
|
|
271
|
-
comp.then(resolve, reject).catch(reject)
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
function renderStringNode (el, context) {
|
|
278
|
-
const { write, next } = context
|
|
279
|
-
if (isUndef(el.children) || el.children.length === 0) {
|
|
280
|
-
write(el.open + (el.close || ''), next)
|
|
281
|
-
} else {
|
|
282
|
-
const children: Array<VNode> = el.children
|
|
283
|
-
context.renderStates.push({
|
|
284
|
-
type: 'Element',
|
|
285
|
-
children,
|
|
286
|
-
rendered: 0,
|
|
287
|
-
total: children.length,
|
|
288
|
-
endTag: el.close
|
|
289
|
-
})
|
|
290
|
-
write(el.open, next)
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function renderElement (el, isRoot, context) {
|
|
295
|
-
const { write, next } = context
|
|
296
|
-
|
|
297
|
-
if (isTrue(isRoot)) {
|
|
298
|
-
if (!el.data) el.data = {}
|
|
299
|
-
if (!el.data.attrs) el.data.attrs = {}
|
|
300
|
-
el.data.attrs[SSR_ATTR] = 'true'
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
if (el.fnOptions) {
|
|
304
|
-
registerComponentForCache(el.fnOptions, write)
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
const startTag = renderStartingTag(el, context)
|
|
308
|
-
const endTag = `</${el.tag}>`
|
|
309
|
-
if (context.isUnaryTag(el.tag)) {
|
|
310
|
-
write(startTag, next)
|
|
311
|
-
} else if (isUndef(el.children) || el.children.length === 0) {
|
|
312
|
-
write(startTag + endTag, next)
|
|
313
|
-
} else {
|
|
314
|
-
const children: Array<VNode> = el.children
|
|
315
|
-
context.renderStates.push({
|
|
316
|
-
type: 'Element',
|
|
317
|
-
children,
|
|
318
|
-
rendered: 0,
|
|
319
|
-
total: children.length,
|
|
320
|
-
endTag
|
|
321
|
-
})
|
|
322
|
-
write(startTag, next)
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
function hasAncestorData (node: VNode) {
|
|
327
|
-
const parentNode = node.parent
|
|
328
|
-
return isDef(parentNode) && (isDef(parentNode.data) || hasAncestorData(parentNode))
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function getVShowDirectiveInfo (node: VNode): ?VNodeDirective {
|
|
332
|
-
let dir: VNodeDirective
|
|
333
|
-
let tmp
|
|
334
|
-
|
|
335
|
-
while (isDef(node)) {
|
|
336
|
-
if (node.data && node.data.directives) {
|
|
337
|
-
tmp = node.data.directives.find(dir => dir.name === 'show')
|
|
338
|
-
if (tmp) {
|
|
339
|
-
dir = tmp
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
node = node.parent
|
|
343
|
-
}
|
|
344
|
-
return dir
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
function renderStartingTag (node: VNode, context) {
|
|
348
|
-
let markup = `<${node.tag}`
|
|
349
|
-
const { directives, modules } = context
|
|
350
|
-
|
|
351
|
-
// construct synthetic data for module processing
|
|
352
|
-
// because modules like style also produce code by parent VNode data
|
|
353
|
-
if (isUndef(node.data) && hasAncestorData(node)) {
|
|
354
|
-
node.data = {}
|
|
355
|
-
}
|
|
356
|
-
if (isDef(node.data)) {
|
|
357
|
-
// check directives
|
|
358
|
-
const dirs = node.data.directives
|
|
359
|
-
if (dirs) {
|
|
360
|
-
for (let i = 0; i < dirs.length; i++) {
|
|
361
|
-
const name = dirs[i].name
|
|
362
|
-
if (name !== 'show') {
|
|
363
|
-
const dirRenderer = resolveAsset(context, 'directives', name)
|
|
364
|
-
if (dirRenderer) {
|
|
365
|
-
// directives mutate the node's data
|
|
366
|
-
// which then gets rendered by modules
|
|
367
|
-
dirRenderer(node, dirs[i])
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
// v-show directive needs to be merged from parent to child
|
|
374
|
-
const vshowDirectiveInfo = getVShowDirectiveInfo(node)
|
|
375
|
-
if (vshowDirectiveInfo) {
|
|
376
|
-
directives.show(node, vshowDirectiveInfo)
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
// apply other modules
|
|
380
|
-
for (let i = 0; i < modules.length; i++) {
|
|
381
|
-
const res = modules[i](node)
|
|
382
|
-
if (res) {
|
|
383
|
-
markup += res
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
// attach scoped CSS ID
|
|
388
|
-
let scopeId
|
|
389
|
-
const activeInstance = context.activeInstance
|
|
390
|
-
if (isDef(activeInstance) &&
|
|
391
|
-
activeInstance !== node.context &&
|
|
392
|
-
isDef(scopeId = activeInstance.$options._scopeId)
|
|
393
|
-
) {
|
|
394
|
-
markup += ` ${(scopeId: any)}`
|
|
395
|
-
}
|
|
396
|
-
if (isDef(node.fnScopeId)) {
|
|
397
|
-
markup += ` ${node.fnScopeId}`
|
|
398
|
-
} else {
|
|
399
|
-
while (isDef(node)) {
|
|
400
|
-
if (isDef(scopeId = node.context.$options._scopeId)) {
|
|
401
|
-
markup += ` ${scopeId}`
|
|
402
|
-
}
|
|
403
|
-
node = node.parent
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
return markup + '>'
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
export function createRenderFunction (
|
|
410
|
-
modules: Array<(node: VNode) => ?string>,
|
|
411
|
-
directives: Object,
|
|
412
|
-
isUnaryTag: Function,
|
|
413
|
-
cache: any
|
|
414
|
-
) {
|
|
415
|
-
return function render (
|
|
416
|
-
component: Component,
|
|
417
|
-
write: (text: string, next: Function) => void,
|
|
418
|
-
userContext: ?Object,
|
|
419
|
-
done: Function
|
|
420
|
-
) {
|
|
421
|
-
warned = Object.create(null)
|
|
422
|
-
const context = new RenderContext({
|
|
423
|
-
activeInstance: component,
|
|
424
|
-
userContext,
|
|
425
|
-
write, done, renderNode,
|
|
426
|
-
isUnaryTag, modules, directives,
|
|
427
|
-
cache
|
|
428
|
-
})
|
|
429
|
-
installSSRHelpers(component)
|
|
430
|
-
normalizeRender(component)
|
|
431
|
-
|
|
432
|
-
const resolve = () => {
|
|
433
|
-
renderNode(component._render(), true, context)
|
|
434
|
-
}
|
|
435
|
-
waitForServerPrefetch(component, resolve, done)
|
|
436
|
-
}
|
|
437
|
-
}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates a mapper that maps components used during a server-side render
|
|
5
|
-
* to async chunk files in the client-side build, so that we can inline them
|
|
6
|
-
* directly in the rendered HTML to avoid waterfall requests.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { ClientManifest } from './index'
|
|
10
|
-
|
|
11
|
-
export type AsyncFileMapper = (files: Array<string>) => Array<string>;
|
|
12
|
-
|
|
13
|
-
export function createMapper (
|
|
14
|
-
clientManifest: ClientManifest
|
|
15
|
-
): AsyncFileMapper {
|
|
16
|
-
const map = createMap(clientManifest)
|
|
17
|
-
// map server-side moduleIds to client-side files
|
|
18
|
-
return function mapper (moduleIds: Array<string>): Array<string> {
|
|
19
|
-
const res = new Set()
|
|
20
|
-
for (let i = 0; i < moduleIds.length; i++) {
|
|
21
|
-
const mapped = map.get(moduleIds[i])
|
|
22
|
-
if (mapped) {
|
|
23
|
-
for (let j = 0; j < mapped.length; j++) {
|
|
24
|
-
res.add(mapped[j])
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return Array.from(res)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function createMap (clientManifest) {
|
|
33
|
-
const map = new Map()
|
|
34
|
-
Object.keys(clientManifest.modules).forEach(id => {
|
|
35
|
-
map.set(id, mapIdToFile(id, clientManifest))
|
|
36
|
-
})
|
|
37
|
-
return map
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function mapIdToFile (id, clientManifest) {
|
|
41
|
-
const files = []
|
|
42
|
-
const fileIndices = clientManifest.modules[id]
|
|
43
|
-
if (fileIndices) {
|
|
44
|
-
fileIndices.forEach(index => {
|
|
45
|
-
const file = clientManifest.all[index]
|
|
46
|
-
// only include async files or non-js, non-css assets
|
|
47
|
-
if (
|
|
48
|
-
file &&
|
|
49
|
-
(clientManifest.async.indexOf(file) > -1 ||
|
|
50
|
-
!/\.(js|css)($|\?)/.test(file))
|
|
51
|
-
) {
|
|
52
|
-
files.push(file)
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
}
|
|
56
|
-
return files
|
|
57
|
-
}
|