Skip to main content

ScopeInfo

Struct ScopeInfo 

Source
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: ScopeId

The program-level (module) scope. Always scopes[0].

Implementations§

Source§

impl ScopeInfo

Source

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.

Source

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.

Source

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.

Source

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.

Source

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).

Source

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).

Source

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.

Source

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.

Source

pub fn scope_bindings( &self, scope_id: ScopeId, ) -> impl Iterator<Item = &BindingData>

Get all bindings declared in a scope (for hoisting iteration).

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for ScopeInfo

Source§

fn clone(&self) -> ScopeInfo

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ScopeInfo

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ScopeInfo

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ScopeInfo

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.