Skip to content

Formatter removes parentheses from the each block types #486

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
yuto0214w opened this issue Feb 4, 2025 · 0 comments
Open

Formatter removes parentheses from the each block types #486

yuto0214w opened this issue Feb 4, 2025 · 0 comments

Comments

@yuto0214w
Copy link

Prettier 3.4.2
prettier-plugin-svelte 3.3.3

// .prettierrc
{
  "plugins": ["prettier-plugin-svelte"],
  "overrides": [
    {
      "files": "*.svelte",
      "options": {
        "parser": "svelte"
      }
    }
  ]
}

Input:

<script lang="ts">
  const modes = { a: "mode 1", b: "mode 2", c: "mode 3" } as const;
  type Mode = keyof typeof modes;
  let currentMode: Mode = $state("a");
</script>

{#each (Object.entries(modes) as [Mode, string][]) as [id, name]}
  <button onclick={() => (currentMode = id)}>{name}</button>
{/each}

Output:

<script lang="ts">
  const modes = { a: "mode 1", b: "mode 2", c: "mode 3" } as const;
  type Mode = keyof typeof modes;
  let currentMode: Mode = $state("a");
</script>

{#each Object.entries(modes) as [Mode, string][] as [id, name]}
  <button onclick={() => (currentMode = id)}>{name}</button>
{/each}

Expected output: (same as input)

Why?

Formatter is removing parentheses from the each block types, which leads to a syntax error when the code is formatted.

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

1 participant