feat(traverse): mutation-capable traversal β MutablePath with replaceWith/remove/insert/skip/stop - #324
Merged
Merged
Conversation
β¦With/remove/insert/skip/stop and enter/exit visitors
Contributor
π€ Devin AI EngineerI'll be helping with this pull request! Here's what you should know: β I will automatically:
Note: I can only respond to comments from users who have write access to this repository. βοΈ Control Options:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Stage 2 of the AST convergence plan (constructive-planning #1323): a principled, Babel-inspired mutation API for
@pgsql/traverse, added as a newtraverse(root, visitor)entry point alongside the untouched read-onlywalk/visit.MutablePathextends the existing NodePath shape (tag / node / parent / keyPath) with the container slot (container,containerKey) that physically holds the node, enabling:replaceWith(value)β writescontainer[key] = value; the replacement's children are traversed but the visitor is not re-invoked on the replacement itself (no self-requeue β a visitor replacing a node with the same tag cannot loop)remove()β splices from array containers / deletes object fields; children not traversed; sibling array iteration stays aligned (iterators consume the net length delta reported by each visit)insertBefore(...)/insertAfter(...)β array containers only; inserted values are not visitedskip()/return falseβ skip children (same semantic aswalk)stop()β halt the whole traversal via a sharedTraversalState{enter, exit}handlers per tag plus catch-allenter/exit; exit runs post-orderTraversal is the same runtime-schema-driven walk as
walkβ tagged nodes, tag-synthesized concrete typed fields (e.g.CreatePolicyStmt.table: RangeVarstored bare), untaggedParseResult/ScanResultroots β so mutation works uniformly on both storage conventions (replaceWithtakes the value exactly as stored: tagged wrapper or bare node data). Mutating the detached root throws.Deliberately no lexical scope/binding layer β SQL object identity lives in the semantic object graph (planning #1322), not the traversal.
14 new tests in
mutate.test.ts; 40/40 green in the package.Link to Devin session: https://app.devin.ai/sessions/025fb88043964fdbb335ac5e39df2478
Requested by: @pyramation