Skip to content

Commit 96254df

Browse files
authored
(fix) await/each/if block close at wrong position (#568)
When there's `{#if}..{/if}{#..}` (no space between closing and opening block), it did use the `{` of the next opening tag instead of the current closing tag
1 parent 03c2520 commit 96254df

File tree

5 files changed

+5
-3
lines changed

5 files changed

+5
-3
lines changed

packages/svelte2tsx/src/htmlxtojsx/nodes/await.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,6 @@ export function handleAwait(htmlx: string, str: MagicString, awaitBlock: Node):
7878
}
7979
// {/await} ->
8080
// <>})}
81-
const awaitEndStart = htmlx.lastIndexOf('{', awaitBlock.end);
81+
const awaitEndStart = htmlx.lastIndexOf('{', awaitBlock.end - 1);
8282
str.overwrite(awaitEndStart, awaitBlock.end, '</>})}}');
8383
}

packages/svelte2tsx/src/htmlxtojsx/nodes/each.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function handleEach(htmlx: string, str: MagicString, eachBlock: Node): vo
2929
const endEachStart = htmlx.indexOf('}', contextEnd);
3030
str.overwrite(endEachStart, endEachStart + 1, ' <>');
3131
}
32-
const endEach = htmlx.lastIndexOf('{', eachBlock.end);
32+
const endEach = htmlx.lastIndexOf('{', eachBlock.end - 1);
3333
// {/each} -> </>)} or {:else} -> </>)}
3434
if (eachBlock.else) {
3535
const elseEnd = htmlx.lastIndexOf('}', eachBlock.else.start);

packages/svelte2tsx/src/htmlxtojsx/nodes/if-else.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function handleIf(htmlx: string, str: MagicString, ifBlock: Node): void {
1818
str.overwrite(ifBlock.expression.end, end + 1, '){<>');
1919

2020
// {/if} -> </>}}}</>
21-
const endif = htmlx.lastIndexOf('{', ifBlock.end);
21+
const endif = htmlx.lastIndexOf('{', ifBlock.end - 1);
2222
str.overwrite(endif, ifBlock.end, '</>}}}');
2323
}
2424

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<>{() => {if (name == "world"){<>!</>}}}{__sveltets_each(x, (y) => <>!</>)}{() => {let _$$p = (x); __sveltets_awaitThen(_$$p, (y) => {<>!</>})}}{() => {if (bla){<>*</>}}}</>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{#if name == "world"}!{/if}{#each x as y}!{/each}{#await x then y}!{/await}{#if bla}*{/if}

0 commit comments

Comments
 (0)