feat(rust): ensure span uniqueness of oxc AST#1927
Conversation
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
✅ Deploy Preview for rolldown-rs canceled.
|
Benchmarks Rust |
| use rustc_hash::FxHashSet; | ||
|
|
||
| /// Make sure there aren't any duplicate spans in the AST. | ||
| pub struct EnsureSpanUniqueness { |
There was a problem hiding this comment.
Maybe rename to EnsureModuleDeclarationSpanUniqueness?
There was a problem hiding this comment.
It's not just for ModuleDeclarations. Other nodes type would be added after oxc-project/oxc#4799.
|
A few thoughts:
fn ensure_uniqueness(&mut self, span: &mut Span) {
// `span.start == span.end` will be false for all real spans,
// and equality check is much cheaper than hashmap lookup
if span.start == span.end && self.visited_span_starts.contains(span.start) {
*span = self.generate_unique_span();
self.visited_span_starts.insert(span.start);
}
}
|
There are other parts need this too, including
Nope. We need to make sure all AST nodes don't have duplicate span. When I say "all AST nodes" it means almost all AST nodes, since we care about |
|
Ah ha. Thanks for explaining. What
Out of interest, how is it possible for 2 AST nodes to have same span if they are "real" spans i.e. from Oxc parser? Is this something that can happen when you combine two ASTs into one? Sorry for "noob" questions. I have very little knowledge of Rolldown, but would like to gain some! |
After oxc transform (or any custom transform), the newly added |
#1818 (comment). We will resolve |

Description
Rolldown uses
Spanas the way to indentify AST ndoes. Now theinjectfeature would generate improt statements with empty Span. They might be duplicated, we need ensure it's uniqueness.Contexts:
Spanof module declarations #1875