withastro / language-tools

Language tools for Astro
MIT License
262 stars 52 forks source link

🐛 BUG: HTML comments not properly highlighted in ternary expressions #271

Open markmals opened 2 years ago

markmals commented 2 years ago

Describe the Bug

When using an HTML comment as one of the results of an inline ternary expression in an Astro template file, Visual Studio Code with the Astro extension (version: 0.16.1) does not properly highlight it as a comment and instead highlights it as what appears to be invalid JSX. Image attached:

Screen Shot 2022-05-05 at 12 32 55 PM

Steps to Reproduce

  1. Install the Astro extension (version: 0.16.1) for Visual Studio Code.
  2. Open or create an Astro template file (.astro) in Visual Studio Code.
  3. Write a ternary expression in the template file where one of the results is an HTML comment, for example:
    
    ---
    const sayHello = false
    ---

{ sayHello ?

Hello, World!

: }


4. Observe how Visual Studio Code doesn't correctly highlight the HTML comment (`<!-- Goodbye, World. -->`) as a comment.

Princesseuh commented 2 years ago

This happens because we treat those context as JSX syntax (which can't have HTML comments) instead of HTML. I wonder if we'd be able to add HTML comments to the JSX syntax for this use case :thinking:

Good catch, thanks for the report!