Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lts20050703 opened this issue Mar 1, 2025 · 1 comment
Labels
awaiting submitter bug Something isn't working

Comments

@lts20050703
Copy link

lts20050703 commented Mar 1, 2025

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 lts20050703 added the bug Something isn't working label Mar 1, 2025
@jasonlyu123
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting submitter bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants