diff --git a/packages/svelte2tsx/src/htmlxtojsx/index.ts b/packages/svelte2tsx/src/htmlxtojsx/index.ts index 10a8433d3..b6a0afb07 100644 --- a/packages/svelte2tsx/src/htmlxtojsx/index.ts +++ b/packages/svelte2tsx/src/htmlxtojsx/index.ts @@ -188,7 +188,9 @@ export function convertHtmlxToJsx( try { switch (node.type) { case 'IfBlock': - ifScope = ifScope.getParent(); + if (!node.elseif) { + ifScope = ifScope.getParent(); + } break; case 'EachBlock': templateScopeManager.eachLeave(node); diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/nested-if-else-if-and-each-block/expected.jsx b/packages/svelte2tsx/test/htmlx2jsx/samples/nested-if-else-if-and-each-block/expected.jsx new file mode 100644 index 000000000..db202efcf --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/nested-if-else-if-and-each-block/expected.jsx @@ -0,0 +1,5 @@ +<>{(true) ? <> + {(true) ? <> : (true) ? <> : <> } + : <> + {__sveltets_each([], (_) => /*Ωignore_startΩ*/(!(true)) && /*Ωignore_endΩ*/<>)} + } \ No newline at end of file diff --git a/packages/svelte2tsx/test/htmlx2jsx/samples/nested-if-else-if-and-each-block/input.svelte b/packages/svelte2tsx/test/htmlx2jsx/samples/nested-if-else-if-and-each-block/input.svelte new file mode 100644 index 000000000..6b2b04e1e --- /dev/null +++ b/packages/svelte2tsx/test/htmlx2jsx/samples/nested-if-else-if-and-each-block/input.svelte @@ -0,0 +1,5 @@ +{#if true} + {#if true}{:else if true}{/if} +{:else} + {#each [] as _}{/each} +{/if}