Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tsx parser stuck in an infinite loop #265

Closed
sebcode opened this issue Sep 29, 2023 · 11 comments · Fixed by #273
Closed

tsx parser stuck in an infinite loop #265

sebcode opened this issue Sep 29, 2023 · 11 comments · Fixed by #273
Labels

Comments

@sebcode
Copy link

sebcode commented Sep 29, 2023

tree-sitter parse gets stuck in an infinite loop with the following code:

const A = () => {
  return 1 ? (
    <div className=""></div>
  ) : 1 ? ( <div className="></div> ) : (
    <div>
      <input type="text" value={value} />
      <button disabled={a.b} autofocus={c.d} />
    </div>
  )
}

Tested with b1bf482

This related issue has a more verbose test-case: nvim-treesitter/nvim-treesitter#3550

@sebcode sebcode added the bug label Sep 29, 2023
@hendrikvanantwerpen
Copy link
Contributor

hendrikvanantwerpen commented Oct 3, 2023

I suspect that this is a problem in tree-sitter itself. Probably better to file an issue there.

@amaanq
Copy link
Member

amaanq commented Oct 3, 2023

It's an issue in the scanner

Nvm, I was thinking of another case similar to this one where the issue is in the scanner, this is not the case and is an upstream bug

@jacksonneal
Copy link

It's an issue in the scanner

Nvm, I was thinking of another case similar to this one where the issue is in the scanner, this is not the case and is an upstream bug

Did you end up filing an upstream bug or resolving the issue? I am running into issues on M1 mac where neovim freezes when opening a tsx file with treesitter highlighting enabled. An infinite loop is the only reasonable explanation I can find.

@MindsightsAI
Copy link

Any workaround of this problem ?

@amaanq
Copy link
Member

amaanq commented Jan 31, 2024

@sebcode I made a plethora of changes in the javascript parser as well as this one. Can you try it out now? If it's still stuck I'll reopen this but I'm hopeful I potentially fixed it.

@sebcode
Copy link
Author

sebcode commented Jan 31, 2024

@amaanq The tsx parser still seems to hang :(

This is how I tested:

$ git clone https://github.com/tree-sitter/tree-sitter-typescript.git
$ git rev-parse HEAD
eb6b845dee9ee22987262699a152312604313662
$ cd tree-sitter-typescript/tsx/
$ tree-sitter -V
tree-sitter 0.20.9 (1d8975319c2d5de1bf710e7e21db25b0eee4bc66)
$ cat /tmp/test.tsx 
const A = () => {
  return 1 ? (
    <div className=""></div>
  ) : 1 ? ( <div className="></div> ) : (
    <div>
      <input type="text" value={value} />
      <button disabled={a.b} autofocus={c.d} />
    </div>
  )
}
$ tree-sitter parse /tmp/test.tsx
# (hangs forever)

If I run tree-sitter parse with --debug I can see that the parser seems to be stuck in an infinite loop.

@amaanq
Copy link
Member

amaanq commented Jan 31, 2024

Sorry about that, I can still reproduce. I fixed another case I believe - I'll try and fix this as well

@amaanq
Copy link
Member

amaanq commented Jan 31, 2024

Ok, I think I've actually fixed it now, I thought I had this fix in when I made my PR, but I didn't. Mind trying master?

If you really need a release with this fix, I can see about creating one in a few days, I'd just like some more changes in before we have another release

Spoke too soon

Alright, I actually found the fix this time, I'll be updating js and ts for import attribute support and more, so hopefully in a couple hrs we'll see this actually fixed.

@amaanq
Copy link
Member

amaanq commented Feb 1, 2024

Okay @sebcode, can you try 0.20.5? :)

@sebcode
Copy link
Author

sebcode commented Feb 1, 2024

@amaanq This seems to work! Tested a few cases and nvim doesn't hang anymore. Thanks a lot!! 🥳

@wentinghome
Copy link

wentinghome commented Jul 3, 2024

Okay @sebcode, can you try 0.20.5? :)

Hi @amaanq ,I 'm running into the same error when parsing on typescript. I wonder if you can apply fix to typescript also? thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants