Open ArmandPhilippot opened 6 months ago
Not 100% sure about the Prettier part, but this is a compiler issue!
Confirmed as a compiler issue! We have some logic to handle these cases, but it looks like it's not being applied 100% of the time. We'll take a look at this when we have some bandwidth to.
Thanks for opening an issue!
If it helps anyone, for my use case I found a workaround:
{ data ? (
<Card
href="https://astro.build/chat/"
title="Community"
body="Come say hi to our amazing Discord community. ❤️"
slot={
/* eslint-disable-next-line @typescript-eslint/no-unnecessary-condition */
data ? 'data' : undefined
}
/>
) : null
}
I have not tested, but I guess the following should also work:
<Card
href="https://astro.build/integrations/"
title={
/* This comment should work */
`Integrations`
}
body="Supercharge your project with new frameworks and libraries."
/>
It is not ideal... but in the meantime, it's not so bad.
Describe the Bug
First of all, I am not sure if this issue belong to the
language-tools
, thecompiler
or theastro
repository. So sorry if I picked the wrong repo.System info
I have the same issue using Node
v21.5.0
.The issue
I can write comments inside JSX like this:
However, if I want to use a comment between the props, it does not work:
On the same line, it does not work neither:
With these examples, I got
Unterminated string literal. ts(1002)
.If I try to put a comment in a ternary like this:
Then I see:
The same error happens if I use the following format:
/* This is a comment */
.In another project using ESlint, it is not Typescript who is complaining but ESlint:
And Prettier does not work neither, it complains with
SyntaxError: Unexpected token
.My expectations
I expect to be able to use comments this way since this pattern is commonly used to disable a linter like ESlint:
Steps to Reproduce
I created a project in Stackblitz ( https://stackblitz.com/edit/astro-comments-parsing-bug?file=src%2Fpages%2Findex.astro ) but the parser does not work (I have a warning in the console
No parser for file type: astro
) so you can download it and open the project in VS Code or you can follow the instructions below.npm create astro@latest -- --template basics
Yes
for all (and keepStrict
for Typescript)./src/pages/index.astro
with: