Expose index and siblings on walk context#20109
Conversation
These are just references to other information we already have. But it does mean that we can avoid things such as: ``` let idx = ctx.parent.nodes.indexOf(node) ```
Confidence Score: 5/5Safe to merge — all changes are mechanical refactors of pre-existing lookups using information that the walk already had internally. The walk implementation correctly sets No files require special attention. Reviews (1): Last reviewed commit: "use `ctx.index` and `ctx.siblings`" | Re-trigger Greptile |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
WalkthroughThis PR extends the AST walk context to expose sibling array traversal position. Two new fields are added to 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
This PR is a small improvement of the current
walkimplementation where we will expose theindexand thesiblingson the current context.During a walk, we walk over objects that contain a
nodes: []field. Thectx.parentthat already exists is a reference to the parent node, butctx.siblingsis a reference to thectx.parent.nodes.The
ctx.indexis the index of the current node we are walking in thesiblingsarray. This way we can prevent the awkwardctx.parent?.nodes.indexOf(node)which is a bit silly because we already know the nodes we're walking and its index...The
ctx.parentcan benull, but thectx.siblingswill never benull, this can be seen in a situation like this:In the above example, the
astis a separately variable, but if this was inlined, we would run into some issues:So, this PR doesn't change much, the additional information we track is already known information that is now exposed to the caller of the
walkfunction.In this PR we did update some usages and got rid of some awkward
ctx.parent?.nodes ?? []andctx.parent.nodes.indexOf(…)usages.Test plan