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>") const t0 = _template("<h1>foo</h1>")
export function render(_ctx) { export function render(_ctx) {
const lazyApplyVShowFn = [] const deferredApplyVShows = []
const n1 = _createComponent(_VaporTransition, { const n1 = _createComponent(_VaporTransition, {
appear: () => (""), appear: () => (""),
persisted: () => ("") persisted: () => ("")
}, { }, {
"default": () => { "default": () => {
const n0 = t0() const n0 = t0()
lazyApplyVShowFn.push(() => _applyVShow(n0, () => (_ctx.show))) deferredApplyVShows.push(() => _applyVShow(n0, () => (_ctx.show)))
return n0 return n0
} }
}, true) }, true)
lazyApplyVShowFn.forEach(fn => fn()) deferredApplyVShows.forEach(fn => fn())
return n1 return n1
}" }"
`; `;

View File

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

View File

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

View File

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

View File

@ -31,7 +31,7 @@ export const newBlock = (node: BlockIRNode['node']): BlockIRNode => ({
returns: [], returns: [],
expressions: [], expressions: [],
tempId: 0, tempId: 0,
hasLazyApplyVShow: false, hasDeferredVShow: false,
}) })
export function wrapTemplate(node: ElementNode, dirs: string[]): TemplateNode { 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 // 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 const parentNode = context.parent && context.parent.node
if (parentNode && parentNode.type === NodeTypes.ELEMENT) { if (parentNode && parentNode.type === NodeTypes.ELEMENT) {
lazyApplyVShow = !!( shouldDeferred = !!(
isTransitionTag(parentNode.tag) && isTransitionTag(parentNode.tag) &&
findProp(parentNode, 'appear', false, true) findProp(parentNode, 'appear', false, true)
) )
if (lazyApplyVShow) { if (shouldDeferred) {
context.parent!.parent!.block.hasLazyApplyVShow = true context.parent!.parent!.block.hasDeferredVShow = true
} }
} }
@ -49,6 +49,6 @@ export const transformVShow: DirectiveTransform = (dir, node, context) => {
dir, dir,
name: 'show', name: 'show',
builtin: true, builtin: true,
lazy: lazyApplyVShow, deferred: shouldDeferred,
}) })
} }