Skip to content

Commit

Permalink
fix(language-core): handle v-for with v-once correctly (#4830)
Browse files Browse the repository at this point in the history
  • Loading branch information
KazariEX committed Sep 10, 2024
1 parent 990363c commit 814b30f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/language-core/lib/codegen/template/templateChild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export function* generateTemplateChild(

const shouldInheritRootNodeAttrs = options.inheritAttrs;

const cur = node as CompilerDOM.ElementNode | CompilerDOM.IfNode | CompilerDOM.ForNode;
if (cur.codegenNode?.type === CompilerDOM.NodeTypes.JS_CACHE_EXPRESSION) {
cur.codegenNode = cur.codegenNode.value as any;
}

if (node.type === CompilerDOM.NodeTypes.ROOT) {
let prev: CompilerDOM.TemplateChildNode | undefined;
if (shouldInheritRootNodeAttrs && node.children.length === 1 && node.children[0].type === CompilerDOM.NodeTypes.ELEMENT) {
Expand Down
3 changes: 3 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#4827/child.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<pre v-for="_ in []" v-once></pre>
</template>
7 changes: 7 additions & 0 deletions test-workspace/tsc/passedFixtures/vue3/#4827/main.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<script setup lang="ts">
import Main from './child.vue'
</script>

<template>
<Main />
</template>

0 comments on commit 814b30f

Please sign in to comment.