Skip to content

Commit 804b714

Browse files
authored
fix: correctly validate nested if block tags (#13218)
Fixes #13210
1 parent 865ec18 commit 804b714

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

packages/svelte/src/compiler/phases/2-analyze/visitors/IfBlock.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ export function IfBlock(node, context) {
1212
validate_block_not_empty(node.alternate, context);
1313

1414
if (context.state.analysis.runes) {
15-
const parent = context.path.at(-1);
16-
const expected =
17-
context.path.at(-2)?.type === 'IfBlock' &&
18-
parent?.type === 'Fragment' &&
19-
parent.nodes.length === 1
20-
? ':'
21-
: '#';
22-
23-
validate_opening_tag(node, context.state, expected);
15+
validate_opening_tag(node, context.state, node.elseif ? ':' : '#');
2416
}
2517

2618
mark_subtree_dynamic(context.path);

packages/svelte/tests/validator/samples/if-block-whitespace-runes/errors.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
"code": "block_unexpected_character",
44
"message": "Expected a `#` character immediately following the opening bracket",
55
"start": {
6-
"line": 5,
6+
"line": 10,
77
"column": 1
88
},
99
"end": {
10-
"line": 5,
10+
"line": 10,
1111
"column": 6
1212
}
1313
}

packages/svelte/tests/validator/samples/if-block-whitespace-runes/input.svelte

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<svelte:options runes={true} />
22

3+
<!-- ok -->
4+
{#if true}{#if true}{/if}{/if}
5+
{#if foo}{:else if bar}{/if}
6+
{#if foo}{:else}{/if}
7+
38
<!-- prettier-ignore -->
49
<div>
510
{ #if true}

0 commit comments

Comments
 (0)