chore: update

This commit is contained in:
daiwei 2025-03-17 14:47:24 +08:00
parent 7a4a4c08b6
commit e42ff1b24c
6 changed files with 18 additions and 18 deletions

View File

@ -74,18 +74,18 @@ exports[`compiler: transition > v-show + appear 1`] = `
const t0 = _template("<h1>foo</h1>")
export function render(_ctx) {
const lazyApplyVShowFn = []
const deferredApplyVShows = []
const n1 = _createComponent(_VaporTransition, {
appear: () => (""),
persisted: () => ("")
}, {
"default": () => {
const n0 = t0()
lazyApplyVShowFn.push(() => _applyVShow(n0, () => (_ctx.show)))
deferredApplyVShows.push(() => _applyVShow(n0, () => (_ctx.show)))
return n0
}
}, true)
lazyApplyVShowFn.forEach(fn => fn())
deferredApplyVShows.forEach(fn => fn())
return n1
}"
`;

View File

@ -44,8 +44,8 @@ export function genBlockContent(
const { dynamic, effect, operation, returns, key } = block
const resetBlock = context.enterBlock(block)
if (block.hasLazyApplyVShow) {
push(NEWLINE, `const lazyApplyVShowFn = []`)
if (block.hasDeferredVShow) {
push(NEWLINE, `const deferredApplyVShows = []`)
}
if (root) {
@ -60,8 +60,8 @@ export function genBlockContent(
push(...genOperations(operation, context))
push(...genEffects(effect, context))
if (block.hasLazyApplyVShow) {
push(NEWLINE, `lazyApplyVShowFn.forEach(fn => fn())`)
if (block.hasDeferredVShow) {
push(NEWLINE, `deferredApplyVShows.forEach(fn => fn())`)
}
if (dynamic.needsKey) {

View File

@ -7,15 +7,15 @@ export function genVShow(
oper: DirectiveIRNode,
context: CodegenContext,
): CodeFragment[] {
const { lazy, element } = oper
const { deferred, element } = oper
return [
NEWLINE,
lazy ? `lazyApplyVShowFn.push(() => ` : undefined,
deferred ? `deferredApplyVShows.push(() => ` : undefined,
...genCall(context.helper('applyVShow'), `n${element}`, [
`() => (`,
...genExpression(oper.dir.exp!, context),
`)`,
]),
lazy ? `)` : undefined,
deferred ? `)` : undefined,
]
}

View File

@ -56,7 +56,7 @@ export interface BlockIRNode extends BaseIRNode {
operation: OperationNode[]
expressions: SimpleExpressionNode[]
returns: number[]
hasLazyApplyVShow: boolean
hasDeferredVShow: boolean
}
export interface RootIRNode {
@ -188,7 +188,7 @@ export interface DirectiveIRNode extends BaseIRNode {
builtin?: boolean
asset?: boolean
modelType?: 'text' | 'dynamic' | 'radio' | 'checkbox' | 'select'
lazy?: boolean
deferred?: boolean
}
export interface CreateComponentIRNode extends BaseIRNode {

View File

@ -31,7 +31,7 @@ export const newBlock = (node: BlockIRNode['node']): BlockIRNode => ({
returns: [],
expressions: [],
tempId: 0,
hasLazyApplyVShow: false,
hasDeferredVShow: false,
})
export function wrapTemplate(node: ElementNode, dirs: string[]): TemplateNode {

View File

@ -30,16 +30,16 @@ export const transformVShow: DirectiveTransform = (dir, node, context) => {
}
// lazy apply vshow if the node is inside a transition with appear
let lazyApplyVShow = false
let shouldDeferred = false
const parentNode = context.parent && context.parent.node
if (parentNode && parentNode.type === NodeTypes.ELEMENT) {
lazyApplyVShow = !!(
shouldDeferred = !!(
isTransitionTag(parentNode.tag) &&
findProp(parentNode, 'appear', false, true)
)
if (lazyApplyVShow) {
context.parent!.parent!.block.hasLazyApplyVShow = true
if (shouldDeferred) {
context.parent!.parent!.block.hasDeferredVShow = true
}
}
@ -49,6 +49,6 @@ export const transformVShow: DirectiveTransform = (dir, node, context) => {
dir,
name: 'show',
builtin: true,
lazy: lazyApplyVShow,
deferred: shouldDeferred,
})
}