fix: correct start of `{:else if}` and `{:else}`

baseballyama 2 weeks ago
parent 95d07de7f9
commit 2c7758f41a

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: correct start of `{:else if}` and `{:else}`

@ -328,13 +328,13 @@ function open(parser) {
/** @param {import('../index.js').Parser} parser */ /** @param {import('../index.js').Parser} parser */
function next(parser) { function next(parser) {
const start = parser.index - 1; const next_to_bracket = parser.index - 1;
const block = parser.current(); // TODO type should not be TemplateNode, that's much too broad const block = parser.current(); // TODO type should not be TemplateNode, that's much too broad
if (block.type === 'IfBlock') { if (block.type === 'IfBlock') {
if (!parser.eat('else')) e.expected_token(start, '{:else} or {:else if}'); if (!parser.eat('else')) e.expected_token(next_to_bracket, '{:else} or {:else if}');
if (parser.eat('if')) e.block_invalid_elseif(start); if (parser.eat('if')) e.block_invalid_elseif(next_to_bracket);
parser.allow_whitespace(); parser.allow_whitespace();
@ -354,7 +354,7 @@ function next(parser) {
/** @type {ReturnType<typeof parser.append<import('#compiler').IfBlock>>} */ /** @type {ReturnType<typeof parser.append<import('#compiler').IfBlock>>} */
const child = parser.append({ const child = parser.append({
start: parser.index, start: next_to_bracket - 1,
end: -1, end: -1,
type: 'IfBlock', type: 'IfBlock',
elseif: true, elseif: true,
@ -376,7 +376,7 @@ function next(parser) {
} }
if (block.type === 'EachBlock') { if (block.type === 'EachBlock') {
if (!parser.eat('else')) e.expected_token(start, '{:else}'); if (!parser.eat('else')) e.expected_token(next_to_bracket, '{:else}');
parser.allow_whitespace(); parser.allow_whitespace();
parser.eat('}', true); parser.eat('}', true);
@ -392,7 +392,7 @@ function next(parser) {
if (block.type === 'AwaitBlock') { if (block.type === 'AwaitBlock') {
if (parser.eat('then')) { if (parser.eat('then')) {
if (block.then) { if (block.then) {
e.block_duplicate_clause(start, '{:then}'); e.block_duplicate_clause(next_to_bracket, '{:then}');
} }
if (!parser.eat('}')) { if (!parser.eat('}')) {
@ -411,7 +411,7 @@ function next(parser) {
if (parser.eat('catch')) { if (parser.eat('catch')) {
if (block.catch) { if (block.catch) {
e.block_duplicate_clause(start, '{:catch}'); e.block_duplicate_clause(next_to_bracket, '{:catch}');
} }
if (!parser.eat('}')) { if (!parser.eat('}')) {
@ -428,10 +428,10 @@ function next(parser) {
return; return;
} }
e.expected_token(start, '{:then ...} or {:catch ...}'); e.expected_token(next_to_bracket, '{:then ...} or {:catch ...}');
} }
e.block_invalid_continuation_placement(start); e.block_invalid_continuation_placement(next_to_bracket);
} }
/** @param {import('../index.js').Parser} parser */ /** @param {import('../index.js').Parser} parser */

@ -82,7 +82,7 @@
"children": [ "children": [
{ {
"type": "IfBlock", "type": "IfBlock",
"start": 58, "start": 42,
"end": 89, "end": 89,
"expression": { "expression": {
"type": "BinaryExpression", "type": "BinaryExpression",

Loading…
Cancel
Save