You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We want to avoid implementing GetAddress for &T because it's error-prone. But often in transformer you only have a &T not a &Box<T> and want to get it's address (e.g. in a visitor like exit_function).
This is legitimate because the &mut T passed into visitor function is always a reference to value in the arena.
We could achieve this by:
Pushing Ancestor to the stack of ancestors before calling enter_* and pop it after calling exit_*.
TraverseAncestry::parent return not stack.last() but 1 ancestor before it.
TraverseAncestry::ancestor return the item at index last_index - level - 1 (not last_index - level).
TraverseAncestry::ancestors skip the last item on stack.
Always push to ancestors stack in all walk_* functions (I think we skip that for leaf nodes at present).
Then existing APIs behave as they do now, but TraverseAncestry::current_address can get the address of the current node with stack.last().address().
Problem: What about visitors for enums e.g. Expression? current_address would return the address of parent node, because enums don't get an Ancestor. Either:
Live with it. or
Move pushing to ancestor stack up into the walk_* functions for enums (a bit tricky, because some nodes don't always live within an enum).
The text was updated successfully, but these errors were encountered:
`impl GetAddress for Function` was added as a hack, in the absence of another way to get the `Address` of a `&Function` (oxc-project/backlog#140).
Remove it, and use `Address:from_ptr` instead in JSX Refresh transform, which is only place using it.
Boshen
pushed a commit
to oxc-project/oxc
that referenced
this issue
Nov 19, 2024
`impl GetAddress for Function` was added as a hack, in the absence of another way to get the `Address` of a `&Function` (oxc-project/backlog#140).
Remove it, and use `Address:from_ptr` instead in JSX Refresh transform, which is only place using it.
See: oxc-project/oxc#6881 (comment)
We want to avoid implementing
GetAddress
for&T
because it's error-prone. But often in transformer you only have a&T
not a&Box<T>
and want to get it's address (e.g. in a visitor likeexit_function
).This is legitimate because the
&mut T
passed into visitor function is always a reference to value in the arena.We could achieve this by:
Ancestor
to the stack of ancestors before callingenter_*
and pop it after callingexit_*
.TraverseAncestry::parent
return notstack.last()
but 1 ancestor before it.TraverseAncestry::ancestor
return the item at indexlast_index - level - 1
(notlast_index - level
).TraverseAncestry::ancestors
skip the last item on stack.walk_*
functions (I think we skip that for leaf nodes at present).Then existing APIs behave as they do now, but
TraverseAncestry::current_address
can get the address of the current node withstack.last().address()
.Problem: What about visitors for enums e.g.
Expression
?current_address
would return the address of parent node, because enums don't get anAncestor
. Either:walk_*
functions for enums (a bit tricky, because some nodes don't always live within an enum).The text was updated successfully, but these errors were encountered: