pub struct Environment {Show 21 fields
pub next_block_id_counter: u32,
pub next_scope_id_counter: u32,
pub identifiers: Vec<Identifier>,
pub types: Vec<Type>,
pub scopes: Vec<ReactiveScope>,
pub functions: Vec<HirFunction>,
pub errors: CompilerError,
pub fn_type: ReactFunctionType,
pub output_mode: OutputMode,
pub code: Option<String>,
pub filename: Option<String>,
pub instrument_fn_name: Option<String>,
pub instrument_gating_name: Option<String>,
pub hook_guard_name: Option<String>,
pub renames: Vec<BindingRename>,
pub reference_node_ids: HashSet<u32>,
pub validate_preserve_existing_memoization_guarantees: bool,
pub validate_no_set_state_in_render: bool,
pub enable_preserve_existing_memoization_guarantees: bool,
pub shapes: ShapeRegistry,
pub config: EnvironmentConfig,
/* private fields */
}Fields§
§next_block_id_counter: u32§next_scope_id_counter: u32§identifiers: Vec<Identifier>§types: Vec<Type>§scopes: Vec<ReactiveScope>§functions: Vec<HirFunction>§errors: CompilerError§fn_type: ReactFunctionType§output_mode: OutputMode§code: Option<String>§filename: Option<String>§instrument_fn_name: Option<String>§instrument_gating_name: Option<String>§hook_guard_name: Option<String>§renames: Vec<BindingRename>§reference_node_ids: HashSet<u32>§validate_preserve_existing_memoization_guarantees: bool§validate_no_set_state_in_render: bool§enable_preserve_existing_memoization_guarantees: bool§shapes: ShapeRegistry§config: EnvironmentConfigImplementations§
Source§impl Environment
impl Environment
pub fn new() -> Self
Sourcepub fn with_config(config: EnvironmentConfig) -> Self
pub fn with_config(config: EnvironmentConfig) -> Self
Create a new Environment with the given configuration.
Initializes the shape and global registries, registers custom hooks, and sets up the module type cache.
Sourcepub fn for_outlined_fn(&self, fn_type: ReactFunctionType) -> Self
pub fn for_outlined_fn(&self, fn_type: ReactFunctionType) -> Self
Create a child Environment for compiling an outlined function.
The child shares the same config, globals, and shapes, and receives copies of all arenas (identifiers, types, scopes, functions) so that references from the outlined HIR remain valid. Block/scope counters start past the cloned data to avoid ID conflicts.
pub fn next_block_id(&mut self) -> BlockId
Sourcepub fn new_mutable_range(
&mut self,
start: EvaluationOrder,
end: EvaluationOrder,
) -> MutableRange
pub fn new_mutable_range( &mut self, start: EvaluationOrder, end: EvaluationOrder, ) -> MutableRange
Create a new MutableRange with a unique ID.
Use this when creating a logically new range (not copying an existing one).
To copy a range preserving its identity, use .clone() instead.
Sourcepub fn next_identifier_id(&mut self) -> IdentifierId
pub fn next_identifier_id(&mut self) -> IdentifierId
Allocate a new Identifier in the arena with default values, returns its IdentifierId.
Sourcepub fn next_scope_id(&mut self) -> ScopeId
pub fn next_scope_id(&mut self) -> ScopeId
Allocate a new ReactiveScope in the arena, returns its ScopeId.
Sourcepub fn next_type_id(&mut self) -> TypeId
pub fn next_type_id(&mut self) -> TypeId
Allocate a new Type in the arena, returns its TypeId.
Sourcepub fn make_type(&mut self) -> TypeId
pub fn make_type(&mut self) -> TypeId
Allocate a new Type (TypeVar) in the arena, returns its TypeId.
pub fn add_function(&mut self, func: HirFunction) -> FunctionId
pub fn record_error( &mut self, detail: CompilerErrorDetail, ) -> Result<(), CompilerError>
pub fn record_diagnostic(&mut self, diagnostic: CompilerDiagnostic)
pub fn has_errors(&self) -> bool
pub fn error_count(&self) -> usize
Sourcepub fn has_invariant_errors(&self) -> bool
pub fn has_invariant_errors(&self) -> bool
Check if any recorded errors have Invariant category. In TS, Invariant errors throw immediately from recordError(), which aborts the current operation.
pub fn errors(&self) -> &CompilerError
pub fn take_errors(&mut self) -> CompilerError
Sourcepub fn take_errors_since(&mut self, since_count: usize) -> CompilerError
pub fn take_errors_since(&mut self, since_count: usize) -> CompilerError
Take errors added after position since_count, leaving earlier errors in place.
Used to detect new errors added by a specific pass.
Sourcepub fn take_invariant_errors(&mut self) -> CompilerError
pub fn take_invariant_errors(&mut self) -> CompilerError
Take only the Invariant errors, leaving non-Invariant errors in place. In TS, Invariant errors throw as a separate CompilerError, so only the Invariant error is surfaced.
Sourcepub fn has_todo_errors(&self) -> bool
pub fn has_todo_errors(&self) -> bool
Check if any recorded errors have Todo category. In TS, Todo errors throw immediately via CompilerError.throwTodo().
Sourcepub fn take_thrown_errors(&mut self) -> CompilerError
pub fn take_thrown_errors(&mut self) -> CompilerError
Take errors that would have been thrown in TS (Invariant and Todo), leaving other accumulated errors in place.
Sourcepub fn is_hoisted_identifier(&self, binding_id: u32) -> bool
pub fn is_hoisted_identifier(&self, binding_id: u32) -> bool
Check if a binding has been hoisted (via DeclareContext) already.
Sourcepub fn add_hoisted_identifier(&mut self, binding_id: u32)
pub fn add_hoisted_identifier(&mut self, binding_id: u32)
Mark a binding as hoisted.
Sourcepub fn get_global_declaration(
&mut self,
binding: &NonLocalBinding,
loc: Option<SourceLocation>,
) -> Result<Option<Global>, CompilerError>
pub fn get_global_declaration( &mut self, binding: &NonLocalBinding, loc: Option<SourceLocation>, ) -> Result<Option<Global>, CompilerError>
Resolve a non-local binding to its type. Ported from TS getGlobalDeclaration.
The loc parameter is used for error diagnostics when validating module type
configurations. Pass None if no source location is available.
Sourcepub fn get_property_type(
&mut self,
receiver: &Type,
property: &str,
) -> Result<Option<Type>, CompilerDiagnostic>
pub fn get_property_type( &mut self, receiver: &Type, property: &str, ) -> Result<Option<Type>, CompilerDiagnostic>
Get the type of a named property on a receiver type.
Ported from TS getPropertyType.
Sourcepub fn get_property_type_numeric(
&self,
receiver: &Type,
) -> Result<Option<Type>, CompilerDiagnostic>
pub fn get_property_type_numeric( &self, receiver: &Type, ) -> Result<Option<Type>, CompilerDiagnostic>
Get the type of a numeric property on a receiver type.
Ported from the numeric branch of TS getPropertyType.
Sourcepub fn get_fallthrough_property_type(
&self,
receiver: &Type,
) -> Result<Option<Type>, CompilerDiagnostic>
pub fn get_fallthrough_property_type( &self, receiver: &Type, ) -> Result<Option<Type>, CompilerDiagnostic>
Get the fallthrough (wildcard *) property type for computed property access.
Ported from TS getFallthroughPropertyType.
Sourcepub fn get_function_signature(
&self,
ty: &Type,
) -> Result<Option<&FunctionSignature>, CompilerDiagnostic>
pub fn get_function_signature( &self, ty: &Type, ) -> Result<Option<&FunctionSignature>, CompilerDiagnostic>
Get the function signature for a function type.
Ported from TS getFunctionSignature.
Sourcepub fn get_hook_kind_for_type(
&self,
ty: &Type,
) -> Result<Option<&HookKind>, CompilerDiagnostic>
pub fn get_hook_kind_for_type( &self, ty: &Type, ) -> Result<Option<&HookKind>, CompilerDiagnostic>
Get the hook kind for a type, if it represents a hook.
Ported from TS getHookKindForType in HIR.ts.
Sourcepub fn get_custom_hook_type_opt(&mut self) -> Option<Global>
pub fn get_custom_hook_type_opt(&mut self) -> Option<Global>
Public accessor for the custom hook type, used by InferTypes for property resolution fallback when a property name looks like a hook.
Sourcepub fn shapes(&self) -> &ShapeRegistry
pub fn shapes(&self) -> &ShapeRegistry
Get a reference to the shapes registry.
Sourcepub fn globals(&self) -> &GlobalRegistry
pub fn globals(&self) -> &GlobalRegistry
Get a reference to the globals registry.
Sourcepub fn generate_globally_unique_identifier_name(
&mut self,
name: Option<&str>,
) -> String
pub fn generate_globally_unique_identifier_name( &mut self, name: Option<&str>, ) -> String
Generate a globally unique identifier name, analogous to TS
generateGloballyUniqueIdentifierName which delegates to Babel’s
scope.generateUidIdentifier. Matches Babel’s naming convention:
first name is _<name>, subsequent are _<name>2, _<name>3, etc.
Also applies Babel’s toIdentifier sanitization on the input name.
Like Babel’s generateUid, checks for collisions against existing
bindings (source-level identifier names) and previously generated UIDs,
rather than using a blind counter.
Sourcepub fn seed_uid_known_names(&mut self, names: &HashSet<String>)
pub fn seed_uid_known_names(&mut self, names: &HashSet<String>)
Seed the UID known names set with external names (e.g. from ProgramContext). This ensures UID generation avoids names generated by previous function compilations, matching Babel’s behavior where the program scope accumulates all generated UIDs.
Sourcepub fn take_uid_known_names(&mut self) -> Option<HashSet<String>>
pub fn take_uid_known_names(&mut self) -> Option<HashSet<String>>
Return the UID known names accumulated during this compilation.
Sourcepub fn outline_function(
&mut self,
func: HirFunction,
fn_type: Option<ReactFunctionType>,
)
pub fn outline_function( &mut self, func: HirFunction, fn_type: Option<ReactFunctionType>, )
Record an outlined function (extracted during outlineFunctions or outlineJSX).
Corresponds to TS env.outlineFunction(fn, type).
Sourcepub fn get_outlined_functions(&self) -> &[OutlinedFunctionEntry]
pub fn get_outlined_functions(&self) -> &[OutlinedFunctionEntry]
Get the outlined functions accumulated during compilation.
Sourcepub fn take_outlined_functions(&mut self) -> Vec<OutlinedFunctionEntry>
pub fn take_outlined_functions(&mut self) -> Vec<OutlinedFunctionEntry>
Take the outlined functions, leaving the vec empty.
Sourcepub fn enable_memoization(&self) -> bool
pub fn enable_memoization(&self) -> bool
Whether memoization is enabled for this compilation.
Ported from TS get enableMemoization() in Environment.ts.
Returns true for client/lint modes, false for SSR.
Sourcepub fn enable_validations(&self) -> bool
pub fn enable_validations(&self) -> bool
Whether validations are enabled for this compilation.
Ported from TS get enableValidations() in Environment.ts.
Sourcepub fn identifier_name_for_id(&self, id: IdentifierId) -> Option<String>
pub fn identifier_name_for_id(&self, id: IdentifierId) -> Option<String>
Get the user-visible name for an identifier.
First checks the identifier’s own name. If None, looks for another
identifier with the same declaration_id that has a name. This handles
SSA identifiers that don’t carry names but share a declaration_id with
the original named identifier from lowering.
This is analogous to identifierName on Babel’s SourceLocation,
which the parser sets on every identifier node.
Sourcepub fn has_no_alias_signature(&self, identifier_id: IdentifierId) -> bool
pub fn has_no_alias_signature(&self, identifier_id: IdentifierId) -> bool
Check whether the function type for an identifier has a noAlias signature. Looks up the identifier’s type and checks its function signature.
Sourcepub fn get_hook_kind_for_id(
&self,
identifier_id: IdentifierId,
) -> Result<Option<&HookKind>, CompilerDiagnostic>
pub fn get_hook_kind_for_id( &self, identifier_id: IdentifierId, ) -> Result<Option<&HookKind>, CompilerDiagnostic>
Get the hook kind for an identifier, if its type represents a hook.
Looks up the identifier’s type and delegates to get_hook_kind_for_type.