oxc-project / backlog

backlog for collborators only
1 stars 0 forks source link

`TraverseAncestry::current_address` to get address of current node #140

Open overlookmotel opened 1 month ago

overlookmotel commented 1 month ago

See: https://github.com/oxc-project/oxc/pull/6881#discussion_r1816560516

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:

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:

  1. Live with it. or
  2. 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).