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: TimingDataTiming data for profiling. Accumulates across all function compilations.
debug_enabled: boolWhether debug logging is enabled (HIR formatting after each pass).
Implementations§
Source§impl ProgramContext
impl ProgramContext
pub fn new( opts: PluginOptions, filename: Option<String>, code: Option<String>, suppressions: Vec<SuppressionRange>, has_module_scope_opt_out: bool, ) -> Self
Sourcepub fn set_source_filename(&mut self, filename: Option<String>)
pub fn set_source_filename(&mut self, filename: Option<String>)
Set the source filename (from AST node loc.filename).
Sourcepub fn source_filename(&self) -> Option<String>
pub fn source_filename(&self) -> Option<String>
Get the source filename for logger events.
Sourcepub fn is_already_compiled(&self, start: u32) -> bool
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().
Sourcepub fn mark_compiled(&mut self, start: u32)
pub fn mark_compiled(&mut self, start: u32)
Mark a function at the given start position as compiled.
Sourcepub fn init_from_scope(&mut self, scope: &ScopeInfo)
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.
Sourcepub fn has_reference(&self, name: &str) -> bool
pub fn has_reference(&self, name: &str) -> bool
Check if a name conflicts with known references.
Sourcepub fn new_uid(&mut self, name: &str) -> String
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.
Sourcepub fn add_memo_cache_import(&mut self) -> NonLocalImportSpecifier
pub fn add_memo_cache_import(&mut self) -> NonLocalImportSpecifier
Add the memo cache import (the c function from the compiler runtime).
Sourcepub fn add_import_specifier(
&mut self,
module: &str,
specifier: &str,
name_hint: Option<&str>,
) -> NonLocalImportSpecifier
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.
Sourcepub fn add_new_reference(&mut self, name: String)
pub fn add_new_reference(&mut self, name: String)
Register a name as referenced so future uid generation avoids it.
Sourcepub fn known_referenced_names(&self) -> &HashSet<String>
pub fn known_referenced_names(&self) -> &HashSet<String>
Get the set of known referenced names for seeding per-function Environment UID generation.
Sourcepub fn merge_uid_known_names(&mut self, names: &HashSet<String>)
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.
Sourcepub fn log_event(&mut self, event: LoggerEvent)
pub fn log_event(&mut self, event: LoggerEvent)
Log a compilation event.
Sourcepub fn log_debug(&mut self, entry: DebugLogEntry)
pub fn log_debug(&mut self, entry: DebugLogEntry)
Log a debug entry (for debugLogIRs support).
Sourcepub fn has_pending_imports(&self) -> bool
pub fn has_pending_imports(&self) -> bool
Check if there are any pending imports to add to the program.