Skip to content

Commit

Permalink
fix: don't move appended content from previous node while hoisting in…
Browse files Browse the repository at this point in the history
…terface

#2592
  • Loading branch information
dummdidumm committed Nov 20, 2024
1 parent b6cac97 commit 44ed5ef
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
17 changes: 15 additions & 2 deletions packages/svelte2tsx/src/svelte2tsx/nodes/HoistableInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,21 @@ export class HoistableInterfaces {

const hoistable = this.determineHoistableInterfaces();
if (hoistable.has(this.props_interface.name)) {
for (const [, node] of hoistable) {
str.move(node.pos + astOffset, node.end + astOffset, scriptStart);
for (const [name, node] of hoistable) {
let pos = node.pos + astOffset;

// node.pos includes preceeding whitespace, which could mean we accidentally also move stuff appended to a previous node
if (name !== '$$ComponentProps') {
if (str.original[pos] === '\r') {
pos++;
}
if (/\s/.test(str.original[pos])) {
pos++;
str.prependRight(pos, '\n');
}
}

str.move(pos, node.end + astOffset, scriptStart);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
};function render() {





let { a, b }: Props<boolean> = $props();
;
async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
};type $$ComponentProps = { a: Dependency, b: string };;function render() {



let { a, b }:/*Ωignore_startΩ*/$$ComponentProps/*Ωignore_endΩ*/ = $props();
;
async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
};function render() {




let { foo }: Props = $props();
;
async () => {};
Expand Down

0 comments on commit 44ed5ef

Please sign in to comment.