tree-sitter / tree-sitter-javascript

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

Incomplete variable declaration before return statement causes incorrect tree linkage (node is own uncle) #186

Closed gushogg-blake closed 4 months ago

gushogg-blake commented 2 years ago

With the following code, I'm seeing a zero-length node of type ; that is its own parent's parent's next sibling:

function a() {
    let
    return {}
}

I ran into an infinite loop when trying to traverse this tree. After processing an identifier node for the return keyword, it doesn't have a nextSibling so we go to its parent which is a variable_declarator. The next sibling of the variable_declarator is the zero-length semicolon node, so that's the next logical node to process. After processing that node, it doesn't have a next sibling so we go to its parent, which is the original identifier. There are other inconsistencies associated with this, e.g. the identifier node has a childCount of 0 even though it has nodes that point to it via parent.

amaanq commented 4 months ago

It'd be nice if you can check if this is still an issue (there's been a plethora of changes here and in tree-sitter core since this issue), if it is then I'd like to investigate it more - thanks!

gushogg-blake commented 4 months ago

No, looks like it's sorted, thanks!