Skip to content

Commit

Permalink
fix: exclude null or undefined from v-for source
Browse files Browse the repository at this point in the history
close #3102
  • Loading branch information
johnsoncodehk committed May 1, 2023
1 parent 6fb19fb commit 83e9ece
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/vue-language-core/src/generators/template.ts
Expand Up @@ -464,6 +464,7 @@ export function generate(
codes.push(`] of (await import('${sharedTypesImport}')).getVForSourceType`);
if (source.type === CompilerDOM.NodeTypes.SIMPLE_EXPRESSION) {
codes.push(
'(',
...createInterpolationCode(
source.content,
source.loc,
Expand All @@ -472,6 +473,7 @@ export function generate(
'(',
')',
),
'!)', // #3102
') {\n',
);

Expand Down
16 changes: 16 additions & 0 deletions packages/vue-test-workspace/vue-tsc/#3102/main.vue
@@ -0,0 +1,16 @@
<script setup lang="ts">
import { ref } from 'vue';
type Item = {
id: number,
text: string
}
const items = ref(null as null | Item[])
</script>

<template>
<div v-for="item in items" :key="item.id">
<div>{{ item.id }}</div>
<div>{{ item.text }}</div>
</div>
</template>

0 comments on commit 83e9ece

Please sign in to comment.