diff --git a/packages/language-core/lib/codegen/template/elementProps.ts b/packages/language-core/lib/codegen/template/elementProps.ts index f6ca405cc8..bdb50705c0 100644 --- a/packages/language-core/lib/codegen/template/elementProps.ts +++ b/packages/language-core/lib/codegen/template/elementProps.ts @@ -302,11 +302,8 @@ function* generatePropExp( isShorthand: boolean, enableCodeFeatures: boolean ): Generator { - if (isShorthand && features.completion) { - features = { - ...features, - completion: undefined, - }; + if (isShorthand) { + features.completion = undefined; } if (exp && exp.constType !== CompilerDOM.ConstantTypes.CAN_STRINGIFY) { // style='z-index: 2' will compile to {'z-index':'2'} if (!isShorthand) { // vue 3.4+ @@ -320,19 +317,37 @@ function* generatePropExp( '(', ')' ); - } else { + } + else { const propVariableName = camelize(exp.loc.source); if (variableNameRegex.test(propVariableName)) { - if (!ctx.hasLocalVariable(propVariableName)) { - ctx.accessExternalVariable(propVariableName, exp.loc.start.offset); - yield `__VLS_ctx.`; - } - yield* generateCamelized( + const isDestructuredProp = options.destructuredPropNames?.has(propVariableName) ?? false; + const isTemplateRef = options.templateRefNames?.has(propVariableName) ?? false; + + const codes = generateCamelized( exp.loc.source, exp.loc.start.offset, features ); + + if (ctx.hasLocalVariable(propVariableName) || isDestructuredProp) { + yield* codes; + } + else { + ctx.accessExternalVariable(propVariableName, exp.loc.start.offset); + + if (isTemplateRef) { + yield `__VLS_unref(`; + yield* codes; + yield `)`; + } + else { + yield `__VLS_ctx.`; + yield* codes; + } + } + if (enableCodeFeatures) { ctx.inlayHints.push(createVBindShorthandInlayHintInfo(prop.loc, propVariableName)); } diff --git a/test-workspace/tsc/passedFixtures/vue3/#4973/comp.vue b/test-workspace/tsc/passedFixtures/vue3/#4973/comp.vue new file mode 100644 index 0000000000..bb43c1af88 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3/#4973/comp.vue @@ -0,0 +1,5 @@ + diff --git a/test-workspace/tsc/passedFixtures/vue3/#4973/main.vue b/test-workspace/tsc/passedFixtures/vue3/#4973/main.vue new file mode 100644 index 0000000000..ca9a33667f --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3/#4973/main.vue @@ -0,0 +1,10 @@ + + +