Skip to content

Commit

Permalink
fix(language-core): map interpolation error with multiple variables c…
Browse files Browse the repository at this point in the history
…orrectly (vuejs#5158)
  • Loading branch information
KazariEX authored Jan 31, 2025
1 parent 24166ba commit 083d460
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/language-core/lib/codegen/template/interpolation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function* forEachInterpolationSegment(
const curVar = ctxVars[i];
const nextVar = ctxVars[i + 1];

yield* generateVar(code, ctx.specialVars, destructuredPropNames, templateRefNames, curVar, nextVar);
yield* generateVar(code, ctx.specialVars, destructuredPropNames, templateRefNames, curVar);

if (nextVar.isShorthand) {
yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
Expand All @@ -161,12 +161,11 @@ function* generateVar(
specialVars: Set<string>,
destructuredPropNames: Set<string> | undefined,
templateRefNames: Set<string> | undefined,
curVar: CtxVar,
nextVar: CtxVar = curVar
curVar: CtxVar
): Generator<[fragment: string, offset: number | undefined, type?: 'errorMappingOnly']> {
// fix https://github.com/vuejs/language-tools/issues/1205
// fix https://github.com/vuejs/language-tools/issues/1264
yield ['', nextVar.offset, 'errorMappingOnly'];
yield ['', curVar.offset, 'errorMappingOnly'];

const isDestructuredProp = destructuredPropNames?.has(curVar.text) ?? false;
const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
Expand Down
10 changes: 10 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#5157/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<script setup lang="ts">
import { ref } from "vue";
const foo = ref<{ bar: string } | undefined>();
</script>

<template>
<!-- @vue-expect-error -->
<div v-if="foo.bar || foo"></div>
</template>

0 comments on commit 083d460

Please sign in to comment.