Skip to content
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

prettier-plugin-svelte delete part of snippet types, resulting in broken svelte code #455

Closed
lts20050703 opened this issue Aug 2, 2024 · 3 comments

Comments

@lts20050703
Copy link

lts20050703 commented Aug 2, 2024

Describe the bug

prettier-plugin-svelte delete part of snippet types, resulting in broken code

Reproduction

<script lang="ts">
  const arr: string[] = []
  const obj: { key: string } = {}
</script>
{#snippet test1(arg: typeof arr[number])}
{/snippet}
{#snippet test2(arg: typeof obj["key"])}
{/snippet}

will first format to

<script lang="ts">
  const arr: string[] = []
  const obj: { key: string } = {}
</script>
{#snippet test1(arg: (typeof arr)[number])}
{/snippet}
{#snippet test2(arg: (typeof obj)["key"])}
{/snippet}

then finally format to this broken svelte code

<script lang="ts">
  const arr: string[] = []
  const obj: { key: string } = {}
</script>
{#snippet test1(arg: (typeof arr)}
{/snippet}
{#snippet test2(arg: (typeof obj)}
{/snippet}

System Info

  System:
    OS: Linux 6.5 KDE neon 6.0 6.0
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 5.88 GB / 15.40 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 22.5.1 - ~/.local/share/nvm/v22.5.1/bin/node
    Yarn: 1.22.22 - ~/.local/share/nvm/v22.5.1/bin/yarn
    npm: 10.8.2 - ~/.local/share/nvm/v22.5.1/bin/npm
    pnpm: 9.4.0 - ~/.local/share/nvm/v22.5.1/bin/pnpm
    bun: 1.1.16 - ~/.bun/bin/bun
  Browsers:
    Brave Browser: 127.1.68.134
  npmPackages:
    svelte: ^5.0.0-next.206 => 5.0.0-next.206

Severity

annoyance

@jonathonadams
Copy link

Similarly

{#snippet foo({ onselect }: { onselect: (value: string) => void})}
    <p>...</p>
{/snippet}

Gets formatted to

{#snippet foo({ onselect }: { onselect: (value: string)}
      <p>...</p>
{/snippet}

@mattlehrer
Copy link

I am facing this problem with this snippet:

{#snippet variableIcon(type: (typeof variableTypes)[number])}
...
{/snippet}

It gets formatted as {#snippet variableIcon(type: (typeof variableTypes)}

Changing to this fixed it:

<script>
...
type IconTypes = (typeof variableTypes)[number];
</script>
{#snippet variableIcon(type: IconTypes)}
...
{/snippet}

@dummdidumm
Copy link
Member

Apologies for the delay, this was fixed a while ago but only published just now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants