From: daiwei Date: Wed, 26 Feb 2025 08:32:26 +0000 (+0800) Subject: fix(compile-vapor): ensure component node is initialized before applyVShow is called X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73bb298451ad02d91fb4664ece6dde4751282136;p=thirdparty%2Fvuejs%2Fcore.git fix(compile-vapor): ensure component node is initialized before applyVShow is called --- diff --git a/packages/compiler-vapor/src/transform.ts b/packages/compiler-vapor/src/transform.ts index 76563899d2..534f28e5d2 100644 --- a/packages/compiler-vapor/src/transform.ts +++ b/packages/compiler-vapor/src/transform.ts @@ -176,6 +176,10 @@ export class TransformContext { this.block.operation.push(...node) } + registerOperationAt(node: OperationNode, index: number): void { + this.block.operation.splice(index, 0, node) + } + create( node: T, index: number, diff --git a/packages/compiler-vapor/src/transforms/transformElement.ts b/packages/compiler-vapor/src/transforms/transformElement.ts index f42801ace6..c47e589953 100644 --- a/packages/compiler-vapor/src/transforms/transformElement.ts +++ b/packages/compiler-vapor/src/transforms/transformElement.ts @@ -33,10 +33,11 @@ import { type IRProps, type IRPropsDynamicAttribute, type IRPropsStatic, + type OperationNode, type VaporDirectiveNode, } from '../ir' import { EMPTY_EXPRESSION } from './utils' -import { findProp } from '../utils' +import { findDir, findProp } from '../utils' export const isReservedProp: (key: string) => boolean = /*#__PURE__*/ makeMap( // the leading comma is intentional so empty string "" is also included @@ -124,7 +125,7 @@ function transformComponentElement( } context.dynamic.flags |= DynamicFlag.NON_TEMPLATE | DynamicFlag.INSERT - context.registerOperation({ + const op: OperationNode = { type: IRNodeTypes.CREATE_COMPONENT_NODE, id: context.reference(), tag, @@ -134,7 +135,16 @@ function transformComponentElement( slots: [...context.slots], once: context.inVOnce, dynamic: dynamicComponent, - }) + } + const hasVShow = findDir(node, 'show') + if (hasVShow) { + const showOperationIndex = context.block.operation.findIndex( + op => op.type === IRNodeTypes.DIRECTIVE && op.name === 'show', + ) + context.registerOperationAt(op, showOperationIndex) + } else { + context.registerOperation(op) + } context.slots = [] }