feat(ast_visit): add walk_children_*
methods
#12643
Draft
+3,257
−388
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.
Implementation of first suggested solution from #12641.
Split out walking children of AST nodes into separate
walk_children_*
functions. e.g.:Enter/leave scope
enter_scope
andleave_scope
calls are inwalk_children_*
, not inwalk_*
. So if you need some code to run afterenter_scope
, you'd still need to copy the code fromwalk_children_*
into yourVisit::visit_*
impl.Reason is that some AST types enter the scope late, or exit it early. e.g.:
oxc/crates/oxc_ast/src/ast/ts.rs
Lines 332 to 345 in 763a618
Therefore it's not possible to have
enter_scope
+leave_scope
calls inwalk_*
functions for all types. I think it'd be confusing if they were in somewalk_*
functions, but not in others, so have opted not to have them in anywalk_*
functions for consistency.Most AST types don't have scopes, so hopefully the
walk_children_*
functions will still be useful in majority of cases.Structs only
Only structs have
walk_children_*
functions, because once changes toAstKind
are complete (#11490), no enums will have anAstKind
. Sowalk_*
andwalk_children_*
functions would be equivalent for all enums.