-
Notifications
You must be signed in to change notification settings - Fork 37
Open
Labels
needs triageIssue needs to be triagedIssue needs to be triaged
Description
Describe the Bug
Using the shorthand form of the JSX Fragment (<>...</>
) as a part of an expression causes a syntax error in the formatter if it does not contain anything, despite being valid syntax.
E.g.,
---
---
<div>
{false ? <p>This won't be formatted.</p> : <></>}
{true && <></>}
{false || <></>}
{[1,2,3].map(() => {
return (<></>)
})}
</div>
Compare that to
<div>
{false ? <p>This won't be displayed.</p> : <>It will be formatted though.</>}
</div>
or
<div>
{true && <Fragment/>}
</div>
or
<div>
<></>
And this shows it isn't empty Fragments in of themselves.
</div>
all of which do work.
Now in almost all of these scenarios it's not entirely clear why you'd even want an empty Fragment, but I personally stumbled across this bug because I tended to use empty Fragments for the else-side of ternaries (never been a big fan of condition && result
).
Steps to Reproduce
npm init astro
using template minimal template- Modify index page to include an empty Fragment in an expression, say,
<p>This document can't be formatted.</p>
<div>
{false ? <p>This won't be displayed.</p> : <></>}
</div>
- Open Command Palette and run Format Document.
- Nothing happens (opening the output of the Astro Language Server reveals that it encountered a syntax error)
Metadata
Metadata
Assignees
Labels
needs triageIssue needs to be triagedIssue needs to be triaged