Skip to content

Commit 88d7832

Browse files
authored
fix: correctly handle HTML between implicit snippet props (#2450)
The transformation util was wrong: It did not stop moving content between transformations that were after the end marker #2441
1 parent d9c48ab commit 88d7832

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

packages/svelte2tsx/src/htmlxtojsx_v2/utils/node-utils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,14 @@ export function transform(
8383

8484
let removeStart = start;
8585
const sortedMoves = [...moves].sort((t1, t2) => t1[0] - t2[0]);
86+
// Remove everything between the transformations up until the end position
8687
for (const transformation of sortedMoves) {
8788
if (removeStart < transformation[0]) {
8889
if (
8990
deletePos !== moves.length &&
9091
removeStart > deleteDest &&
91-
!(removeStart < end && transformation[0] >= end)
92+
removeStart < end &&
93+
transformation[0] < end
9294
) {
9395
str.move(removeStart, transformation[0], end);
9496
}

packages/svelte2tsx/test/htmlx2jsx/samples/snippet.v5/expectedv2.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,29 @@
2525

2626
Component}
2727

28-
{ const $$_tsiL0C = __sveltets_2_ensureComponent(List); const $$_tsiL0 = new $$_tsiL0C({ target: __sveltets_2_any(), props: {
29-
"data":[1, 2, 3],row:(item) => { async ()/*Ωignore_positionΩ*/ => {
28+
{ const $$_tsiL0C = __sveltets_2_ensureComponent(List); const $$_tsiL0 = new $$_tsiL0C({ target: __sveltets_2_any(), props: { "data":[1, 2, 3],row:(item) => { async ()/*Ωignore_positionΩ*/ => {
3029
item;
3130
};return __sveltets_2_any(0)},await_inside:() => { async ()/*Ωignore_positionΩ*/ => {
3231
{ const $$_value = await (foo);{ const bar = $$_value; bar;}}
3332
};return __sveltets_2_any(0)},}});/*Ωignore_startΩ*/const {row, await_inside} = $$_tsiL0.$$prop_def;/*Ωignore_endΩ*/
3433

34+
3535
List}
3636

3737
{ const $$_tsiL0C = __sveltets_2_ensureComponent(List); new $$_tsiL0C({ target: __sveltets_2_any(), props: {children:() => { return __sveltets_2_any(0); },}});
3838

3939
List}
4040

41+
{ const $$_tsiL0C = __sveltets_2_ensureComponent(List); const $$_tsiL0 = new $$_tsiL0C({ target: __sveltets_2_any(), props: { children:() => { return __sveltets_2_any(0); },"data":[1, 2, 3],row1:(item) => { async ()/*Ωignore_positionΩ*/ => {
42+
item;
43+
};return __sveltets_2_any(0)},row2:(item) => { async ()/*Ωignore_positionΩ*/ => {
44+
item;
45+
};return __sveltets_2_any(0)},}});/*Ωignore_startΩ*/const {row1, row2} = $$_tsiL0.$$prop_def;/*Ωignore_endΩ*/
46+
47+
{ svelteHTML.createElement("p", {}); }
48+
49+
List}
50+
4151
;__sveltets_2_ensureSnippet(children());
4252

4353
const jsDoc/*Ωignore_positionΩ*/ = (/**@type {number}*/a)/*Ωignore_startΩ*/: ReturnType<import('svelte').Snippet>/*Ωignore_endΩ*/ => { async ()/*Ωignore_positionΩ*/ => {

packages/svelte2tsx/test/htmlx2jsx/samples/snippet.v5/input.svelte

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@
3838
implicit children
3939
</List>
4040

41+
<List data={[1, 2, 3]}>
42+
{#snippet row1(item)}
43+
{item}
44+
{/snippet}
45+
<p>html between snippets</p>
46+
{#snippet row2(item)}
47+
{item}
48+
{/snippet}
49+
</List>
50+
4151
{@render children()}
4252

4353
{#snippet jsDoc(/**@type {number}*/a)}

0 commit comments

Comments
 (0)