tree-sitter / tree-sitter-javascript

Javascript grammar for tree-sitter
MIT License
323 stars 109 forks source link

node.parent has implicit side-effects #127

Closed sguillia closed 4 years ago

sguillia commented 4 years ago

Hi

I am encountering hard-to-debug bugs.

Sometimes, node.parent is undefined while the node actually has a parent. This happens only on leaf nodes that were accessed with a cursor.

Sometimes, reading node.parent has side-effects.

void (cursor.currentNode.parent)

This statement is supposed to do nothing right? Well, if I comment it out, tree-sitter is giving me another tree! It's giving me nodes of type _expression that disappear when uncommenting the statement.

I am having this in a large codebase. I will try to make a minimal reproducible examples but I probably won't be able to do it soon. I opended this issue just wondering if this problem is known. You can close it meanwhile if you want.

Many thanks

maxbrunsfeld commented 4 years ago

Are you using web-tree-sitter or node-tree-sitter?

This issue was not known to me already. A minimal reproduction would allow me to fix it much more quickly, but I can understand how that may take time for you to set up. Thanks for the report, and apologies for the bug.

sguillia commented 4 years ago

No problem, I'm already glad this project exists!

I am using node-tree-sitter. Indeed, this issue might belong more to the binding than to the grammar.

maxbrunsfeld commented 4 years ago

Closing this out since the bug in the core library is fixed. I'll leave https://github.com/tree-sitter/node-tree-sitter/issues/61 open until a new node-tree-sitter version is published.

sguillia commented 4 years ago

@maxbrunsfeld The bug is indeed fixed, thank you!

If you ever want an example to reproduce the implicit side-effects, before 0.16.1, here you are. https://github.com/sguillia/tree-sitter-ub

(wish I had seen your message before)