Skip to content

Commit 083d460

Browse files
authored
fix(language-core): map interpolation error with multiple variables correctly (#5158)
1 parent 24166ba commit 083d460

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Diff for: packages/language-core/lib/codegen/template/interpolation.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ function* forEachInterpolationSegment(
134134
const curVar = ctxVars[i];
135135
const nextVar = ctxVars[i + 1];
136136

137-
yield* generateVar(code, ctx.specialVars, destructuredPropNames, templateRefNames, curVar, nextVar);
137+
yield* generateVar(code, ctx.specialVars, destructuredPropNames, templateRefNames, curVar);
138138

139139
if (nextVar.isShorthand) {
140140
yield [code.slice(curVar.offset + curVar.text.length, nextVar.offset + nextVar.text.length), curVar.offset + curVar.text.length];
@@ -161,12 +161,11 @@ function* generateVar(
161161
specialVars: Set<string>,
162162
destructuredPropNames: Set<string> | undefined,
163163
templateRefNames: Set<string> | undefined,
164-
curVar: CtxVar,
165-
nextVar: CtxVar = curVar
164+
curVar: CtxVar
166165
): Generator<[fragment: string, offset: number | undefined, type?: 'errorMappingOnly']> {
167166
// fix https://github.com/vuejs/language-tools/issues/1205
168167
// fix https://github.com/vuejs/language-tools/issues/1264
169-
yield ['', nextVar.offset, 'errorMappingOnly'];
168+
yield ['', curVar.offset, 'errorMappingOnly'];
170169

171170
const isDestructuredProp = destructuredPropNames?.has(curVar.text) ?? false;
172171
const isTemplateRef = templateRefNames?.has(curVar.text) ?? false;
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<script setup lang="ts">
2+
import { ref } from "vue";
3+
4+
const foo = ref<{ bar: string } | undefined>();
5+
</script>
6+
7+
<template>
8+
<!-- @vue-expect-error -->
9+
<div v-if="foo.bar || foo"></div>
10+
</template>

0 commit comments

Comments
 (0)