Skip to content

Introduce span_mut for GetSpan #4606

@hyf0

Description

@hyf0

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory - New feature or request

    Type

    No type

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions