codemirror / dev

Development repository for the CodeMirror editor project
https://codemirror.net/
Other
5.76k stars 368 forks source link

Typescript / JSX syntax highlighting breaks in certain documents with templated strings #1364

Closed sergeichestakov closed 6 months ago

sergeichestakov commented 6 months ago

Describe the issue

It seems the TypeScript language parser breaks down and fails to correctly apply syntax highlighting in certain documents that contain JSX and a templated string.

Here is a screenshot of a minimal example that showcases this:

Screenshot 2024-03-29 at 7 07 33 PM

Strangely, when you remove just one line (line 6 which contains the last destructured variable) the above example no longer reproduces:

Screenshot 2024-03-29 at 7 07 47 PM

Not entirely sure what causes this and in exactly which scenarios but this reproduces pretty consistently for documents like the above.

Browser and platform

latest MacOS, Firefox (but should repro in all)

Reproduction link

https://replit.com/@SergeiChestakov/cm-tsx-highlight-bug

marijnh commented 6 months ago

I wasn't aware you could use destructured parameters in function type signatures. That's a lot of ambiguity for little use, but indeed, it looks like TypeScript parses it. Attached patch adds support to @lezer/javascript.