Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce span_mut for GetSpan #4606

Closed
hyf0 opened this issue Aug 2, 2024 · 1 comment · Fixed by #4609
Closed

Introduce span_mut for GetSpan #4606

hyf0 opened this issue Aug 2, 2024 · 1 comment · Fixed by #4609
Labels
C-enhancement Category - New feature or request

Comments

@hyf0
Copy link
Contributor

hyf0 commented Aug 2, 2024

There's situiation that we need turn a identifier a into various form depend on the conditions. And we want to apply the span of a to the final form. The current solution make it complex to do it.

let span_of_a = a.span;
let expr = if rewrite_to_member_expr {
  member_expr!(a, SPAN)
} else {
  a
 }
let expr = if is_callee {
  member_expr_again!(expr, SPAN)
} else {
  expr
};

expr.span = span_of_a;

You will see we have to apply the span of a in the end, otherwise the sourcemap might be wrong, which is caused by nested ast nodes have the same span. I guess this is allowed maybe? But it's doesn't generate accurate sourcemap.

@hyf0 hyf0 added the C-enhancement Category - New feature or request label Aug 2, 2024
@overlookmotel
Copy link
Collaborator

I don't see any reason why we couldn't add this, and it wouldn't be too hard to do.

rzvxa pushed a commit that referenced this issue Aug 2, 2024
Closes #4606.

Introduce `GetSpanMut` trait and implement it on all AST node types.

This has to be a separate trait, rather than adding `span_mut` method to `GetSpan` because `AstKind` implements `GetSpan`, and it only has an immutable `&` ref to AST node it contains.
@Boshen Boshen closed this as completed Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category - New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants