Skip to content

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

Open
@lts20050703

Description

@lts20050703

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions