Skip to content

Commit

Permalink
fix: move snippets to correct place when only module script present
Browse files Browse the repository at this point in the history
  • Loading branch information
dummdidumm committed Jan 8, 2025
1 parent b5ec504 commit 52c0d9f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion packages/svelte2tsx/src/svelte2tsx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export function svelte2tsx(
end,
scriptTag
? scriptTag.start + 1 // +1 because imports are also moved at that position, and we want to move interfaces after imports
: moduleScriptTag.end
: instanceScriptTarget
);
} else if (scriptTag) {
str.move(start, end, renderFunctionStart);
Expand Down

2 comments on commit 52c0d9f

@Wombosvideo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix introduces another bug. If using both exported module-level snippets and non-exported instance-level snippets, the instance-level snippets are now no longer able to access the instance's variables.

@Wombosvideo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to set up a minimal reproduction: Found out that only passed snippets are affected (so far)

<script lang="ts" module>
  export { moduleLevel };
</script>

<script lang="ts">
  import type { Snippet } from 'svelte';

  const { children }: { children: Snippet } = $props();
</script>

{#snippet moduleLevel()}{/snippet}

{#snippet componentLevel()}
  {@render children?.()} <!-- Cannot find name 'children' -->
{/snippet}

Please sign in to comment.