From efa7c9a3be446595fe1842622c7c70b87e616810 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 2 Nov 2024 12:56:50 +0800 Subject: [PATCH 1/3] fix: consistent interpolation behavior of shorthand binding --- .../lib/codegen/template/elementProps.ts | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) 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)); } From d66f54de4d0fcaae0d17e8eed9864352c971e7b6 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 2 Nov 2024 13:03:48 +0800 Subject: [PATCH 2/3] test: add --- test-workspace/tsc/passedFixtures/vue3/#7777/comp.vue | 5 +++++ test-workspace/tsc/passedFixtures/vue3/#7777/main.vue | 10 ++++++++++ 2 files changed, 15 insertions(+) create mode 100644 test-workspace/tsc/passedFixtures/vue3/#7777/comp.vue create mode 100644 test-workspace/tsc/passedFixtures/vue3/#7777/main.vue diff --git a/test-workspace/tsc/passedFixtures/vue3/#7777/comp.vue b/test-workspace/tsc/passedFixtures/vue3/#7777/comp.vue new file mode 100644 index 0000000000..bb43c1af88 --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3/#7777/comp.vue @@ -0,0 +1,5 @@ + diff --git a/test-workspace/tsc/passedFixtures/vue3/#7777/main.vue b/test-workspace/tsc/passedFixtures/vue3/#7777/main.vue new file mode 100644 index 0000000000..ca9a33667f --- /dev/null +++ b/test-workspace/tsc/passedFixtures/vue3/#7777/main.vue @@ -0,0 +1,10 @@ + + + From ff97cbea0c0712fb25a34d134263d8a185d0cbb3 Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sat, 2 Nov 2024 13:05:51 +0800 Subject: [PATCH 3/3] test: rename --- test-workspace/tsc/passedFixtures/vue3/{#7777 => #4973}/comp.vue | 0 test-workspace/tsc/passedFixtures/vue3/{#7777 => #4973}/main.vue | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename test-workspace/tsc/passedFixtures/vue3/{#7777 => #4973}/comp.vue (100%) rename test-workspace/tsc/passedFixtures/vue3/{#7777 => #4973}/main.vue (100%) diff --git a/test-workspace/tsc/passedFixtures/vue3/#7777/comp.vue b/test-workspace/tsc/passedFixtures/vue3/#4973/comp.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3/#7777/comp.vue rename to test-workspace/tsc/passedFixtures/vue3/#4973/comp.vue diff --git a/test-workspace/tsc/passedFixtures/vue3/#7777/main.vue b/test-workspace/tsc/passedFixtures/vue3/#4973/main.vue similarity index 100% rename from test-workspace/tsc/passedFixtures/vue3/#7777/main.vue rename to test-workspace/tsc/passedFixtures/vue3/#4973/main.vue