tree-sitter / tree-sitter-typescript

TypeScript grammar for tree-sitter
MIT License
359 stars 109 forks source link

bug: Ampersand breaks className string on tsx #279

Closed serranomorante closed 7 months ago

serranomorante commented 7 months ago

Did you check existing issues?

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

No response

Describe the bug

image

Related: this also causes neovim to freeze, see: https://github.com/nvim-treesitter/nvim-treesitter/issues/6202

Only happens on repro.tsx file but not on repro.ts file.

Ampersand should be a perfectly valid char on a className=string but it is breaking syntax highlighting.

Steps To Reproduce/Bad Parse Tree

  1. Install tsx treesitter parser
  2. Create a new file: repro.tsx
  3. Add the code snippet below
  4. See how the syntax highlighting breaks after the ampersand sign

repro.tsx

function Repro() {
  return (<div className='font-bold & bg-gray-500'>Test</div>)
}

Expected Behavior/Parse Tree

Syntax highlighting shouldn't break on *.tsx files using the tsx parser

Repro

This is valid react jsx/tsx code

function Repro() {
  return (<div className='font-bold & bg-gray-500'>Test</div>)
}
serranomorante commented 7 months ago

image

serranomorante commented 7 months ago

Opened an issue here: https://github.com/nvim-treesitter/nvim-treesitter/issues/6202 with a related bug

serranomorante commented 7 months ago

Opened an issue here: nvim-treesitter/nvim-treesitter#6202 with a related bug

From that issue:

This is a parser issue; nothing we can do here.

amaanq commented 7 months ago

although it's fixed in jsx which is where the issue lies, it's not exactly fixed here yet, i probably will update parser.c within a couple hrs here as well

serranomorante commented 7 months ago

although it's fixed in jsx which is where the issue lies, it's not exactly fixed here yet, i probably will update parser.c within a couple hrs here as well

Thank you so much! 🤗

serranomorante commented 7 months ago

although it's fixed in jsx which is where the issue lies, it's not exactly fixed here yet, i probably will update parser.c within a couple hrs here as well

Sorry for the basic question but I just realized that the fix on tree-sitter-javascript also fixes the issue here on the tree-sitter-typescript parser automatically? Then why would you need to update this repo's parser.c file?

serranomorante commented 7 months ago

jajaja I'm so sorry! my previous comment doesn't make any sense. It was because I had treesitter highlight disabled, now that I enabled it again the issue remains for typescript and tsx files.

amaanq commented 6 months ago

ok this is actually fixed in typescript as well now, sorry for forgetting to bump js

serranomorante commented 6 months ago

ok this is actually fixed in typescript as well now, sorry for forgetting to bump js

No worries! Thank you, it is working now! 👍