Skip to content

Commit

Permalink
fix: harden split/move logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Nov 22, 2023
1 parent a9940c1 commit 3f691b6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
12 changes: 9 additions & 3 deletions packages/svelte2tsx/src/htmlxtojsx_v2/utils/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,14 @@ export function transform(
}

let removeStart = start;
for (const transformation of [...moves].sort((t1, t2) => t1[0] - t2[0])) {
const sortedMoves = [...moves].sort((t1, t2) => t1[0] - t2[0]);
for (const transformation of sortedMoves) {
if (removeStart < transformation[0]) {
if (deletePos !== moves.length && removeStart > deleteDest) {
if (
deletePos !== moves.length &&
removeStart > deleteDest &&
!(removeStart < end && transformation[0] >= end)
) {
str.move(removeStart, transformation[0], end);
}
if (transformation[0] < end) {
Expand All @@ -98,7 +103,8 @@ export function transform(
if (removeStart > end) {
// Reset the end to the last transformation before the end if there were transformations after the end
// so we still delete the correct range afterwards
removeStart = moves.find((m) => m[1] < end)?.[1] ?? end;
let idx = sortedMoves.findIndex((m) => m[0] > end) - 1;
removeStart = sortedMoves[idx]?.[1] ?? end;
}

if (removeStart < end) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@ return __sveltets_2_any(0)}
return __sveltets_2_any(0)},}});
{ svelteHTML.createElement("div", {});asd; }

Component}
Component}

{ const $$_tsiL0C = __sveltets_2_ensureComponent(List); new $$_tsiL0C({ target: __sveltets_2_any(), props: { "data":[1, 2, 3],row:(item) => {
item;
return __sveltets_2_any(0)},}});

List}
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
{#snippet bar(x)}
<div>asd{x}</div>
{/snippet}
</Component>
</Component>

<List data={[1, 2, 3]}>
{#snippet row(item)}
{item}
{/snippet}
</List>

0 comments on commit 3f691b6

Please sign in to comment.