From 91043002e2bfbdffcb14fd0fe0115c254863ca05 Mon Sep 17 00:00:00 2001 From: Vadim Kruglov Date: Thu, 18 Apr 2024 14:17:14 +0700 Subject: [PATCH] refactor(compiler-core): add in buildProps an auxiliary variable hasVFor --- packages/compiler-core/src/transforms/transformElement.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/compiler-core/src/transforms/transformElement.ts b/packages/compiler-core/src/transforms/transformElement.ts index b104dbe320e..d497876076c 100644 --- a/packages/compiler-core/src/transforms/transformElement.ts +++ b/packages/compiler-core/src/transforms/transformElement.ts @@ -411,6 +411,7 @@ export function buildProps( const mergeArgs: PropsExpression[] = [] const runtimeDirectives: DirectiveNode[] = [] const hasChildren = children.length > 0 + const hasVFor = context.scopes.vFor > 0 let shouldUseBlock = false // patchFlag analysis @@ -502,7 +503,7 @@ export function buildProps( let isStatic = true if (name === 'ref') { hasRef = true - if (context.scopes.vFor > 0) { + if (hasVFor) { properties.push( createObjectProperty( createSimpleExpression('ref_for', true), @@ -601,7 +602,7 @@ export function buildProps( shouldUseBlock = true } - if (isVBind && isStaticArgOf(arg, 'ref') && context.scopes.vFor > 0) { + if (isVBind && isStaticArgOf(arg, 'ref') && hasVFor) { properties.push( createObjectProperty( createSimpleExpression('ref_for', true), @@ -617,7 +618,7 @@ export function buildProps( if (isVBind) { // if in v-bind object will have a ref we should set ref_for to true // otherwise the ref will be set to a random element in the list - if (context.scopes.vFor > 0) properties.push( + if (hasVFor) properties.push( createObjectProperty( createSimpleExpression('ref_for', true), createSimpleExpression('true'),