docs/adr/00004-add-ast-path-info-to-visitor.md
Currently one can't get any information about parent node.
This is due to ownership restriction of rust.
We can't pass a reference to the parent to a visitor method.
Let's say we have a CallExpr, and we are now going to call visit_mut_callee from visit_mut_call_expr.
We want &mut callee, because it's the signature of visit_mut_callee.
So we borrow it from CallExpr.
As we mutabily borrowed something from CallExpr, we cannot pass &CallExpr to visit_mut_callee.
We can workaround this by
CallExpr.calleevisit_mut_callee(&mut self, callee: &mut Callee, parent: &CallExpr), with dummy callee in parent.callee.visit_mut_call.But doing this by hand is error-prone and doing this automatically by codegen is costly.
This is explicit memmove, and memmove is quite costly.
SWC moved from Fold to VisitMut because of mmemove.
[option 1] Stay with as-is.
[option 2] Provide full information using unsafe.
[option 3] Provide small amount of information .
We will expose the spans and kinds of the parent ast nodes for VisitMut and Fold, while passing an enum with parent data for Visit.
This difference is related to the restriction above.
This is the exact problem rust is trying to solve, and we don't want to violate the rules of rust.
Chosen option: [option 3] Provide small amount of information .
This decision is taken because
unsafe in public API requires more discussion.unsafe in plugins is strongly discourages.