wip: fix one test
This commit is contained in:
parent
ba571cda61
commit
f79f0e658b
@ -1,10 +1,9 @@
|
|||||||
import {
|
import {
|
||||||
h,
|
h,
|
||||||
Component,
|
Component,
|
||||||
render,
|
|
||||||
nodeOps,
|
|
||||||
observable,
|
observable,
|
||||||
nextTick
|
nextTick,
|
||||||
|
renderInstance
|
||||||
} from '@vue/runtime-test'
|
} from '@vue/runtime-test'
|
||||||
|
|
||||||
describe('Parent chain management', () => {
|
describe('Parent chain management', () => {
|
||||||
@ -36,11 +35,12 @@ describe('Parent chain management', () => {
|
|||||||
unmounted() {
|
unmounted() {
|
||||||
grandChildren.splice(grandChildren.indexOf(this), 1)
|
grandChildren.splice(grandChildren.indexOf(this), 1)
|
||||||
}
|
}
|
||||||
render() {}
|
render() {
|
||||||
|
return h('div')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const root = nodeOps.createElement('div')
|
const parent = await renderInstance(Parent)
|
||||||
const parent = (await render(h(Parent), root)) as Component
|
|
||||||
|
|
||||||
expect(child.$parent).toBe(parent)
|
expect(child.$parent).toBe(parent)
|
||||||
expect(child.$root).toBe(parent)
|
expect(child.$root).toBe(parent)
|
||||||
@ -98,8 +98,7 @@ describe('Parent chain management', () => {
|
|||||||
render() {}
|
render() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const root = nodeOps.createElement('div')
|
const parent = await renderInstance(Parent)
|
||||||
const parent = (await render(h(Parent), root)) as Component
|
|
||||||
|
|
||||||
expect(child.$parent).toBe(parent)
|
expect(child.$parent).toBe(parent)
|
||||||
expect(child.$root).toBe(parent)
|
expect(child.$root).toBe(parent)
|
||||||
|
@ -7,7 +7,6 @@ import {
|
|||||||
MountedVNode,
|
MountedVNode,
|
||||||
RenderNode,
|
RenderNode,
|
||||||
createTextVNode,
|
createTextVNode,
|
||||||
Ref,
|
|
||||||
VNodeChildren
|
VNodeChildren
|
||||||
} from './vdom'
|
} from './vdom'
|
||||||
import { ComponentInstance } from './component'
|
import { ComponentInstance } from './component'
|
||||||
@ -109,9 +108,13 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
const lifecycleHooks: Function[] = []
|
const lifecycleHooks: Function[] = []
|
||||||
const vnodeUpdatedHooks: Function[] = []
|
const vnodeUpdatedHooks: Function[] = []
|
||||||
|
|
||||||
|
function queuePostCommitHook(fn: Function) {
|
||||||
|
lifecycleHooks.push(fn)
|
||||||
|
}
|
||||||
|
|
||||||
function flushHooks() {
|
function flushHooks() {
|
||||||
let fn
|
let fn
|
||||||
while ((fn = lifecycleHooks.shift())) {
|
while ((fn = lifecycleHooks.pop())) {
|
||||||
fn()
|
fn()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -187,21 +190,17 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
insertOrAppend(container, el, endNode)
|
insertOrAppend(container, el, endNode)
|
||||||
}
|
}
|
||||||
if (ref) {
|
if (ref) {
|
||||||
mountRef(ref, el)
|
queuePostCommitHook(() => {
|
||||||
|
ref(el)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if (data != null && data.vnodeMounted) {
|
if (data != null && data.vnodeMounted) {
|
||||||
lifecycleHooks.unshift(() => {
|
queuePostCommitHook(() => {
|
||||||
data.vnodeMounted(vnode)
|
data.vnodeMounted(vnode)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function mountRef(ref: Ref, el: RenderNode | ComponentInstance) {
|
|
||||||
lifecycleHooks.push(() => {
|
|
||||||
ref(el)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
function mountComponent(
|
function mountComponent(
|
||||||
vnode: VNode,
|
vnode: VNode,
|
||||||
container: RenderNode | null,
|
container: RenderNode | null,
|
||||||
@ -325,8 +324,10 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
const { children, childFlags } = vnode
|
const { children, childFlags } = vnode
|
||||||
switch (childFlags) {
|
switch (childFlags) {
|
||||||
case ChildrenFlags.SINGLE_VNODE:
|
case ChildrenFlags.SINGLE_VNODE:
|
||||||
mount(children as VNode, container, contextVNode, isSVG, endNode)
|
queuePostCommitHook(() => {
|
||||||
vnode.el = (children as MountedVNode).el
|
vnode.el = (children as MountedVNode).el
|
||||||
|
})
|
||||||
|
mount(children as VNode, container, contextVNode, isSVG, endNode)
|
||||||
break
|
break
|
||||||
case ChildrenFlags.NO_CHILDREN:
|
case ChildrenFlags.NO_CHILDREN:
|
||||||
const placeholder = createTextVNode('')
|
const placeholder = createTextVNode('')
|
||||||
@ -334,6 +335,9 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
vnode.el = placeholder.el
|
vnode.el = placeholder.el
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
|
queuePostCommitHook(() => {
|
||||||
|
vnode.el = (children as MountedVNode[])[0].el
|
||||||
|
})
|
||||||
mountArrayChildren(
|
mountArrayChildren(
|
||||||
children as VNode[],
|
children as VNode[],
|
||||||
container,
|
container,
|
||||||
@ -341,7 +345,6 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
isSVG,
|
isSVG,
|
||||||
endNode
|
endNode
|
||||||
)
|
)
|
||||||
vnode.el = (children as MountedVNode[])[0].el
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -369,7 +372,9 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (ref) {
|
if (ref) {
|
||||||
mountRef(ref, target as RenderNode)
|
queuePostCommitHook(() => {
|
||||||
|
ref(target)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
const placeholder = createTextVNode('')
|
const placeholder = createTextVNode('')
|
||||||
mountText(placeholder, container, null)
|
mountText(placeholder, container, null)
|
||||||
@ -573,16 +578,7 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
// then retrieve its next sibling to use as the end node for patchChildren.
|
// then retrieve its next sibling to use as the end node for patchChildren.
|
||||||
const endNode = platformNextSibling(getVNodeLastEl(prevVNode))
|
const endNode = platformNextSibling(getVNodeLastEl(prevVNode))
|
||||||
const { childFlags, children } = nextVNode
|
const { childFlags, children } = nextVNode
|
||||||
patchChildren(
|
queuePostCommitHook(() => {
|
||||||
prevVNode.childFlags,
|
|
||||||
childFlags,
|
|
||||||
prevVNode.children,
|
|
||||||
children,
|
|
||||||
container,
|
|
||||||
contextVNode,
|
|
||||||
isSVG,
|
|
||||||
endNode
|
|
||||||
)
|
|
||||||
switch (childFlags) {
|
switch (childFlags) {
|
||||||
case ChildrenFlags.SINGLE_VNODE:
|
case ChildrenFlags.SINGLE_VNODE:
|
||||||
nextVNode.el = (children as MountedVNode).el
|
nextVNode.el = (children as MountedVNode).el
|
||||||
@ -593,6 +589,17 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
default:
|
default:
|
||||||
nextVNode.el = (children as MountedVNode[])[0].el
|
nextVNode.el = (children as MountedVNode[])[0].el
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
patchChildren(
|
||||||
|
prevVNode.childFlags,
|
||||||
|
childFlags,
|
||||||
|
prevVNode.children,
|
||||||
|
children,
|
||||||
|
container,
|
||||||
|
contextVNode,
|
||||||
|
isSVG,
|
||||||
|
endNode
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVNodeLastEl(vnode: MountedVNode): RenderNode {
|
function getVNodeLastEl(vnode: MountedVNode): RenderNode {
|
||||||
@ -1152,7 +1159,7 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
container: RenderNode | null,
|
container: RenderNode | null,
|
||||||
isSVG: boolean,
|
isSVG: boolean,
|
||||||
endNode: RenderNode | null
|
endNode: RenderNode | null
|
||||||
): RenderNode {
|
) {
|
||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
pushWarningContext(vnode)
|
pushWarningContext(vnode)
|
||||||
}
|
}
|
||||||
@ -1190,6 +1197,20 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
} else {
|
} else {
|
||||||
// this will be executed synchronously right here
|
// this will be executed synchronously right here
|
||||||
instance.$vnode = renderInstanceRoot(instance) as MountedVNode
|
instance.$vnode = renderInstanceRoot(instance) as MountedVNode
|
||||||
|
|
||||||
|
queuePostCommitHook(() => {
|
||||||
|
vnode.el = instance.$vnode.el
|
||||||
|
if (vnode.ref) {
|
||||||
|
vnode.ref($proxy)
|
||||||
|
}
|
||||||
|
// retrieve mounted value after initial render so that we get
|
||||||
|
// to inject effects in hooks
|
||||||
|
const { mounted } = instance.$options
|
||||||
|
if (mounted) {
|
||||||
|
callLifecycleHookWithHandle(mounted, $proxy, ErrorTypes.MOUNTED)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
mount(
|
mount(
|
||||||
instance.$vnode,
|
instance.$vnode,
|
||||||
container,
|
container,
|
||||||
@ -1197,7 +1218,6 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
isSVG,
|
isSVG,
|
||||||
endNode
|
endNode
|
||||||
)
|
)
|
||||||
vnode.el = instance.$vnode.el
|
|
||||||
|
|
||||||
if (__COMPAT__) {
|
if (__COMPAT__) {
|
||||||
// expose __vue__ for devtools
|
// expose __vue__ for devtools
|
||||||
@ -1205,18 +1225,6 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
instance._mounted = true
|
instance._mounted = true
|
||||||
if (vnode.ref) {
|
|
||||||
mountRef(vnode.ref, $proxy)
|
|
||||||
}
|
|
||||||
|
|
||||||
// retrieve mounted value right before calling it so that we get
|
|
||||||
// to inject effects in first render
|
|
||||||
const { mounted } = instance.$options
|
|
||||||
if (mounted) {
|
|
||||||
lifecycleHooks.unshift(() => {
|
|
||||||
callLifecycleHookWithHandle(mounted, $proxy, ErrorTypes.MOUNTED)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -1229,8 +1237,6 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
popWarningContext()
|
popWarningContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
return vnode.el as RenderNode
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateComponentInstance(
|
function updateComponentInstance(
|
||||||
@ -1259,15 +1265,13 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
const nextVNode = (instance.$vnode = renderInstanceRoot(
|
const nextVNode = (instance.$vnode = renderInstanceRoot(
|
||||||
instance
|
instance
|
||||||
) as MountedVNode)
|
) as MountedVNode)
|
||||||
const container = platformParentNode(prevVNode.el) as RenderNode
|
|
||||||
patch(prevVNode, nextVNode, container, $parentVNode as MountedVNode, isSVG)
|
|
||||||
const el = nextVNode.el as RenderNode
|
|
||||||
|
|
||||||
|
queuePostCommitHook(() => {
|
||||||
|
const el = nextVNode.el as RenderNode
|
||||||
if (__COMPAT__) {
|
if (__COMPAT__) {
|
||||||
// expose __vue__ for devtools
|
// expose __vue__ for devtools
|
||||||
;(el as any).__vue__ = instance
|
;(el as any).__vue__ = instance
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursively update contextVNode el for nested HOCs
|
// recursively update contextVNode el for nested HOCs
|
||||||
if ((nextVNode.flags & VNodeFlags.PORTAL) === 0) {
|
if ((nextVNode.flags & VNodeFlags.PORTAL) === 0) {
|
||||||
let vnode = $parentVNode
|
let vnode = $parentVNode
|
||||||
@ -1278,33 +1282,28 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
vnode = vnode.contextVNode
|
vnode = vnode.contextVNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const { updated } = instance.$options
|
const { updated } = instance.$options
|
||||||
if (updated) {
|
if (updated) {
|
||||||
// Because the child's update is executed by the scheduler and not
|
|
||||||
// synchronously within the parent's update call, the child's updated hook
|
|
||||||
// will be added to the queue AFTER the parent's, but they should be
|
|
||||||
// invoked BEFORE the parent's. Therefore we add them to the head of the
|
|
||||||
// queue instead.
|
|
||||||
lifecycleHooks.unshift(() => {
|
|
||||||
callLifecycleHookWithHandle(
|
callLifecycleHookWithHandle(
|
||||||
updated,
|
updated,
|
||||||
$proxy,
|
$proxy,
|
||||||
ErrorTypes.UPDATED,
|
ErrorTypes.UPDATED,
|
||||||
nextVNode
|
nextVNode
|
||||||
)
|
)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vnodeUpdatedHooks.length > 0) {
|
if (vnodeUpdatedHooks.length > 0) {
|
||||||
const vnodeUpdatedHooksForCurrentInstance = vnodeUpdatedHooks.slice()
|
const vnodeUpdatedHooksForCurrentInstance = vnodeUpdatedHooks.slice()
|
||||||
vnodeUpdatedHooks.length = 0
|
vnodeUpdatedHooks.length = 0
|
||||||
lifecycleHooks.unshift(() => {
|
queuePostCommitHook(() => {
|
||||||
for (let i = 0; i < vnodeUpdatedHooksForCurrentInstance.length; i++) {
|
for (let i = 0; i < vnodeUpdatedHooksForCurrentInstance.length; i++) {
|
||||||
vnodeUpdatedHooksForCurrentInstance[i]()
|
vnodeUpdatedHooksForCurrentInstance[i]()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const container = platformParentNode(prevVNode.el) as RenderNode
|
||||||
|
patch(prevVNode, nextVNode, container, $parentVNode as MountedVNode, isSVG)
|
||||||
|
|
||||||
if (__DEV__ && instance.$parentVNode) {
|
if (__DEV__ && instance.$parentVNode) {
|
||||||
popWarningContext()
|
popWarningContext()
|
||||||
@ -1357,7 +1356,7 @@ export function createRenderer(options: RendererOptions) {
|
|||||||
if (__DEV__) {
|
if (__DEV__) {
|
||||||
popWarningContext()
|
popWarningContext()
|
||||||
}
|
}
|
||||||
lifecycleHooks.push(() => {
|
queuePostCommitHook(() => {
|
||||||
callActivatedHook(instance, true)
|
callActivatedHook(instance, true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -92,5 +92,3 @@ export const Inject: FunctionalComponent<InjectProps> = (
|
|||||||
}
|
}
|
||||||
return slots.default && slots.default(resolvedValue)
|
return slots.default && slots.default(resolvedValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
Inject.pure = true
|
|
||||||
|
@ -9,6 +9,10 @@
|
|||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/vuejs/vue.git"
|
"url": "git+https://github.com/vuejs/vue.git"
|
||||||
},
|
},
|
||||||
|
"buildOptions": {
|
||||||
|
"name": "VueTestRuntime",
|
||||||
|
"formats": ["esm", "cjs", "global"]
|
||||||
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"vue"
|
"vue"
|
||||||
],
|
],
|
||||||
|
@ -30,14 +30,18 @@ function patchOps(nodeOps: NodeOps) {
|
|||||||
return original(...args)
|
return original(...args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!/parent|next|query/.test(key)) {
|
||||||
nodeOps[key] = (...args: any[]) => {
|
nodeOps[key] = (...args: any[]) => {
|
||||||
if (currentOps) {
|
if (currentOps) {
|
||||||
currentOps.push([original, ...args.map(evaluate)])
|
currentOps.push([original, ...args.map(evaluate)])
|
||||||
} else {
|
} else {
|
||||||
original(...args)
|
return original(...args)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
nodeOps[key] = (node: any) => {
|
||||||
|
return original(evaluate(node))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
;(global as any).__COMPAT__ = true
|
;(global as any).__COMPAT__ = true
|
||||||
|
|
||||||
import Vue from '../src/index'
|
import Vue from '../src/index-compat'
|
||||||
|
|
||||||
describe('2.x compat build', async () => {
|
describe('2.x compat build', async () => {
|
||||||
test('should work', async () => {
|
test('should work', async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user