Skip to main content

ProgramContext

Struct ProgramContext 

Source
pub struct ProgramContext {
Show 14 fields pub opts: PluginOptions, pub filename: Option<String>, pub code: Option<String>, pub react_runtime_module: String, pub suppressions: Vec<SuppressionRange>, pub has_module_scope_opt_out: bool, pub events: Vec<LoggerEvent>, pub ordered_log: Vec<OrderedLogItem>, pub instrument_fn_name: Option<String>, pub instrument_gating_name: Option<String>, pub hook_guard_name: Option<String>, pub renames: Vec<BindingRename>, pub timing: TimingData, pub debug_enabled: bool, /* private fields */
}
Expand description

Context for the program being compiled. Tracks compiled functions, generated names, and import requirements. Equivalent to ProgramContext class in Imports.ts.

Fields§

§opts: PluginOptions§filename: Option<String>§code: Option<String>§react_runtime_module: String§suppressions: Vec<SuppressionRange>§has_module_scope_opt_out: bool§events: Vec<LoggerEvent>§ordered_log: Vec<OrderedLogItem>

Unified ordered log that interleaves events and debug entries in the order they were emitted during compilation.

§instrument_fn_name: Option<String>§instrument_gating_name: Option<String>§hook_guard_name: Option<String>§renames: Vec<BindingRename>§timing: TimingData

Timing data for profiling. Accumulates across all function compilations.

§debug_enabled: bool

Whether debug logging is enabled (HIR formatting after each pass).

Implementations§

Source§

impl ProgramContext

Source

pub fn new( opts: PluginOptions, filename: Option<String>, code: Option<String>, suppressions: Vec<SuppressionRange>, has_module_scope_opt_out: bool, ) -> Self

Source

pub fn set_source_filename(&mut self, filename: Option<String>)

Set the source filename (from AST node loc.filename).

Source

pub fn source_filename(&self) -> Option<String>

Get the source filename for logger events.

Source

pub fn is_already_compiled(&self, start: u32) -> bool

Check if a function at the given start position has already been compiled. This is a workaround for Babel not consistently respecting skip().

Source

pub fn mark_compiled(&mut self, start: u32)

Mark a function at the given start position as compiled.

Source

pub fn init_from_scope(&mut self, scope: &ScopeInfo)

Initialize known referenced names from scope bindings. Call this after construction to seed conflict detection with program scope bindings.

Source

pub fn has_reference(&self, name: &str) -> bool

Check if a name conflicts with known references.

Source

pub fn new_uid(&mut self, name: &str) -> String

Generate a unique identifier name that doesn’t conflict with existing bindings.

For hook names (use*), preserves the original name to avoid breaking hook-name-based type inference. For other names, prefixes with underscore similar to Babel’s generateUid.

Source

pub fn add_memo_cache_import(&mut self) -> NonLocalImportSpecifier

Add the memo cache import (the c function from the compiler runtime).

Source

pub fn add_import_specifier( &mut self, module: &str, specifier: &str, name_hint: Option<&str>, ) -> NonLocalImportSpecifier

Add an import specifier, reusing an existing one if it was already added.

If name_hint is provided, it will be used as the basis for the local name; otherwise specifier is used.

Source

pub fn add_new_reference(&mut self, name: String)

Register a name as referenced so future uid generation avoids it.

Source

pub fn known_referenced_names(&self) -> &HashSet<String>

Get the set of known referenced names for seeding per-function Environment UID generation.

Source

pub fn merge_uid_known_names(&mut self, names: &HashSet<String>)

Merge UID names generated during a function compilation back into the program context, so subsequent function compilations avoid collisions.

Source

pub fn log_event(&mut self, event: LoggerEvent)

Log a compilation event.

Source

pub fn log_debug(&mut self, entry: DebugLogEntry)

Log a debug entry (for debugLogIRs support).

Source

pub fn has_pending_imports(&self) -> bool

Check if there are any pending imports to add to the program.

Source

pub fn imports( &self, ) -> &HashMap<String, HashMap<String, NonLocalImportSpecifier>>

Get an immutable view of the generated imports.

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.