Skip to content

Commit ba13e5c

Browse files
committed
fix(language-core): @vue-ignore not working for fragment v-if/v-for nodes
close #4232
1 parent cc52990 commit ba13e5c

File tree

2 files changed

+20
-2
lines changed
  • packages/language-core/lib/generators
  • test-workspace/tsc/vue3/directiveComments

2 files changed

+20
-2
lines changed

packages/language-core/lib/generators/template.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ export function* generate(
510510
}
511511

512512
yield _ts(` {\n`);
513-
yield* resetDirectiveComments('end of v-if start');
513+
if (isFragment(node)) {
514+
yield* resetDirectiveComments('end of v-if start');
515+
}
514516
let prev: CompilerDOM.TemplateChildNode | undefined;
515517
for (const childNode of branch.children) {
516518
yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
@@ -557,7 +559,9 @@ export function* generate(
557559
);
558560
yield _ts('!)'); // #3102
559561
yield _ts(') {\n');
560-
yield* resetDirectiveComments('end of v-for start');
562+
if (isFragment(node)) {
563+
yield* resetDirectiveComments('end of v-for start');
564+
}
561565
let prev: CompilerDOM.TemplateChildNode | undefined;
562566
for (const childNode of node.children) {
563567
yield* generateAstNode(childNode, parentEl, prev, componentCtxVar);
@@ -1800,6 +1804,10 @@ export function* generate(
18001804
}
18011805
}
18021806

1807+
function isFragment(node: CompilerDOM.IfNode | CompilerDOM.ForNode) {
1808+
return node.codegenNode && 'consequent' in node.codegenNode && 'tag' in node.codegenNode.consequent && node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
1809+
}
1810+
18031811
export function createTsAst(ts: typeof import('typescript'), astHolder: any, text: string) {
18041812
if (astHolder.__volar_ast_text !== text) {
18051813
astHolder.__volar_ast_text = text;

test-workspace/tsc/vue3/directiveComments/main.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,15 @@
2121
{{ foo }}
2222
<!-- @vue-skip -->
2323
{{ foo }}
24+
25+
<!-- @vue-ignore -->
26+
<div v-if="true" :foo="foo"></div>
27+
<!-- @vue-expect-error -->
28+
<div v-if="true" :foo="foo"></div>
29+
30+
<!-- @vue-ignore -->
31+
<div v-for="_a in 10" :foo="foo"></div>
32+
<!-- @vue-expect-error -->
33+
<div v-for="_a in 10" :foo="foo"></div>
2434
</div>
2535
</template>

0 commit comments

Comments
 (0)