fix: correctly validate nested if block tags (#13218)

Fixes #13210
pull/13223/head
Simon H 3 months ago committed by GitHub
parent 865ec18cb7
commit 804b714096
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -12,15 +12,7 @@ export function IfBlock(node, context) {
validate_block_not_empty(node.alternate, context); validate_block_not_empty(node.alternate, context);
if (context.state.analysis.runes) { if (context.state.analysis.runes) {
const parent = context.path.at(-1); validate_opening_tag(node, context.state, node.elseif ? ':' : '#');
const expected =
context.path.at(-2)?.type === 'IfBlock' &&
parent?.type === 'Fragment' &&
parent.nodes.length === 1
? ':'
: '#';
validate_opening_tag(node, context.state, expected);
} }
mark_subtree_dynamic(context.path); mark_subtree_dynamic(context.path);

@ -3,11 +3,11 @@
"code": "block_unexpected_character", "code": "block_unexpected_character",
"message": "Expected a `#` character immediately following the opening bracket", "message": "Expected a `#` character immediately following the opening bracket",
"start": { "start": {
"line": 5, "line": 10,
"column": 1 "column": 1
}, },
"end": { "end": {
"line": 5, "line": 10,
"column": 6 "column": 6
} }
} }

@ -1,5 +1,10 @@
<svelte:options runes={true} /> <svelte:options runes={true} />
<!-- ok -->
{#if true}{#if true}{/if}{/if}
{#if foo}{:else if bar}{/if}
{#if foo}{:else}{/if}
<!-- prettier-ignore --> <!-- prettier-ignore -->
<div> <div>
{ #if true} { #if true}

Loading…
Cancel
Save