lezer-parser / lezer

Dev utils and issues for the Lezer core packages
34 stars 1 forks source link

TreeCursor.iterate continues iterating over sibling nodes #60

Closed peaffenzeller closed 1 week ago

peaffenzeller commented 1 week ago

The docs for TreeCursor.iterate say

Iterate over the current node and all its descendants, [...]

That would suggest, that siblings of a node are not included when iterating, only its children. But when I create a new cursor for a given node and call iterate on it, it continues iterating also over sibling nodes, see this example.

the new cursor used to iterate over the VariableDeclaration logs both const a = 1 and const b = 2, even though - according to the docs - it should stop after its last child.

marijnh commented 1 week ago

That was indeed a bug. Attached patch should fix it.

JClackett commented 1 day ago

Think this has caused a regression, getting: TypeError: undefined is not an object (evaluating 'children.length') now

marijnh commented 1 day ago

I suspect you upgraded incorrectly, and have duplicated @lezer packages in your node_modules.

JClackett commented 1 day ago

im using codemirror which depends on lezer apparantly, so dont have lezer in my package json. Reverting to 1.2.2 has solved for now :)

marijnh commented 1 day ago

yarn upgrade (or npm upgrade in old npm versions) will duplicate some dependencies that are depended on in multiple ways, leading to, for example, instanceof becoming unreliable because classes are loaded multiple times.

JClackett commented 17 hours ago

Sorry im not really sure what you mean, if I look in my lock file after my app started crashing, I see that this package was updated to 1.2.3, so if I set the resolutions property to keep lezer at 1.2.2 it fixes my issues. The stack trace of the error leads back to this package causing the error. Is that not an issue with this package then?

marijnh commented 16 hours ago

In the broken state, what does npm ls -a | grep @lezer give?

JClackett commented 16 hours ago

hmm yeah, actually, if I set the resolutions to 1.2.3 it works as well, so for some reason my lock file changed and there was a broken version or something weird happening?