refactor(runtime-vapor): clean up

This commit is contained in:
三咲智子 Kevin Deng 2023-12-15 01:30:26 +08:00
parent 6eaf4b651b
commit 9dda97e736
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
5 changed files with 8 additions and 29 deletions

View File

@ -4,13 +4,11 @@ import {
effect,
setText,
render,
getCurrentInstance,
ref,
unmountComponent,
} from '../src'
import type { ComponentInternalInstance } from '../src'
import { afterEach, beforeEach, describe, expect } from 'vitest'
import { defineComponent, nextTick } from '@vue/runtime-core'
import { defineComponent } from '@vue/runtime-core'
let host: HTMLElement
@ -42,7 +40,6 @@ describe('component', () => {
},
})
const instance = render(Comp as any, {}, '#host')
await nextTick()
expect(host.innerHTML).toBe('<div>0</div>')
unmountComponent(instance)
expect(host.innerHTML).toBe('')

View File

@ -1,7 +1,3 @@
/**
* @vitest-environment jsdom
*/
import { template, fragment } from '../src'
describe('api: template', () => {

View File

@ -24,26 +24,14 @@ describe('directive: v-show', () => {
function handleClick() {
visible.value = !visible.value
}
const __returned__ = { visible, handleClick }
Object.defineProperty(__returned__, '__isScriptSetup', {
enumerable: false,
value: true,
})
return __returned__
},
render(_ctx: any) {
const t0 = template('<button>toggle</button><h1>hello world</h1>')
const n0 = t0()
const {
0: [n1],
1: [n2],
} = children(n0 as ChildNode)
withDirectives(n2, [[vShow, () => _ctx.visible]])
on(
n1 as HTMLElement,
'click',
(...args) => _ctx.handleClick && _ctx.handleClick(...args),
)
} = children(n0)
withDirectives(n2, [[vShow, () => visible.value]])
on(n1 as HTMLElement, 'click', (...args) => handleClick(...args))
return n0
},
})

View File

@ -1,6 +1,5 @@
import { markRaw, proxyRefs } from '@vue/reactivity'
import { type Data } from '@vue/shared'
import {
type Component,
type ComponentInternalInstance,
@ -8,11 +7,8 @@ import {
setCurrentInstance,
unsetCurrentInstance,
} from './component'
import { initProps } from './componentProps'
import { invokeDirectiveHook } from './directive'
import { insert, remove } from './dom'
import { PublicInstanceProxyHandlers } from './componentPublicInstance'
@ -61,7 +57,9 @@ export function mountComponent(
} else {
block = state as Block
}
if (block instanceof DocumentFragment) block = Array.from(block.childNodes)
if (block instanceof DocumentFragment) {
block = Array.from(block.childNodes)
}
return (instance.block = block)
})!
invokeDirectiveHook(instance, 'beforeMount')

View File

@ -20,7 +20,7 @@ function flush() {
queued = undefined
}
export const nextTick = (fn: any) => p.then(fn)
export const nextTick = (fn?: any) => (fn ? p.then(fn) : p)
export function effect(fn: any) {
let run: () => void