@nest-vue/vue-security-patched 2.7.16-patch.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/LICENSE +21 -0
- package/README.md +122 -0
- 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.js +5 -0
- package/dist/vue.runtime.common.js +5 -0
- package/dist/vue.runtime.mjs +76 -0
- package/package.json +136 -0
- package/packages/compiler-sfc/api-extractor.json +64 -0
- package/packages/compiler-sfc/dist/compiler-sfc.js +17146 -0
- package/packages/compiler-sfc/node_modules/.bin/lessc +17 -0
- package/packages/compiler-sfc/node_modules/.bin/parser +17 -0
- package/packages/compiler-sfc/node_modules/.bin/prettier +17 -0
- package/packages/compiler-sfc/node_modules/.bin/sass +17 -0
- package/packages/compiler-sfc/node_modules/.bin/stylus +17 -0
- package/packages/compiler-sfc/package.json +37 -0
- package/packages/compiler-sfc/src/babelUtils.ts +423 -0
- package/packages/compiler-sfc/src/compileScript.ts +1916 -0
- package/packages/compiler-sfc/src/compileStyle.ts +147 -0
- package/packages/compiler-sfc/src/compileTemplate.ts +205 -0
- package/packages/compiler-sfc/src/cssVars.ts +179 -0
- package/packages/compiler-sfc/src/index.ts +31 -0
- package/packages/compiler-sfc/src/parse.ts +129 -0
- package/packages/compiler-sfc/src/parseComponent.ts +220 -0
- package/packages/compiler-sfc/src/prefixIdentifiers.ts +82 -0
- package/packages/compiler-sfc/src/rewriteDefault.ts +121 -0
- package/packages/compiler-sfc/src/stylePlugins/scoped.ts +203 -0
- package/packages/compiler-sfc/src/stylePlugins/trim.ts +18 -0
- package/packages/compiler-sfc/src/stylePreprocessors.ts +135 -0
- package/packages/compiler-sfc/src/templateCompilerModules/assetUrl.ts +84 -0
- package/packages/compiler-sfc/src/templateCompilerModules/srcset.ts +76 -0
- package/packages/compiler-sfc/src/templateCompilerModules/utils.ts +86 -0
- package/packages/compiler-sfc/src/types.ts +69 -0
- package/packages/compiler-sfc/src/warn.ts +16 -0
- package/packages/compiler-sfc/test/__snapshots__/compileScript.spec.ts.snap +971 -0
- package/packages/compiler-sfc/test/__snapshots__/cssVars.spec.ts.snap +189 -0
- package/packages/compiler-sfc/test/compileScript.spec.ts +1635 -0
- package/packages/compiler-sfc/test/compileStyle.spec.ts +203 -0
- package/packages/compiler-sfc/test/compileTemplate.spec.ts +258 -0
- package/packages/compiler-sfc/test/cssVars.spec.ts +247 -0
- package/packages/compiler-sfc/test/parseComponent.spec.ts +269 -0
- package/packages/compiler-sfc/test/prefixIdentifiers.spec.ts +97 -0
- package/packages/compiler-sfc/test/rewriteDefault.spec.ts +311 -0
- package/packages/compiler-sfc/test/stylePluginScoped.spec.ts +137 -0
- package/packages/compiler-sfc/test/tsconfig.json +7 -0
- package/packages/compiler-sfc/test/util.ts +35 -0
- package/src/compiler/codeframe.ts +52 -0
- package/src/compiler/codegen/events.ts +170 -0
- package/src/compiler/codegen/index.ts +668 -0
- package/src/compiler/create-compiler.ts +83 -0
- package/src/compiler/directives/bind.ts +9 -0
- package/src/compiler/directives/index.ts +9 -0
- package/src/compiler/directives/model.ts +145 -0
- package/src/compiler/directives/on.ts +9 -0
- package/src/compiler/error-detector.ts +158 -0
- package/src/compiler/helpers.ts +243 -0
- package/src/compiler/index.ts +24 -0
- package/src/compiler/optimizer.ts +135 -0
- package/src/compiler/parser/entity-decoder.ts +9 -0
- package/src/compiler/parser/filter-parser.ts +116 -0
- package/src/compiler/parser/html-parser.ts +345 -0
- package/src/compiler/parser/index.ts +999 -0
- package/src/compiler/parser/text-parser.ts +52 -0
- package/src/compiler/to-function.ts +119 -0
- package/src/core/components/index.ts +5 -0
- package/src/core/components/keep-alive.ts +171 -0
- package/src/core/config.ts +128 -0
- package/src/core/global-api/assets.ts +35 -0
- package/src/core/global-api/extend.ts +94 -0
- package/src/core/global-api/index.ts +68 -0
- package/src/core/global-api/mixin.ts +9 -0
- package/src/core/global-api/use.ts +23 -0
- package/src/core/index.ts +27 -0
- package/src/core/instance/events.ts +160 -0
- package/src/core/instance/index.ts +27 -0
- package/src/core/instance/init.ts +143 -0
- package/src/core/instance/inject.ts +80 -0
- package/src/core/instance/lifecycle.ts +421 -0
- package/src/core/instance/proxy.ts +97 -0
- package/src/core/instance/render-helpers/bind-dynamic-keys.ts +36 -0
- package/src/core/instance/render-helpers/bind-object-listeners.ts +18 -0
- package/src/core/instance/render-helpers/bind-object-props.ts +59 -0
- package/src/core/instance/render-helpers/check-keycodes.ts +33 -0
- package/src/core/instance/render-helpers/index.ts +31 -0
- package/src/core/instance/render-helpers/render-list.ts +49 -0
- package/src/core/instance/render-helpers/render-slot.ts +39 -0
- package/src/core/instance/render-helpers/render-static.ts +57 -0
- package/src/core/instance/render-helpers/resolve-filter.ts +8 -0
- package/src/core/instance/render-helpers/resolve-scoped-slots.ts +30 -0
- package/src/core/instance/render-helpers/resolve-slots.ts +51 -0
- package/src/core/instance/render.ts +172 -0
- package/src/core/instance/state.ts +393 -0
- package/src/core/observer/array.ts +54 -0
- package/src/core/observer/dep.ts +108 -0
- package/src/core/observer/index.ts +339 -0
- package/src/core/observer/scheduler.ts +199 -0
- package/src/core/observer/traverse.ts +47 -0
- package/src/core/observer/watcher.ts +278 -0
- package/src/core/util/debug.ts +105 -0
- package/src/core/util/env.ts +93 -0
- package/src/core/util/error.ts +81 -0
- package/src/core/util/index.ts +9 -0
- package/src/core/util/lang.ts +45 -0
- package/src/core/util/next-tick.ts +117 -0
- package/src/core/util/options.ts +489 -0
- package/src/core/util/perf.ts +28 -0
- package/src/core/util/props.ts +254 -0
- package/src/core/vdom/create-component.ts +275 -0
- package/src/core/vdom/create-element.ts +172 -0
- package/src/core/vdom/create-functional-component.ts +180 -0
- package/src/core/vdom/helpers/extract-props.ts +75 -0
- package/src/core/vdom/helpers/get-first-component-child.ts +16 -0
- package/src/core/vdom/helpers/index.ts +7 -0
- package/src/core/vdom/helpers/is-async-placeholder.ts +6 -0
- package/src/core/vdom/helpers/merge-hook.ts +40 -0
- package/src/core/vdom/helpers/normalize-children.ts +99 -0
- package/src/core/vdom/helpers/normalize-scoped-slots.ts +97 -0
- package/src/core/vdom/helpers/resolve-async-component.ts +157 -0
- package/src/core/vdom/helpers/update-listeners.ts +101 -0
- package/src/core/vdom/modules/directives.ts +137 -0
- package/src/core/vdom/modules/index.ts +4 -0
- package/src/core/vdom/modules/template-ref.ts +94 -0
- package/src/core/vdom/patch.ts +907 -0
- package/src/core/vdom/vnode.ts +119 -0
- package/src/global.d.ts +17 -0
- package/src/platforms/web/compiler/directives/html.ts +8 -0
- package/src/platforms/web/compiler/directives/index.ts +9 -0
- package/src/platforms/web/compiler/directives/model.ts +181 -0
- package/src/platforms/web/compiler/directives/text.ts +8 -0
- package/src/platforms/web/compiler/index.ts +6 -0
- package/src/platforms/web/compiler/modules/class.ts +44 -0
- package/src/platforms/web/compiler/modules/index.ts +5 -0
- package/src/platforms/web/compiler/modules/model.ts +89 -0
- package/src/platforms/web/compiler/modules/style.ts +47 -0
- package/src/platforms/web/compiler/options.ts +25 -0
- package/src/platforms/web/compiler/util.ts +22 -0
- package/src/platforms/web/entry-compiler.ts +4 -0
- package/src/platforms/web/entry-runtime-esm.ts +5 -0
- 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.ts +61 -0
- package/src/platforms/web/runtime/components/index.ts +7 -0
- package/src/platforms/web/runtime/components/transition-group.ts +204 -0
- package/src/platforms/web/runtime/components/transition.ts +205 -0
- package/src/platforms/web/runtime/directives/index.ts +7 -0
- package/src/platforms/web/runtime/directives/model.ts +148 -0
- package/src/platforms/web/runtime/directives/show.ts +61 -0
- package/src/platforms/web/runtime/index.ts +75 -0
- package/src/platforms/web/runtime/modules/attrs.ts +115 -0
- package/src/platforms/web/runtime/modules/class.ts +37 -0
- package/src/platforms/web/runtime/modules/dom-props.ts +123 -0
- package/src/platforms/web/runtime/modules/events.ts +127 -0
- package/src/platforms/web/runtime/modules/index.ts +8 -0
- package/src/platforms/web/runtime/modules/style.ts +102 -0
- package/src/platforms/web/runtime/modules/transition.ts +341 -0
- package/src/platforms/web/runtime/node-ops.ts +66 -0
- package/src/platforms/web/runtime/patch.ts +10 -0
- package/src/platforms/web/runtime/transition-util.ts +215 -0
- package/src/platforms/web/runtime-with-compiler.ts +110 -0
- package/src/platforms/web/util/attrs.ts +58 -0
- package/src/platforms/web/util/class.ts +87 -0
- package/src/platforms/web/util/compat.ts +16 -0
- package/src/platforms/web/util/element.ts +76 -0
- package/src/platforms/web/util/index.ts +21 -0
- package/src/platforms/web/util/style.ts +71 -0
- package/src/shared/constants.ts +20 -0
- package/src/shared/util.ts +378 -0
- package/src/types/compiler.ts +207 -0
- package/src/types/component.ts +212 -0
- package/src/types/global-api.ts +37 -0
- package/src/types/modules.d.ts +15 -0
- package/src/types/options.ts +114 -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/apiAsyncComponent.ts +117 -0
- package/src/v3/apiInject.ts +71 -0
- package/src/v3/apiLifecycle.ts +68 -0
- package/src/v3/apiSetup.ts +246 -0
- package/src/v3/apiWatch.ts +353 -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 +96 -0
- package/src/v3/reactivity/computed.ts +100 -0
- package/src/v3/reactivity/effect.ts +20 -0
- package/src/v3/reactivity/effectScope.ts +137 -0
- package/src/v3/reactivity/operations.ts +14 -0
- package/src/v3/reactivity/reactive.ts +137 -0
- package/src/v3/reactivity/readonly.ts +127 -0
- package/src/v3/reactivity/ref.ts +293 -0
- package/src/v3/sfc-helpers/useCssModule.ts +24 -0
- package/src/v3/sfc-helpers/useCssVars.ts +34 -0
- package/types/built-in-components.d.ts +63 -0
- package/types/common.d.ts +21 -0
- package/types/index.d.ts +81 -0
- package/types/jsx.d.ts +1353 -0
- package/types/options.d.ts +349 -0
- package/types/plugin.d.ts +8 -0
- package/types/umd.d.ts +68 -0
- package/types/v3-component-options.d.ts +252 -0
- package/types/v3-component-props.d.ts +99 -0
- package/types/v3-component-public-instance.d.ts +232 -0
- package/types/v3-define-async-component.d.ts +26 -0
- package/types/v3-define-component.d.ts +201 -0
- package/types/v3-directive.d.ts +29 -0
- package/types/v3-manual-apis.d.ts +10 -0
- package/types/v3-setup-context.d.ts +41 -0
- package/types/v3-setup-helpers.d.ts +154 -0
- package/types/vnode.d.ts +117 -0
- package/types/vue.d.ts +446 -0
|
@@ -0,0 +1,907 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Virtual DOM patching algorithm based on Snabbdom by
|
|
3
|
+
* Simon Friis Vindum (@paldepind)
|
|
4
|
+
* Licensed under the MIT License
|
|
5
|
+
* https://github.com/paldepind/snabbdom/blob/master/LICENSE
|
|
6
|
+
*
|
|
7
|
+
* modified by Evan You (@yyx990803)
|
|
8
|
+
*
|
|
9
|
+
* Not type-checking this because this file is perf-critical and the cost
|
|
10
|
+
* of making flow understand it is not worth it.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import VNode, { cloneVNode } from './vnode'
|
|
14
|
+
import config from '../config'
|
|
15
|
+
import { SSR_ATTR } from 'shared/constants'
|
|
16
|
+
import { registerRef } from './modules/template-ref'
|
|
17
|
+
import { traverse } from '../observer/traverse'
|
|
18
|
+
import { activeInstance } from '../instance/lifecycle'
|
|
19
|
+
import { isTextInputType } from 'web/util/element'
|
|
20
|
+
|
|
21
|
+
import {
|
|
22
|
+
warn,
|
|
23
|
+
isDef,
|
|
24
|
+
isUndef,
|
|
25
|
+
isTrue,
|
|
26
|
+
isArray,
|
|
27
|
+
makeMap,
|
|
28
|
+
isRegExp,
|
|
29
|
+
isPrimitive
|
|
30
|
+
} from '../util/index'
|
|
31
|
+
|
|
32
|
+
export const emptyNode = new VNode('', {}, [])
|
|
33
|
+
|
|
34
|
+
const hooks = ['create', 'activate', 'update', 'remove', 'destroy']
|
|
35
|
+
|
|
36
|
+
function sameVnode(a, b) {
|
|
37
|
+
return (
|
|
38
|
+
a.key === b.key &&
|
|
39
|
+
a.asyncFactory === b.asyncFactory &&
|
|
40
|
+
((a.tag === b.tag &&
|
|
41
|
+
a.isComment === b.isComment &&
|
|
42
|
+
isDef(a.data) === isDef(b.data) &&
|
|
43
|
+
sameInputType(a, b)) ||
|
|
44
|
+
(isTrue(a.isAsyncPlaceholder) && isUndef(b.asyncFactory.error)))
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function sameInputType(a, b) {
|
|
49
|
+
if (a.tag !== 'input') return true
|
|
50
|
+
let i
|
|
51
|
+
const typeA = isDef((i = a.data)) && isDef((i = i.attrs)) && i.type
|
|
52
|
+
const typeB = isDef((i = b.data)) && isDef((i = i.attrs)) && i.type
|
|
53
|
+
return typeA === typeB || (isTextInputType(typeA) && isTextInputType(typeB))
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function createKeyToOldIdx(children, beginIdx, endIdx) {
|
|
57
|
+
let i, key
|
|
58
|
+
const map = {}
|
|
59
|
+
for (i = beginIdx; i <= endIdx; ++i) {
|
|
60
|
+
key = children[i].key
|
|
61
|
+
if (isDef(key)) map[key] = i
|
|
62
|
+
}
|
|
63
|
+
return map
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function createPatchFunction(backend) {
|
|
67
|
+
let i, j
|
|
68
|
+
const cbs: any = {}
|
|
69
|
+
|
|
70
|
+
const { modules, nodeOps } = backend
|
|
71
|
+
|
|
72
|
+
for (i = 0; i < hooks.length; ++i) {
|
|
73
|
+
cbs[hooks[i]] = []
|
|
74
|
+
for (j = 0; j < modules.length; ++j) {
|
|
75
|
+
if (isDef(modules[j][hooks[i]])) {
|
|
76
|
+
cbs[hooks[i]].push(modules[j][hooks[i]])
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function emptyNodeAt(elm) {
|
|
82
|
+
return new VNode(nodeOps.tagName(elm).toLowerCase(), {}, [], undefined, elm)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function createRmCb(childElm, listeners) {
|
|
86
|
+
function remove() {
|
|
87
|
+
if (--remove.listeners === 0) {
|
|
88
|
+
removeNode(childElm)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
remove.listeners = listeners
|
|
92
|
+
return remove
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function removeNode(el) {
|
|
96
|
+
const parent = nodeOps.parentNode(el)
|
|
97
|
+
// element may have already been removed due to v-html / v-text
|
|
98
|
+
if (isDef(parent)) {
|
|
99
|
+
nodeOps.removeChild(parent, el)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function isUnknownElement(vnode, inVPre) {
|
|
104
|
+
return (
|
|
105
|
+
!inVPre &&
|
|
106
|
+
!vnode.ns &&
|
|
107
|
+
!(
|
|
108
|
+
config.ignoredElements.length &&
|
|
109
|
+
config.ignoredElements.some(ignore => {
|
|
110
|
+
return isRegExp(ignore)
|
|
111
|
+
? ignore.test(vnode.tag)
|
|
112
|
+
: ignore === vnode.tag
|
|
113
|
+
})
|
|
114
|
+
) &&
|
|
115
|
+
config.isUnknownElement(vnode.tag)
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
let creatingElmInVPre = 0
|
|
120
|
+
|
|
121
|
+
function createElm(
|
|
122
|
+
vnode,
|
|
123
|
+
insertedVnodeQueue,
|
|
124
|
+
parentElm?: any,
|
|
125
|
+
refElm?: any,
|
|
126
|
+
nested?: any,
|
|
127
|
+
ownerArray?: any,
|
|
128
|
+
index?: any
|
|
129
|
+
) {
|
|
130
|
+
if (isDef(vnode.elm) && isDef(ownerArray)) {
|
|
131
|
+
// This vnode was used in a previous render!
|
|
132
|
+
// now it's used as a new node, overwriting its elm would cause
|
|
133
|
+
// potential patch errors down the road when it's used as an insertion
|
|
134
|
+
// reference node. Instead, we clone the node on-demand before creating
|
|
135
|
+
// associated DOM element for it.
|
|
136
|
+
vnode = ownerArray[index] = cloneVNode(vnode)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
vnode.isRootInsert = !nested // for transition enter check
|
|
140
|
+
if (createComponent(vnode, insertedVnodeQueue, parentElm, refElm)) {
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const data = vnode.data
|
|
145
|
+
const children = vnode.children
|
|
146
|
+
const tag = vnode.tag
|
|
147
|
+
if (isDef(tag)) {
|
|
148
|
+
if (__DEV__) {
|
|
149
|
+
if (data && data.pre) {
|
|
150
|
+
creatingElmInVPre++
|
|
151
|
+
}
|
|
152
|
+
if (isUnknownElement(vnode, creatingElmInVPre)) {
|
|
153
|
+
warn(
|
|
154
|
+
'Unknown custom element: <' +
|
|
155
|
+
tag +
|
|
156
|
+
'> - did you ' +
|
|
157
|
+
'register the component correctly? For recursive components, ' +
|
|
158
|
+
'make sure to provide the "name" option.',
|
|
159
|
+
vnode.context
|
|
160
|
+
)
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
vnode.elm = vnode.ns
|
|
165
|
+
? nodeOps.createElementNS(vnode.ns, tag)
|
|
166
|
+
: nodeOps.createElement(tag, vnode)
|
|
167
|
+
setScope(vnode)
|
|
168
|
+
|
|
169
|
+
createChildren(vnode, children, insertedVnodeQueue)
|
|
170
|
+
if (isDef(data)) {
|
|
171
|
+
invokeCreateHooks(vnode, insertedVnodeQueue)
|
|
172
|
+
}
|
|
173
|
+
insert(parentElm, vnode.elm, refElm)
|
|
174
|
+
|
|
175
|
+
if (__DEV__ && data && data.pre) {
|
|
176
|
+
creatingElmInVPre--
|
|
177
|
+
}
|
|
178
|
+
} else if (isTrue(vnode.isComment)) {
|
|
179
|
+
vnode.elm = nodeOps.createComment(vnode.text)
|
|
180
|
+
insert(parentElm, vnode.elm, refElm)
|
|
181
|
+
} else {
|
|
182
|
+
vnode.elm = nodeOps.createTextNode(vnode.text)
|
|
183
|
+
insert(parentElm, vnode.elm, refElm)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
function createComponent(vnode, insertedVnodeQueue, parentElm, refElm) {
|
|
188
|
+
let i = vnode.data
|
|
189
|
+
if (isDef(i)) {
|
|
190
|
+
const isReactivated = isDef(vnode.componentInstance) && i.keepAlive
|
|
191
|
+
if (isDef((i = i.hook)) && isDef((i = i.init))) {
|
|
192
|
+
i(vnode, false /* hydrating */)
|
|
193
|
+
}
|
|
194
|
+
// after calling the init hook, if the vnode is a child component
|
|
195
|
+
// it should've created a child instance and mounted it. the child
|
|
196
|
+
// component also has set the placeholder vnode's elm.
|
|
197
|
+
// in that case we can just return the element and be done.
|
|
198
|
+
if (isDef(vnode.componentInstance)) {
|
|
199
|
+
initComponent(vnode, insertedVnodeQueue)
|
|
200
|
+
insert(parentElm, vnode.elm, refElm)
|
|
201
|
+
if (isTrue(isReactivated)) {
|
|
202
|
+
reactivateComponent(vnode, insertedVnodeQueue, parentElm, refElm)
|
|
203
|
+
}
|
|
204
|
+
return true
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function initComponent(vnode, insertedVnodeQueue) {
|
|
210
|
+
if (isDef(vnode.data.pendingInsert)) {
|
|
211
|
+
insertedVnodeQueue.push.apply(
|
|
212
|
+
insertedVnodeQueue,
|
|
213
|
+
vnode.data.pendingInsert
|
|
214
|
+
)
|
|
215
|
+
vnode.data.pendingInsert = null
|
|
216
|
+
}
|
|
217
|
+
vnode.elm = vnode.componentInstance.$el
|
|
218
|
+
if (isPatchable(vnode)) {
|
|
219
|
+
invokeCreateHooks(vnode, insertedVnodeQueue)
|
|
220
|
+
setScope(vnode)
|
|
221
|
+
} else {
|
|
222
|
+
// empty component root.
|
|
223
|
+
// skip all element-related modules except for ref (#3455)
|
|
224
|
+
registerRef(vnode)
|
|
225
|
+
// make sure to invoke the insert hook
|
|
226
|
+
insertedVnodeQueue.push(vnode)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function reactivateComponent(vnode, insertedVnodeQueue, parentElm, refElm) {
|
|
231
|
+
let i
|
|
232
|
+
// hack for #4339: a reactivated component with inner transition
|
|
233
|
+
// does not trigger because the inner node's created hooks are not called
|
|
234
|
+
// again. It's not ideal to involve module-specific logic in here but
|
|
235
|
+
// there doesn't seem to be a better way to do it.
|
|
236
|
+
let innerNode = vnode
|
|
237
|
+
while (innerNode.componentInstance) {
|
|
238
|
+
innerNode = innerNode.componentInstance._vnode
|
|
239
|
+
if (isDef((i = innerNode.data)) && isDef((i = i.transition))) {
|
|
240
|
+
for (i = 0; i < cbs.activate.length; ++i) {
|
|
241
|
+
cbs.activate[i](emptyNode, innerNode)
|
|
242
|
+
}
|
|
243
|
+
insertedVnodeQueue.push(innerNode)
|
|
244
|
+
break
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
// unlike a newly created component,
|
|
248
|
+
// a reactivated keep-alive component doesn't insert itself
|
|
249
|
+
insert(parentElm, vnode.elm, refElm)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function insert(parent, elm, ref) {
|
|
253
|
+
if (isDef(parent)) {
|
|
254
|
+
if (isDef(ref)) {
|
|
255
|
+
if (nodeOps.parentNode(ref) === parent) {
|
|
256
|
+
nodeOps.insertBefore(parent, elm, ref)
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
nodeOps.appendChild(parent, elm)
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function createChildren(vnode, children, insertedVnodeQueue) {
|
|
265
|
+
if (isArray(children)) {
|
|
266
|
+
if (__DEV__) {
|
|
267
|
+
checkDuplicateKeys(children)
|
|
268
|
+
}
|
|
269
|
+
for (let i = 0; i < children.length; ++i) {
|
|
270
|
+
createElm(
|
|
271
|
+
children[i],
|
|
272
|
+
insertedVnodeQueue,
|
|
273
|
+
vnode.elm,
|
|
274
|
+
null,
|
|
275
|
+
true,
|
|
276
|
+
children,
|
|
277
|
+
i
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
} else if (isPrimitive(vnode.text)) {
|
|
281
|
+
nodeOps.appendChild(vnode.elm, nodeOps.createTextNode(String(vnode.text)))
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function isPatchable(vnode) {
|
|
286
|
+
while (vnode.componentInstance) {
|
|
287
|
+
vnode = vnode.componentInstance._vnode
|
|
288
|
+
}
|
|
289
|
+
return isDef(vnode.tag)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function invokeCreateHooks(vnode, insertedVnodeQueue) {
|
|
293
|
+
for (let i = 0; i < cbs.create.length; ++i) {
|
|
294
|
+
cbs.create[i](emptyNode, vnode)
|
|
295
|
+
}
|
|
296
|
+
i = vnode.data.hook // Reuse variable
|
|
297
|
+
if (isDef(i)) {
|
|
298
|
+
if (isDef(i.create)) i.create(emptyNode, vnode)
|
|
299
|
+
if (isDef(i.insert)) insertedVnodeQueue.push(vnode)
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// set scope id attribute for scoped CSS.
|
|
304
|
+
// this is implemented as a special case to avoid the overhead
|
|
305
|
+
// of going through the normal attribute patching process.
|
|
306
|
+
function setScope(vnode) {
|
|
307
|
+
let i
|
|
308
|
+
if (isDef((i = vnode.fnScopeId))) {
|
|
309
|
+
nodeOps.setStyleScope(vnode.elm, i)
|
|
310
|
+
} else {
|
|
311
|
+
let ancestor = vnode
|
|
312
|
+
while (ancestor) {
|
|
313
|
+
if (isDef((i = ancestor.context)) && isDef((i = i.$options._scopeId))) {
|
|
314
|
+
nodeOps.setStyleScope(vnode.elm, i)
|
|
315
|
+
}
|
|
316
|
+
ancestor = ancestor.parent
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
// for slot content they should also get the scopeId from the host instance.
|
|
320
|
+
if (
|
|
321
|
+
isDef((i = activeInstance)) &&
|
|
322
|
+
i !== vnode.context &&
|
|
323
|
+
i !== vnode.fnContext &&
|
|
324
|
+
isDef((i = i.$options._scopeId))
|
|
325
|
+
) {
|
|
326
|
+
nodeOps.setStyleScope(vnode.elm, i)
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function addVnodes(
|
|
331
|
+
parentElm,
|
|
332
|
+
refElm,
|
|
333
|
+
vnodes,
|
|
334
|
+
startIdx,
|
|
335
|
+
endIdx,
|
|
336
|
+
insertedVnodeQueue
|
|
337
|
+
) {
|
|
338
|
+
for (; startIdx <= endIdx; ++startIdx) {
|
|
339
|
+
createElm(
|
|
340
|
+
vnodes[startIdx],
|
|
341
|
+
insertedVnodeQueue,
|
|
342
|
+
parentElm,
|
|
343
|
+
refElm,
|
|
344
|
+
false,
|
|
345
|
+
vnodes,
|
|
346
|
+
startIdx
|
|
347
|
+
)
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function invokeDestroyHook(vnode) {
|
|
352
|
+
let i, j
|
|
353
|
+
const data = vnode.data
|
|
354
|
+
if (isDef(data)) {
|
|
355
|
+
if (isDef((i = data.hook)) && isDef((i = i.destroy))) i(vnode)
|
|
356
|
+
for (i = 0; i < cbs.destroy.length; ++i) cbs.destroy[i](vnode)
|
|
357
|
+
}
|
|
358
|
+
if (isDef((i = vnode.children))) {
|
|
359
|
+
for (j = 0; j < vnode.children.length; ++j) {
|
|
360
|
+
invokeDestroyHook(vnode.children[j])
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function removeVnodes(vnodes, startIdx, endIdx) {
|
|
366
|
+
for (; startIdx <= endIdx; ++startIdx) {
|
|
367
|
+
const ch = vnodes[startIdx]
|
|
368
|
+
if (isDef(ch)) {
|
|
369
|
+
if (isDef(ch.tag)) {
|
|
370
|
+
removeAndInvokeRemoveHook(ch)
|
|
371
|
+
invokeDestroyHook(ch)
|
|
372
|
+
} else {
|
|
373
|
+
// Text node
|
|
374
|
+
removeNode(ch.elm)
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function removeAndInvokeRemoveHook(vnode, rm?: any) {
|
|
381
|
+
if (isDef(rm) || isDef(vnode.data)) {
|
|
382
|
+
let i
|
|
383
|
+
const listeners = cbs.remove.length + 1
|
|
384
|
+
if (isDef(rm)) {
|
|
385
|
+
// we have a recursively passed down rm callback
|
|
386
|
+
// increase the listeners count
|
|
387
|
+
rm.listeners += listeners
|
|
388
|
+
} else {
|
|
389
|
+
// directly removing
|
|
390
|
+
rm = createRmCb(vnode.elm, listeners)
|
|
391
|
+
}
|
|
392
|
+
// recursively invoke hooks on child component root node
|
|
393
|
+
if (
|
|
394
|
+
isDef((i = vnode.componentInstance)) &&
|
|
395
|
+
isDef((i = i._vnode)) &&
|
|
396
|
+
isDef(i.data)
|
|
397
|
+
) {
|
|
398
|
+
removeAndInvokeRemoveHook(i, rm)
|
|
399
|
+
}
|
|
400
|
+
for (i = 0; i < cbs.remove.length; ++i) {
|
|
401
|
+
cbs.remove[i](vnode, rm)
|
|
402
|
+
}
|
|
403
|
+
if (isDef((i = vnode.data.hook)) && isDef((i = i.remove))) {
|
|
404
|
+
i(vnode, rm)
|
|
405
|
+
} else {
|
|
406
|
+
rm()
|
|
407
|
+
}
|
|
408
|
+
} else {
|
|
409
|
+
removeNode(vnode.elm)
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
function updateChildren(
|
|
414
|
+
parentElm,
|
|
415
|
+
oldCh,
|
|
416
|
+
newCh,
|
|
417
|
+
insertedVnodeQueue,
|
|
418
|
+
removeOnly
|
|
419
|
+
) {
|
|
420
|
+
let oldStartIdx = 0
|
|
421
|
+
let newStartIdx = 0
|
|
422
|
+
let oldEndIdx = oldCh.length - 1
|
|
423
|
+
let oldStartVnode = oldCh[0]
|
|
424
|
+
let oldEndVnode = oldCh[oldEndIdx]
|
|
425
|
+
let newEndIdx = newCh.length - 1
|
|
426
|
+
let newStartVnode = newCh[0]
|
|
427
|
+
let newEndVnode = newCh[newEndIdx]
|
|
428
|
+
let oldKeyToIdx, idxInOld, vnodeToMove, refElm
|
|
429
|
+
|
|
430
|
+
// removeOnly is a special flag used only by <transition-group>
|
|
431
|
+
// to ensure removed elements stay in correct relative positions
|
|
432
|
+
// during leaving transitions
|
|
433
|
+
const canMove = !removeOnly
|
|
434
|
+
|
|
435
|
+
if (__DEV__) {
|
|
436
|
+
checkDuplicateKeys(newCh)
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
while (oldStartIdx <= oldEndIdx && newStartIdx <= newEndIdx) {
|
|
440
|
+
if (isUndef(oldStartVnode)) {
|
|
441
|
+
oldStartVnode = oldCh[++oldStartIdx] // Vnode has been moved left
|
|
442
|
+
} else if (isUndef(oldEndVnode)) {
|
|
443
|
+
oldEndVnode = oldCh[--oldEndIdx]
|
|
444
|
+
} else if (sameVnode(oldStartVnode, newStartVnode)) {
|
|
445
|
+
patchVnode(
|
|
446
|
+
oldStartVnode,
|
|
447
|
+
newStartVnode,
|
|
448
|
+
insertedVnodeQueue,
|
|
449
|
+
newCh,
|
|
450
|
+
newStartIdx
|
|
451
|
+
)
|
|
452
|
+
oldStartVnode = oldCh[++oldStartIdx]
|
|
453
|
+
newStartVnode = newCh[++newStartIdx]
|
|
454
|
+
} else if (sameVnode(oldEndVnode, newEndVnode)) {
|
|
455
|
+
patchVnode(
|
|
456
|
+
oldEndVnode,
|
|
457
|
+
newEndVnode,
|
|
458
|
+
insertedVnodeQueue,
|
|
459
|
+
newCh,
|
|
460
|
+
newEndIdx
|
|
461
|
+
)
|
|
462
|
+
oldEndVnode = oldCh[--oldEndIdx]
|
|
463
|
+
newEndVnode = newCh[--newEndIdx]
|
|
464
|
+
} else if (sameVnode(oldStartVnode, newEndVnode)) {
|
|
465
|
+
// Vnode moved right
|
|
466
|
+
patchVnode(
|
|
467
|
+
oldStartVnode,
|
|
468
|
+
newEndVnode,
|
|
469
|
+
insertedVnodeQueue,
|
|
470
|
+
newCh,
|
|
471
|
+
newEndIdx
|
|
472
|
+
)
|
|
473
|
+
canMove &&
|
|
474
|
+
nodeOps.insertBefore(
|
|
475
|
+
parentElm,
|
|
476
|
+
oldStartVnode.elm,
|
|
477
|
+
nodeOps.nextSibling(oldEndVnode.elm)
|
|
478
|
+
)
|
|
479
|
+
oldStartVnode = oldCh[++oldStartIdx]
|
|
480
|
+
newEndVnode = newCh[--newEndIdx]
|
|
481
|
+
} else if (sameVnode(oldEndVnode, newStartVnode)) {
|
|
482
|
+
// Vnode moved left
|
|
483
|
+
patchVnode(
|
|
484
|
+
oldEndVnode,
|
|
485
|
+
newStartVnode,
|
|
486
|
+
insertedVnodeQueue,
|
|
487
|
+
newCh,
|
|
488
|
+
newStartIdx
|
|
489
|
+
)
|
|
490
|
+
canMove &&
|
|
491
|
+
nodeOps.insertBefore(parentElm, oldEndVnode.elm, oldStartVnode.elm)
|
|
492
|
+
oldEndVnode = oldCh[--oldEndIdx]
|
|
493
|
+
newStartVnode = newCh[++newStartIdx]
|
|
494
|
+
} else {
|
|
495
|
+
if (isUndef(oldKeyToIdx))
|
|
496
|
+
oldKeyToIdx = createKeyToOldIdx(oldCh, oldStartIdx, oldEndIdx)
|
|
497
|
+
idxInOld = isDef(newStartVnode.key)
|
|
498
|
+
? oldKeyToIdx[newStartVnode.key]
|
|
499
|
+
: findIdxInOld(newStartVnode, oldCh, oldStartIdx, oldEndIdx)
|
|
500
|
+
if (isUndef(idxInOld)) {
|
|
501
|
+
// New element
|
|
502
|
+
createElm(
|
|
503
|
+
newStartVnode,
|
|
504
|
+
insertedVnodeQueue,
|
|
505
|
+
parentElm,
|
|
506
|
+
oldStartVnode.elm,
|
|
507
|
+
false,
|
|
508
|
+
newCh,
|
|
509
|
+
newStartIdx
|
|
510
|
+
)
|
|
511
|
+
} else {
|
|
512
|
+
vnodeToMove = oldCh[idxInOld]
|
|
513
|
+
if (sameVnode(vnodeToMove, newStartVnode)) {
|
|
514
|
+
patchVnode(
|
|
515
|
+
vnodeToMove,
|
|
516
|
+
newStartVnode,
|
|
517
|
+
insertedVnodeQueue,
|
|
518
|
+
newCh,
|
|
519
|
+
newStartIdx
|
|
520
|
+
)
|
|
521
|
+
oldCh[idxInOld] = undefined
|
|
522
|
+
canMove &&
|
|
523
|
+
nodeOps.insertBefore(
|
|
524
|
+
parentElm,
|
|
525
|
+
vnodeToMove.elm,
|
|
526
|
+
oldStartVnode.elm
|
|
527
|
+
)
|
|
528
|
+
} else {
|
|
529
|
+
// same key but different element. treat as new element
|
|
530
|
+
createElm(
|
|
531
|
+
newStartVnode,
|
|
532
|
+
insertedVnodeQueue,
|
|
533
|
+
parentElm,
|
|
534
|
+
oldStartVnode.elm,
|
|
535
|
+
false,
|
|
536
|
+
newCh,
|
|
537
|
+
newStartIdx
|
|
538
|
+
)
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
newStartVnode = newCh[++newStartIdx]
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
if (oldStartIdx > oldEndIdx) {
|
|
545
|
+
refElm = isUndef(newCh[newEndIdx + 1]) ? null : newCh[newEndIdx + 1].elm
|
|
546
|
+
addVnodes(
|
|
547
|
+
parentElm,
|
|
548
|
+
refElm,
|
|
549
|
+
newCh,
|
|
550
|
+
newStartIdx,
|
|
551
|
+
newEndIdx,
|
|
552
|
+
insertedVnodeQueue
|
|
553
|
+
)
|
|
554
|
+
} else if (newStartIdx > newEndIdx) {
|
|
555
|
+
removeVnodes(oldCh, oldStartIdx, oldEndIdx)
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
function checkDuplicateKeys(children) {
|
|
560
|
+
const seenKeys = {}
|
|
561
|
+
for (let i = 0; i < children.length; i++) {
|
|
562
|
+
const vnode = children[i]
|
|
563
|
+
const key = vnode.key
|
|
564
|
+
if (isDef(key)) {
|
|
565
|
+
if (seenKeys[key]) {
|
|
566
|
+
warn(
|
|
567
|
+
`Duplicate keys detected: '${key}'. This may cause an update error.`,
|
|
568
|
+
vnode.context
|
|
569
|
+
)
|
|
570
|
+
} else {
|
|
571
|
+
seenKeys[key] = true
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
function findIdxInOld(node, oldCh, start, end) {
|
|
578
|
+
for (let i = start; i < end; i++) {
|
|
579
|
+
const c = oldCh[i]
|
|
580
|
+
if (isDef(c) && sameVnode(node, c)) return i
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
function patchVnode(
|
|
585
|
+
oldVnode,
|
|
586
|
+
vnode,
|
|
587
|
+
insertedVnodeQueue,
|
|
588
|
+
ownerArray,
|
|
589
|
+
index,
|
|
590
|
+
removeOnly?: any
|
|
591
|
+
) {
|
|
592
|
+
if (oldVnode === vnode) {
|
|
593
|
+
return
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
if (isDef(vnode.elm) && isDef(ownerArray)) {
|
|
597
|
+
// clone reused vnode
|
|
598
|
+
vnode = ownerArray[index] = cloneVNode(vnode)
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const elm = (vnode.elm = oldVnode.elm)
|
|
602
|
+
|
|
603
|
+
if (isTrue(oldVnode.isAsyncPlaceholder)) {
|
|
604
|
+
if (isDef(vnode.asyncFactory.resolved)) {
|
|
605
|
+
hydrate(oldVnode.elm, vnode, insertedVnodeQueue)
|
|
606
|
+
} else {
|
|
607
|
+
vnode.isAsyncPlaceholder = true
|
|
608
|
+
}
|
|
609
|
+
return
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
// reuse element for static trees.
|
|
613
|
+
// note we only do this if the vnode is cloned -
|
|
614
|
+
// if the new node is not cloned it means the render functions have been
|
|
615
|
+
// reset by the hot-reload-api and we need to do a proper re-render.
|
|
616
|
+
if (
|
|
617
|
+
isTrue(vnode.isStatic) &&
|
|
618
|
+
isTrue(oldVnode.isStatic) &&
|
|
619
|
+
vnode.key === oldVnode.key &&
|
|
620
|
+
(isTrue(vnode.isCloned) || isTrue(vnode.isOnce))
|
|
621
|
+
) {
|
|
622
|
+
vnode.componentInstance = oldVnode.componentInstance
|
|
623
|
+
return
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
let i
|
|
627
|
+
const data = vnode.data
|
|
628
|
+
if (isDef(data) && isDef((i = data.hook)) && isDef((i = i.prepatch))) {
|
|
629
|
+
i(oldVnode, vnode)
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
const oldCh = oldVnode.children
|
|
633
|
+
const ch = vnode.children
|
|
634
|
+
if (isDef(data) && isPatchable(vnode)) {
|
|
635
|
+
for (i = 0; i < cbs.update.length; ++i) cbs.update[i](oldVnode, vnode)
|
|
636
|
+
if (isDef((i = data.hook)) && isDef((i = i.update))) i(oldVnode, vnode)
|
|
637
|
+
}
|
|
638
|
+
if (isUndef(vnode.text)) {
|
|
639
|
+
if (isDef(oldCh) && isDef(ch)) {
|
|
640
|
+
if (oldCh !== ch)
|
|
641
|
+
updateChildren(elm, oldCh, ch, insertedVnodeQueue, removeOnly)
|
|
642
|
+
} else if (isDef(ch)) {
|
|
643
|
+
if (__DEV__) {
|
|
644
|
+
checkDuplicateKeys(ch)
|
|
645
|
+
}
|
|
646
|
+
if (isDef(oldVnode.text)) nodeOps.setTextContent(elm, '')
|
|
647
|
+
addVnodes(elm, null, ch, 0, ch.length - 1, insertedVnodeQueue)
|
|
648
|
+
} else if (isDef(oldCh)) {
|
|
649
|
+
removeVnodes(oldCh, 0, oldCh.length - 1)
|
|
650
|
+
} else if (isDef(oldVnode.text)) {
|
|
651
|
+
nodeOps.setTextContent(elm, '')
|
|
652
|
+
}
|
|
653
|
+
} else if (oldVnode.text !== vnode.text) {
|
|
654
|
+
nodeOps.setTextContent(elm, vnode.text)
|
|
655
|
+
}
|
|
656
|
+
if (isDef(data)) {
|
|
657
|
+
if (isDef((i = data.hook)) && isDef((i = i.postpatch))) i(oldVnode, vnode)
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
function invokeInsertHook(vnode, queue, initial) {
|
|
662
|
+
// delay insert hooks for component root nodes, invoke them after the
|
|
663
|
+
// element is really inserted
|
|
664
|
+
if (isTrue(initial) && isDef(vnode.parent)) {
|
|
665
|
+
vnode.parent.data.pendingInsert = queue
|
|
666
|
+
} else {
|
|
667
|
+
for (let i = 0; i < queue.length; ++i) {
|
|
668
|
+
queue[i].data.hook.insert(queue[i])
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
let hydrationBailed = false
|
|
674
|
+
// list of modules that can skip create hook during hydration because they
|
|
675
|
+
// are already rendered on the client or has no need for initialization
|
|
676
|
+
// Note: style is excluded because it relies on initial clone for future
|
|
677
|
+
// deep updates (#7063).
|
|
678
|
+
const isRenderedModule = makeMap('attrs,class,staticClass,staticStyle,key')
|
|
679
|
+
|
|
680
|
+
// Note: this is a browser-only function so we can assume elms are DOM nodes.
|
|
681
|
+
function hydrate(elm, vnode, insertedVnodeQueue, inVPre?: boolean) {
|
|
682
|
+
let i
|
|
683
|
+
const { tag, data, children } = vnode
|
|
684
|
+
inVPre = inVPre || (data && data.pre)
|
|
685
|
+
vnode.elm = elm
|
|
686
|
+
|
|
687
|
+
if (isTrue(vnode.isComment) && isDef(vnode.asyncFactory)) {
|
|
688
|
+
vnode.isAsyncPlaceholder = true
|
|
689
|
+
return true
|
|
690
|
+
}
|
|
691
|
+
// assert node match
|
|
692
|
+
if (__DEV__) {
|
|
693
|
+
if (!assertNodeMatch(elm, vnode, inVPre)) {
|
|
694
|
+
return false
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
if (isDef(data)) {
|
|
698
|
+
if (isDef((i = data.hook)) && isDef((i = i.init)))
|
|
699
|
+
i(vnode, true /* hydrating */)
|
|
700
|
+
if (isDef((i = vnode.componentInstance))) {
|
|
701
|
+
// child component. it should have hydrated its own tree.
|
|
702
|
+
initComponent(vnode, insertedVnodeQueue)
|
|
703
|
+
return true
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
if (isDef(tag)) {
|
|
707
|
+
if (isDef(children)) {
|
|
708
|
+
// empty element, allow client to pick up and populate children
|
|
709
|
+
if (!elm.hasChildNodes()) {
|
|
710
|
+
createChildren(vnode, children, insertedVnodeQueue)
|
|
711
|
+
} else {
|
|
712
|
+
// v-html and domProps: innerHTML
|
|
713
|
+
if (
|
|
714
|
+
isDef((i = data)) &&
|
|
715
|
+
isDef((i = i.domProps)) &&
|
|
716
|
+
isDef((i = i.innerHTML))
|
|
717
|
+
) {
|
|
718
|
+
if (i !== elm.innerHTML) {
|
|
719
|
+
/* istanbul ignore if */
|
|
720
|
+
if (
|
|
721
|
+
__DEV__ &&
|
|
722
|
+
typeof console !== 'undefined' &&
|
|
723
|
+
!hydrationBailed
|
|
724
|
+
) {
|
|
725
|
+
hydrationBailed = true
|
|
726
|
+
console.warn('Parent: ', elm)
|
|
727
|
+
console.warn('server innerHTML: ', i)
|
|
728
|
+
console.warn('client innerHTML: ', elm.innerHTML)
|
|
729
|
+
}
|
|
730
|
+
return false
|
|
731
|
+
}
|
|
732
|
+
} else {
|
|
733
|
+
// iterate and compare children lists
|
|
734
|
+
let childrenMatch = true
|
|
735
|
+
let childNode = elm.firstChild
|
|
736
|
+
for (let i = 0; i < children.length; i++) {
|
|
737
|
+
if (
|
|
738
|
+
!childNode ||
|
|
739
|
+
!hydrate(childNode, children[i], insertedVnodeQueue, inVPre)
|
|
740
|
+
) {
|
|
741
|
+
childrenMatch = false
|
|
742
|
+
break
|
|
743
|
+
}
|
|
744
|
+
childNode = childNode.nextSibling
|
|
745
|
+
}
|
|
746
|
+
// if childNode is not null, it means the actual childNodes list is
|
|
747
|
+
// longer than the virtual children list.
|
|
748
|
+
if (!childrenMatch || childNode) {
|
|
749
|
+
/* istanbul ignore if */
|
|
750
|
+
if (
|
|
751
|
+
__DEV__ &&
|
|
752
|
+
typeof console !== 'undefined' &&
|
|
753
|
+
!hydrationBailed
|
|
754
|
+
) {
|
|
755
|
+
hydrationBailed = true
|
|
756
|
+
console.warn('Parent: ', elm)
|
|
757
|
+
console.warn(
|
|
758
|
+
'Mismatching childNodes vs. VNodes: ',
|
|
759
|
+
elm.childNodes,
|
|
760
|
+
children
|
|
761
|
+
)
|
|
762
|
+
}
|
|
763
|
+
return false
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
if (isDef(data)) {
|
|
769
|
+
let fullInvoke = false
|
|
770
|
+
for (const key in data) {
|
|
771
|
+
if (!isRenderedModule(key)) {
|
|
772
|
+
fullInvoke = true
|
|
773
|
+
invokeCreateHooks(vnode, insertedVnodeQueue)
|
|
774
|
+
break
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
if (!fullInvoke && data['class']) {
|
|
778
|
+
// ensure collecting deps for deep class bindings for future updates
|
|
779
|
+
traverse(data['class'])
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
} else if (elm.data !== vnode.text) {
|
|
783
|
+
elm.data = vnode.text
|
|
784
|
+
}
|
|
785
|
+
return true
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
function assertNodeMatch(node, vnode, inVPre) {
|
|
789
|
+
if (isDef(vnode.tag)) {
|
|
790
|
+
return (
|
|
791
|
+
vnode.tag.indexOf('vue-component') === 0 ||
|
|
792
|
+
(!isUnknownElement(vnode, inVPre) &&
|
|
793
|
+
vnode.tag.toLowerCase() ===
|
|
794
|
+
(node.tagName && node.tagName.toLowerCase()))
|
|
795
|
+
)
|
|
796
|
+
} else {
|
|
797
|
+
return node.nodeType === (vnode.isComment ? 8 : 3)
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
return function patch(oldVnode, vnode, hydrating, removeOnly) {
|
|
802
|
+
if (isUndef(vnode)) {
|
|
803
|
+
if (isDef(oldVnode)) invokeDestroyHook(oldVnode)
|
|
804
|
+
return
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
let isInitialPatch = false
|
|
808
|
+
const insertedVnodeQueue: any[] = []
|
|
809
|
+
|
|
810
|
+
if (isUndef(oldVnode)) {
|
|
811
|
+
// empty mount (likely as component), create new root element
|
|
812
|
+
isInitialPatch = true
|
|
813
|
+
createElm(vnode, insertedVnodeQueue)
|
|
814
|
+
} else {
|
|
815
|
+
const isRealElement = isDef(oldVnode.nodeType)
|
|
816
|
+
if (!isRealElement && sameVnode(oldVnode, vnode)) {
|
|
817
|
+
// patch existing root node
|
|
818
|
+
patchVnode(oldVnode, vnode, insertedVnodeQueue, null, null, removeOnly)
|
|
819
|
+
} else {
|
|
820
|
+
if (isRealElement) {
|
|
821
|
+
// mounting to a real element
|
|
822
|
+
// check if this is server-rendered content and if we can perform
|
|
823
|
+
// a successful hydration.
|
|
824
|
+
if (oldVnode.nodeType === 1 && oldVnode.hasAttribute(SSR_ATTR)) {
|
|
825
|
+
oldVnode.removeAttribute(SSR_ATTR)
|
|
826
|
+
hydrating = true
|
|
827
|
+
}
|
|
828
|
+
if (isTrue(hydrating)) {
|
|
829
|
+
if (hydrate(oldVnode, vnode, insertedVnodeQueue)) {
|
|
830
|
+
invokeInsertHook(vnode, insertedVnodeQueue, true)
|
|
831
|
+
return oldVnode
|
|
832
|
+
} else if (__DEV__) {
|
|
833
|
+
warn(
|
|
834
|
+
'The client-side rendered virtual DOM tree is not matching ' +
|
|
835
|
+
'server-rendered content. This is likely caused by incorrect ' +
|
|
836
|
+
'HTML markup, for example nesting block-level elements inside ' +
|
|
837
|
+
'<p>, or missing <tbody>. Bailing hydration and performing ' +
|
|
838
|
+
'full client-side render.'
|
|
839
|
+
)
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
// either not server-rendered, or hydration failed.
|
|
843
|
+
// create an empty node and replace it
|
|
844
|
+
oldVnode = emptyNodeAt(oldVnode)
|
|
845
|
+
}
|
|
846
|
+
|
|
847
|
+
// replacing existing element
|
|
848
|
+
const oldElm = oldVnode.elm
|
|
849
|
+
const parentElm = nodeOps.parentNode(oldElm)
|
|
850
|
+
|
|
851
|
+
// create new node
|
|
852
|
+
createElm(
|
|
853
|
+
vnode,
|
|
854
|
+
insertedVnodeQueue,
|
|
855
|
+
// extremely rare edge case: do not insert if old element is in a
|
|
856
|
+
// leaving transition. Only happens when combining transition +
|
|
857
|
+
// keep-alive + HOCs. (#4590)
|
|
858
|
+
oldElm._leaveCb ? null : parentElm,
|
|
859
|
+
nodeOps.nextSibling(oldElm)
|
|
860
|
+
)
|
|
861
|
+
|
|
862
|
+
// update parent placeholder node element, recursively
|
|
863
|
+
if (isDef(vnode.parent)) {
|
|
864
|
+
let ancestor = vnode.parent
|
|
865
|
+
const patchable = isPatchable(vnode)
|
|
866
|
+
while (ancestor) {
|
|
867
|
+
for (let i = 0; i < cbs.destroy.length; ++i) {
|
|
868
|
+
cbs.destroy[i](ancestor)
|
|
869
|
+
}
|
|
870
|
+
ancestor.elm = vnode.elm
|
|
871
|
+
if (patchable) {
|
|
872
|
+
for (let i = 0; i < cbs.create.length; ++i) {
|
|
873
|
+
cbs.create[i](emptyNode, ancestor)
|
|
874
|
+
}
|
|
875
|
+
// #6513
|
|
876
|
+
// invoke insert hooks that may have been merged by create hooks.
|
|
877
|
+
// e.g. for directives that uses the "inserted" hook.
|
|
878
|
+
const insert = ancestor.data.hook.insert
|
|
879
|
+
if (insert.merged) {
|
|
880
|
+
// start at index 1 to avoid re-invoking component mounted hook
|
|
881
|
+
// clone insert hooks to avoid being mutated during iteration.
|
|
882
|
+
// e.g. for customed directives under transition group.
|
|
883
|
+
const cloned = insert.fns.slice(1)
|
|
884
|
+
for (let i = 0; i < cloned.length; i++) {
|
|
885
|
+
cloned[i]()
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
} else {
|
|
889
|
+
registerRef(ancestor)
|
|
890
|
+
}
|
|
891
|
+
ancestor = ancestor.parent
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
// destroy old node
|
|
896
|
+
if (isDef(parentElm)) {
|
|
897
|
+
removeVnodes([oldVnode], 0, 0)
|
|
898
|
+
} else if (isDef(oldVnode.tag)) {
|
|
899
|
+
invokeDestroyHook(oldVnode)
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
invokeInsertHook(vnode, insertedVnodeQueue, isInitialPatch)
|
|
905
|
+
return vnode.elm
|
|
906
|
+
}
|
|
907
|
+
}
|