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

🐛 BUG: Error when using <></> syntax in a ternary expression #422

Open
shreyasminocha opened this issue Jul 11, 2024 · 1 comment
Open

Comments

@shreyasminocha
Copy link

Describe the Bug

Using the <></> syntax in a conditional causes a SyntaxError but AFAIK this is valid syntax.

---
---

<!-- snip -->
  <body>
    {true ? <span></span> : <></>}
  </body>
</html>

Running npx prettier --check . results in:

Checking formatting...
src/pages/index.astro
[error] src/pages/index.astro: SyntaxError: Unexpected token (1:24)
[error] > 1 | true ? <span /> : < />
[error]     |                        ^

I looked for similar reports, but didn't find anything that matched. Sorry if this is a duplicate.

.prettierrc.yml:

plugins:
  - prettier-plugin-astro

overrides:
  - files: "*.astro"
    options:
      parser: astro
  • prettier-plugin-astro: 0.14.0
  • prettier-plugin-astro/node_modules/@astrojs/compiler: 1.8.2

Steps to Reproduce

  1. npm init astro using template "Empty" and TypeScript strictness "Strictest"
  2. npm i --save-dev prettier-plugin-astro prettier
  3. Add the .prettierrc.yml from the description.
  4. npx prettier --write .
  5. Verify that npx prettier --check . reports no errors
  6. Edit the body of src/pages/index.astro to include the expression {true ? <span></span> : <></>}
  7. npx prettier --check . reports a syntax error.
@g-plane
Copy link

g-plane commented Jul 27, 2024

Please consider dprint with markup_fmt. It works well with this syntax:

image

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

2 participants