Skip to content

Commit

Permalink
fix(language-core): consistent interpolation behavior of shorthand bi…
Browse files Browse the repository at this point in the history
…nding (#4975)
  • Loading branch information
KazariEX authored Dec 20, 2024
1 parent 9abe5d9 commit 34d7bfd
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
30 changes: 24 additions & 6 deletions packages/language-core/lib/codegen/template/elementProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,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));
}
Expand Down
5 changes: 5 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#4973/comp.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<script setup lang="ts">
defineProps<{
condition: 'B'
}>();
</script>
10 changes: 10 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#4973/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script setup lang="ts">
import Comp from './comp.vue';
let condition!: 'A' | 'B';
</script>

<template>
<div v-if="condition === 'A'"></div>
<Comp v-else :condition />
</template>

0 comments on commit 34d7bfd

Please sign in to comment.