Skip to content

Commit

Permalink
Make sure nodes aren't returned multiple times from stack iterators
Browse files Browse the repository at this point in the history
FIX: Fix a bug where `resolveStack` could sometimes yield the same node multiple
times.
  • Loading branch information
marijnh committed Sep 19, 2023
1 parent 661c1fe commit 280117f
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1013,8 +1013,6 @@ class BufferNode extends BaseNode {

function iterStack(heads: readonly SyntaxNode[]): NodeIterator | null {
if (!heads.length) return null
if (heads.length == 1) return heads[0] as any

let pick = 0, picked = heads[0]
for (let i = 1; i < heads.length; i++) {
let node = heads[i]
Expand Down Expand Up @@ -1045,7 +1043,7 @@ function stackIterator(tree: Tree, pos: number, side: -1 | 0 | 1): NodeIterator
let mount = MountedTree.get(scan.tree)
// Relevant overlay branching off
if (mount && mount.overlay && mount.overlay[0].from <= pos && mount.overlay[mount.overlay.length - 1].to >= pos) {
let root = new TreeNode(mount.tree, mount.overlay[0].from + scan.from, 0, scan)
let root = new TreeNode(mount.tree, mount.overlay[0].from + scan.from, -1, scan)
;(layers || (layers = [inner])).push(resolveNode(root, pos, side, false))
}
}
Expand Down

0 comments on commit 280117f

Please sign in to comment.