From 280117f4e54412ad4f32b8abc5d68cba28f88f38 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 19 Sep 2023 17:19:40 +0200 Subject: [PATCH] Make sure nodes aren't returned multiple times from stack iterators FIX: Fix a bug where `resolveStack` could sometimes yield the same node multiple times. --- src/tree.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/tree.ts b/src/tree.ts index d229e91..b6221f3 100644 --- a/src/tree.ts +++ b/src/tree.ts @@ -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] @@ -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)) } }