Skip to content

Commit 2abec30

Browse files
serkodevKazariEX
andauthored
fix(language-core): respect directive comments before v-else (#5753)
Co-authored-by: KazariEX <zinkawaii@qq.com>
1 parent 6646704 commit 2abec30

File tree

2 files changed

+10
-8
lines changed
  • packages/language-core/lib/codegen/template
  • test-workspace/tsc/passedFixtures/vue3/#5729

2 files changed

+10
-8
lines changed

packages/language-core/lib/codegen/template/vIf.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ export function* generateVIf(
1414
node: CompilerDOM.IfNode,
1515
): Generator<Code> {
1616
const originalBlockConditionsLength = ctx.blockConditions.length;
17+
const isFragment = node.codegenNode
18+
&& 'consequent' in node.codegenNode
19+
&& 'tag' in node.codegenNode.consequent
20+
&& node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
1721

1822
for (let i = 0; i < node.branches.length; i++) {
1923
const branch = node.branches[i]!;
@@ -48,7 +52,7 @@ export function* generateVIf(
4852
}
4953

5054
yield `{${newLine}`;
51-
yield* generateElementChildren(options, ctx, branch.children, isFragment(node) || branch.isTemplateIf);
55+
yield* generateElementChildren(options, ctx, branch.children, i !== 0 || isFragment);
5256
yield `}${newLine}`;
5357

5458
if (addedBlockCondition) {
@@ -58,10 +62,3 @@ export function* generateVIf(
5862

5963
ctx.blockConditions.length = originalBlockConditionsLength;
6064
}
61-
62-
function isFragment(node: CompilerDOM.IfNode) {
63-
return node.codegenNode
64-
&& 'consequent' in node.codegenNode
65-
&& 'tag' in node.codegenNode.consequent
66-
&& node.codegenNode.consequent.tag === CompilerDOM.FRAGMENT;
67-
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div v-if="true" />
3+
<!-- @vue-expect-error -->
4+
<div v-else :class="unknownProp" />
5+
</template>

0 commit comments

Comments
 (0)