pub struct ScopeInfo {
pub scopes: Vec<ScopeData>,
pub bindings: Vec<BindingData>,
pub node_to_scope: HashMap<u32, ScopeId>,
pub node_to_scope_end: HashMap<u32, u32>,
pub reference_to_binding: IndexMap<u32, BindingId>,
pub ref_node_id_to_binding: IndexMap<u32, BindingId>,
pub node_id_to_scope: HashMap<u32, ScopeId>,
pub program_scope: ScopeId,
}Expand description
Complete scope information for a program. Stored separately from the AST and linked via position-based lookup maps.
Fields§
§scopes: Vec<ScopeData>All scopes, indexed by ScopeId. scopes[id.0] gives the ScopeData for that scope.
bindings: Vec<BindingData>All bindings, indexed by BindingId. bindings[id.0] gives the BindingData.
node_to_scope: HashMap<u32, ScopeId>Maps an AST node’s start offset to the scope it creates.
NOT for identity lookups — use node_id_to_scope (via resolve_scope_for_node)
instead. Retained only for position-range containment queries
(e.g., “is reference R inside function scope S?”).
node_to_scope_end: HashMap<u32, u32>Maps an AST node’s start offset to the node’s end offset.
Parallel to node_to_scope — used for position-range containment checks.
reference_to_binding: IndexMap<u32, BindingId>DEPRECATED — retained only for Babel bridge JSON deserialization.
All backends pass empty maps; only the Babel bridge populates this.
Use ref_node_id_to_binding for all lookups and iteration.
ref_node_id_to_binding: IndexMap<u32, BindingId>Maps an identifier reference’s node-ID to the binding it resolves to. Only present for identifiers that resolve to a binding (not globals). Uses IndexMap to preserve insertion order.
node_id_to_scope: HashMap<u32, ScopeId>Maps a scope-creating AST node’s node-ID to the scope it creates.
program_scope: ScopeIdThe program-level (module) scope. Always scopes[0].
Implementations§
Source§impl ScopeInfo
impl ScopeInfo
Sourcepub fn get_binding(&self, scope_id: ScopeId, name: &str) -> Option<BindingId>
pub fn get_binding(&self, scope_id: ScopeId, name: &str) -> Option<BindingId>
Look up a binding by name starting from the given scope, walking up the parent chain. Returns None for globals.
Sourcepub fn resolve_scope_by_node_id(&self, node_id: u32) -> Option<ScopeId>
pub fn resolve_scope_by_node_id(&self, node_id: u32) -> Option<ScopeId>
Look up the scope for an AST node by its unique node ID.
Sourcepub fn resolve_scope_for_node(&self, node_id: Option<u32>) -> Option<ScopeId>
pub fn resolve_scope_for_node(&self, node_id: Option<u32>) -> Option<ScopeId>
Resolve the scope for an AST node by node_id. Returns None if node_id is None (the node has no scope entry) or if the node_id doesn’t map to any scope. This is expected for AST nodes that don’t create their own scope — e.g., a function body BlockStatement in Babel shares the function’s scope and never gets a _nodeId assigned by scope extraction.
Sourcepub fn resolve_reference_by_node_id(&self, node_id: u32) -> Option<BindingId>
pub fn resolve_reference_by_node_id(&self, node_id: u32) -> Option<BindingId>
Look up the binding for an identifier reference by its unique node ID. Returns None for globals/unresolved references.
Sourcepub fn resolve_reference_id_for_node(
&self,
node_id: Option<u32>,
) -> Option<BindingId>
pub fn resolve_reference_id_for_node( &self, node_id: Option<u32>, ) -> Option<BindingId>
Resolve the binding for an identifier by node_id. Returns None if node_id is None or if the identifier doesn’t resolve to a binding (i.e., it’s a global/unresolved reference).
Sourcepub fn resolve_reference_for_node(
&self,
node_id: Option<u32>,
) -> Option<&BindingData>
pub fn resolve_reference_for_node( &self, node_id: Option<u32>, ) -> Option<&BindingData>
Resolve the binding for an identifier by node_id. Returns None if node_id is None or if the identifier doesn’t resolve to a binding (i.e., it’s a global/unresolved reference).
Sourcepub fn find_binding_in_descendants(
&self,
name: &str,
ancestor: ScopeId,
) -> Option<&BindingData>
pub fn find_binding_in_descendants( &self, name: &str, ancestor: ScopeId, ) -> Option<&BindingData>
Find a binding by name within the descendants of a given scope.
Sourcepub fn find_binding_id_in_descendants(
&self,
name: &str,
ancestor: ScopeId,
) -> Option<(BindingId, &BindingData)>
pub fn find_binding_id_in_descendants( &self, name: &str, ancestor: ScopeId, ) -> Option<(BindingId, &BindingData)>
Like find_binding_in_descendants, but returns the BindingData with its id for use in resolve_binding.
Sourcepub fn scope_bindings(
&self,
scope_id: ScopeId,
) -> impl Iterator<Item = &BindingData>
pub fn scope_bindings( &self, scope_id: ScopeId, ) -> impl Iterator<Item = &BindingData>
Get all bindings declared in a scope (for hoisting iteration).
Sourcepub fn scope_bindings_with_children(
&self,
scope_id: ScopeId,
) -> impl Iterator<Item = &BindingData>
pub fn scope_bindings_with_children( &self, scope_id: ScopeId, ) -> impl Iterator<Item = &BindingData>
Get bindings from a scope AND its direct child block scopes. In Babel, a function body’s BlockStatement shares the function’s scope, so all bindings (var, const, let) appear in one scope. But our scope extraction may split them: function scope has params/var, a child block scope has const/let. This method merges them to match TS behavior.
Sourcepub fn find_block_scope_by_bindings(
&self,
names: &[&str],
ancestor: ScopeId,
is_claimed: impl Fn(ScopeId) -> bool,
) -> Option<ScopeId>
pub fn find_block_scope_by_bindings( &self, names: &[&str], ancestor: ScopeId, is_claimed: impl Fn(ScopeId) -> bool, ) -> Option<ScopeId>
Find a block scope by matching variable names declared within it.
Used for synthetic blocks (position 0) where position-based lookup fails.
The is_claimed predicate allows skipping scopes already matched to other blocks.