@@ -2,7 +2,7 @@ use std::hash::BuildHasherDefault;
2
2
3
3
use indexmap:: IndexMap ;
4
4
use oxc_index:: IndexVec ;
5
- use oxc_span:: CompactStr ;
5
+ use oxc_span:: { Atom , CompactStr } ;
6
6
pub use oxc_syntax:: scope:: { ScopeFlags , ScopeId } ;
7
7
use rustc_hash:: { FxHashMap , FxHasher } ;
8
8
@@ -11,13 +11,13 @@ use crate::{reference::ReferenceId, symbol::SymbolId, AstNodeId};
11
11
type FxIndexMap < K , V > = IndexMap < K , V , BuildHasherDefault < FxHasher > > ;
12
12
13
13
type Bindings = FxIndexMap < CompactStr , SymbolId > ;
14
- type UnresolvedReferences = FxHashMap < CompactStr , Vec < ReferenceId > > ;
14
+ type UnresolvedReferences < ' a > = FxHashMap < Atom < ' a > , Vec < ReferenceId > > ;
15
15
16
16
/// Scope Tree
17
17
///
18
18
/// `SoA` (Struct of Arrays) for memory efficiency.
19
19
#[ derive( Debug , Default ) ]
20
- pub struct ScopeTree {
20
+ pub struct ScopeTree < ' a > {
21
21
/// Maps a scope to the parent scope it belongs in
22
22
parent_ids : IndexVec < ScopeId , Option < ScopeId > > ,
23
23
@@ -27,10 +27,10 @@ pub struct ScopeTree {
27
27
node_ids : FxHashMap < ScopeId , AstNodeId > ,
28
28
flags : IndexVec < ScopeId , ScopeFlags > ,
29
29
bindings : IndexVec < ScopeId , Bindings > ,
30
- unresolved_references : IndexVec < ScopeId , UnresolvedReferences > ,
30
+ unresolved_references : IndexVec < ScopeId , UnresolvedReferences < ' a > > ,
31
31
}
32
32
33
- impl ScopeTree {
33
+ impl < ' a > ScopeTree < ' a > {
34
34
pub fn len ( & self ) -> usize {
35
35
self . parent_ids . len ( )
36
36
}
@@ -141,7 +141,7 @@ impl ScopeTree {
141
141
self . get_binding ( self . root_scope_id ( ) , name)
142
142
}
143
143
144
- pub fn add_root_unresolved_reference ( & mut self , name : CompactStr , reference_id : ReferenceId ) {
144
+ pub fn add_root_unresolved_reference ( & mut self , name : Atom < ' a > , reference_id : ReferenceId ) {
145
145
self . add_unresolved_reference ( self . root_scope_id ( ) , name, reference_id) ;
146
146
}
147
147
@@ -208,7 +208,7 @@ impl ScopeTree {
208
208
pub ( crate ) fn add_unresolved_reference (
209
209
& mut self ,
210
210
scope_id : ScopeId ,
211
- name : CompactStr ,
211
+ name : Atom < ' a > ,
212
212
reference_id : ReferenceId ,
213
213
) {
214
214
self . unresolved_references [ scope_id] . entry ( name) . or_default ( ) . push ( reference_id) ;
@@ -217,7 +217,7 @@ impl ScopeTree {
217
217
pub ( crate ) fn extend_unresolved_reference (
218
218
& mut self ,
219
219
scope_id : ScopeId ,
220
- name : CompactStr ,
220
+ name : Atom < ' a > ,
221
221
reference_ids : Vec < ReferenceId > ,
222
222
) {
223
223
self . unresolved_references [ scope_id] . entry ( name) . or_default ( ) . extend ( reference_ids) ;
@@ -226,7 +226,7 @@ impl ScopeTree {
226
226
pub ( crate ) fn unresolved_references_mut (
227
227
& mut self ,
228
228
scope_id : ScopeId ,
229
- ) -> & mut UnresolvedReferences {
229
+ ) -> & mut UnresolvedReferences < ' a > {
230
230
& mut self . unresolved_references [ scope_id]
231
231
}
232
232
}
0 commit comments