language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

Prettier produce invalid code when formatting exported snippets with semi: false

Open lts20050703 opened this issue 9 months ago • 1 comments

Describe the bug

According to the snippets docs, it is possible to export a snippet. https://svelte.dev/docs/svelte/snippet#Exporting-snippets

However, I use semi: false in .prettierrc, and it looks like there's a bug. After pretter removes the semicolon, saving again makes it delete part of the code and produce invalid code.

<script module>
	export { snip }
}{/snippet}

In the case of semi: true, this also happens if the code doesn't have semicolon to begin with, prettier correctly add the semicolon, but "it's too late" and it still delete part of the code and produce invalid code.

<script module>
	export { snip };
}{/snippet}

Reproduction

<script module>
	export { snip }
</script>

{#snippet snip()}{/snippet}

Expected behaviour

<script module>
	export { snip }
</script>

{#snippet snip()}{/snippet}

System Info

IDE: VSCOdium 1.97.2 Extension:

  • Svelte for VS Code: 109.5.2

  • Prettier: 11.0.0

    System: OS: Linux 6.11 KDE neon 6.3 6.3 CPU: (12) x64 AMD Ryzen 5 7640U w/ Radeon 760M Graphics Memory: 580.75 MB / 27.21 GB Container: Yes Shell: 5.2.21 - /bin/bash Binaries: bun: 1.2.1 - /tmp/bun-node-ce532901c/bun Browsers: Brave Browser: 133.1.75.181 npmPackages: prettier: ^3.4.2 => 3.5.2 svelte: ^5.0.0 => 5.20.5

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

No response

lts20050703 avatar Mar 01 '25 01:03 lts20050703

I can't reproduce this. Can you check if you were using the latest version of prettier-plugin-svelte?

jasonlyu123 avatar Mar 03 '25 04:03 jasonlyu123

Edit: On second thought, this might be a different issue. I think this issue got fixed. Closing this bug report

lts20050703 avatar Jul 26 '25 03:07 lts20050703