Skip to content

Bug: TokenVisitor missing visitPost breaks parent tracking #151

Description

@leogdion

Description

TokenVisitor.visitPre sets current = treeNode when entering a node, but there is no visitPost override to restore current to the parent node when leaving. After visiting a node's first child subtree, current still points to the deepest node visited, so subsequent children at the same level get incorrect parent IDs. This produces a malformed tree for any syntax node with more than one child.

Fix

Add a visitPost override that restores current to its parent:

override func visitPost(_ node: Syntax) {
    current = current?.parentNode  // or pop from a stack
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions