withastro / prettier-plugin-astro

Prettier plugin for Astro
Other
479 stars 36 forks source link

🐛 BUG: Unexpected token, expected "}" for no reason #407

Open silveltman opened 8 months ago

silveltman commented 8 months ago

Describe the Bug

This gives error Unexpected token, expected "}":

---
const heading = 'Hello, world!'
const As = 'h1'
---

{
  true && (
    <As>
      {heading}
        <Fragment set:html={'test'} />
    </As>
  )
}

<style>
</style>

You can change almost anything in this file and suddenly it works. For example, switch the order or {heading} and Fragment. Or remove the style tag. Or remove the if statement. etc.

These are my deps:

  "devDependencies": {
    "prettier": "3.2.5",
    "prettier-plugin-astro": "0.13.0",
    "prettier-plugin-astro-organize-imports": "^0.4.1",
    "prettier-plugin-organize-imports": "^3.2.4"
  }

this my prettierconfig:

tabWidth: 2
parser: 'typescript'
semi: false
singleQuote: true
trailingComma: 'es5'
singleAttributePerLine: true
svelteStrictMode: false
plugins:
  - 'prettier-plugin-astro'
  - 'prettier-plugin-organize-imports'
  - 'prettier-plugin-astro-organize-imports' # Really must be last

overrides:
  - files: '*.ts'
    options:
      parser: 'typescript'
  - files: '*.astro'
    options:
      parser: 'astro'

Steps to Reproduce

  1. npm create astro@latest -- --template minimal
  2. add the packages and prettierconfig above in vscode
  3. add the code above anywhere, in a page.astro for example
  4. look at the prettier output in vscode
mark-reason commented 7 months ago

I get the same issue within Githubissues.

  • Githubissues is a development platform for aggregating issues.