language-tools icon indicating copy to clipboard operation
language-tools copied to clipboard

comment close character sequence in HTML comment breaks module exports

Open RSWilli opened this issue 2 years ago • 2 comments

Describe the bug

using a */ in an HTML Comment breaks the modules exports, and the language server complains

Reproduction

insert this comment in the svelte file:

<!--
@component
AudioVis is a SVG component to display the FFT data of an audio stream.
@example
    ```tsx
    <AudioVis getFFT={() => /* get the FFT data */}/>
    ```
-->

Afterwards, other files importing the module report the following:

Module '"/path/to/my.svelte"' has no default export.ts(1192)

And the svelte file itself reports the following error at the location of the first Tag:

'render' is declared but its value is never read.ts(6133)

workaround: just don't use */ in HTML comments

Expected behaviour

nothing, it is a comment and should be more or less ignored

System Info

  • OS: linux
  • IDE:VSCode

Which package is the issue about?

svelte2tsx

Additional Information, eg. Screenshots

I suspect this is because svelte2tsx transforms the comment to a JS comment, which is wrongly terminated, as highlighted by githubs highlighting:

/*
@component
AudioVis is a SVG component to display the FFT data of an audio stream.
@example
    ```tsx
    <AudioVis getFFT={() => /* get the FFT data */}/>
    ```
*/

possible solution:

generating the comment as follows wont break the syntax:

// @component
// AudioVis is a SVG component to display the FFT data of an audio stream.
// @example
//    ```tsx
//    <AudioVis getFFT={() => /* get the FFT data */}/>
//    ```

otherwise just skip the comment in tsx

RSWilli avatar Jan 10 '23 12:01 RSWilli

This is tricky. We transform the comment into a JSDoc comment, which can only be a multi-line comment. One solution is to add invisible characters like u+200b to escape it. but copying the example would also copy that character. But we suffer from that ourselves recently so I am not sure about that.

jasonlyu123 avatar Jan 11 '23 01:01 jasonlyu123

I'll drop these links, since they cover the same problem: https://github.com/microsoft/tsdoc/issues/166 https://github.com/jsdoc/jsdoc/issues/821

it could be solved if JSDoc itself would allow such an escape method, which would have to be understood by the editor/docs renderer and unescaped, so that copying invisible characters cannot happen

RSWilli avatar Jan 11 '23 14:01 RSWilli