fix: error if `{:else}` is followed by another `{:else}` or `{:else if ...}` (#18900)

Fixes #18202
pull/18889/merge
Maksim Romanov 14 hours ago committed by GitHub
parent 179f66b297
commit fe4fb460b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: error if `{:else}` is followed by another `{:else}` or `{:else if ...}`

@ -532,6 +532,7 @@ function next(parser) {
if (block.type === 'IfBlock') {
if (!parser.eat('else')) e.expected_token(start, '{:else} or {:else if}');
if (parser.eat('if')) e.block_invalid_elseif(start);
if (block.alternate) e.block_duplicate_clause(start, '{:else}');
parser.allow_whitespace();
@ -580,6 +581,7 @@ function next(parser) {
if (block.type === 'EachBlock') {
if (!parser.eat('else')) e.expected_token(start, '{:else}');
if (block.fallback) e.block_duplicate_clause(start, '{:else}');
parser.allow_whitespace();
parser.eat('}', true);

@ -0,0 +1,9 @@
import { test } from '../../test';
export default test({
error: {
code: 'block_duplicate_clause',
message: '{:else} cannot appear more than once within a block',
position: [42, 42]
}
});

@ -0,0 +1,7 @@
{#each items as item}
{item}
{:else}
A
{:else}
B
{/each}

@ -0,0 +1,9 @@
import { test } from '../../test';
export default test({
error: {
code: 'block_duplicate_clause',
message: '{:else} cannot appear more than once within a block',
position: [23, 23]
}
});
Loading…
Cancel
Save