pub(crate) struct Scope<'a> {Show 23 fields
parent: Option<&'a Scope<'a>>,
kind: ScopeKind,
pub declaring: Vec<Id>,
pub declaring_parameters: Vec<Id>,
pub declared_return_type: Option<Type>,
pub declaring_type_params: FxHashSet<Id>,
pub(super) vars: FxHashMap<Id, VarInfo>,
types: FxHashMap<Id, Type>,
pub(super) facts: CondFacts,
pub(super) declaring_fn: Option<Id>,
pub(super) declaring_prop: Option<Id>,
pub(super) this: Option<Type>,
pub(super) this_class_name: Option<Id>,
pub(super) this_class_members: Vec<(usize, ClassMember)>,
pub(super) this_object_members: Vec<TypeElement>,
pub(super) super_class: Option<Box<Type>>,
pub(super) return_values: ReturnValues,
expand_triage_depth: u8,
pub(super) is_call_arg_count_unknown: bool,
pub(super) type_params: FxHashMap<Id, Type>,
pub(super) cur_module_name: Option<Id>,
pub(super) class: ClassState,
pub(super) destructure_vars: FxHashMap<DestructureId, Type>,
}
Fields
parent: Option<&'a Scope<'a>>
kind: ScopeKind
declaring: Vec<Id>
declaring_parameters: Vec<Id>
declared_return_type: Option<Type>
declaring_type_params: FxHashSet<Id>
vars: FxHashMap<Id, VarInfo>
types: FxHashMap<Id, Type>
facts: CondFacts
declaring_fn: Option<Id>
declaring_prop: Option<Id>
Some while declaring a class property or a property of an object literal.
this: Option<Type>
this_class_name: Option<Id>
Used while validating super class and static class properties. Otherwise None.
Required to handle static properties.
this_class_members: Vec<(usize, ClassMember)>
Only contains instance members.
The value of usize should be ignored by methods except
Validate<Class>
this_object_members: Vec<TypeElement>
super_class: Option<Box<Type>>
return_values: ReturnValues
expand_triage_depth: u8
0
if we are not trying to expand it.
is_call_arg_count_unknown: bool
Used to handle ...any
in calls.
type_params: FxHashMap<Id, Type>
cur_module_name: Option<Id>
If two modules have same name, the latter can reference exported members from other modules.
It means we need a way to know which module we are in, and this field is used to store module name.
class: ClassState
All states related to validation of a class.
destructure_vars: FxHashMap<DestructureId, Type>
Save All destructure state
Implementations
sourceimpl Scope<'_>
impl Scope<'_>
pub fn parent(&self) -> Option<&Self>
pub fn first<F>(&self, filter: F) -> Option<&Self>where
F: FnMut(&Scope<'_>) -> bool,
pub fn first_kind<F>(&self, filter: F) -> Option<&Self>where
F: FnMut(ScopeKind) -> bool,
sourcepub fn matches<F>(&self, filter: F) -> Option<bool>where
F: FnMut(&Self) -> Option<bool>,
pub fn matches<F>(&self, filter: F) -> Option<bool>where
F: FnMut(&Self) -> Option<bool>,
If filter
returns Some, this method returns it.
sourcepub fn matches_kind<F>(&self, filter: F) -> Option<bool>where
F: FnMut(ScopeKind) -> Option<bool>,
pub fn matches_kind<F>(&self, filter: F) -> Option<bool>where
F: FnMut(ScopeKind) -> Option<bool>,
If filter
returns Some, this method returns it.
pub fn is_arguments_implicitly_defined(&self) -> bool
pub fn is_declaring(&self, id: &Id) -> bool
pub fn can_access_declaring_regardless_of_context(&self, id: &Id) -> bool
sourcepub fn scope_of_computed_props(&self) -> Option<&Self>
pub fn scope_of_computed_props(&self) -> Option<&Self>
Get scope of computed property names.
fn scope_of_computed_props_inner(&self) -> Option<&Self>
pub fn get_type_facts(&self, name: &Name) -> TypeFacts
pub fn is_declaring_fn(&self, id: &Id) -> bool
pub fn get_this_class_name(&self) -> Option<Id>
pub fn declaring_prop(&self) -> Option<Id>
pub(crate) fn is_this_defined(&self) -> bool
pub fn is_root(&self) -> bool
pub fn is_module(&self) -> bool
sourcepub fn should_store_type_params(&self) -> bool
pub fn should_store_type_params(&self) -> bool
Returns true
if a scope exists for storing
pub fn is_in_call(&self) -> bool
pub fn is_in_loop_body(&self) -> bool
pub fn store_type_param(&mut self, name: Id, ty: Type)
sourcepub fn class_members(&self) -> &[(usize, ClassMember)]
pub fn class_members(&self) -> &[(usize, ClassMember)]
Get members of current class.
sourcepub fn object_lit_members(&self) -> &[TypeElement]
pub fn object_lit_members(&self) -> &[TypeElement]
Get members of the current object literal.
pub fn get_super_class(&self, is_static: bool) -> Option<Type>
pub fn remove_parent(self) -> Scope<'static>
pub fn current_module_name(&self) -> Option<Id>
pub fn move_types_from_child(&mut self, child: &mut Scope<'_>)
pub fn move_vars_from_child(&mut self, child: &mut Scope<'_>)
pub fn declared_return_type(&self) -> Option<&Type>
pub fn remove_declaring<I>(
&mut self,
names: impl IntoIterator<IntoIter = I, Item = Id>
)where
I: Iterator<Item = Id> + DoubleEndedIterator,
pub fn insert_var(&mut self, name: Id, v: VarInfo)
pub fn get_type_from_name(&self, name: &Name) -> Option<Type>
sourcepub fn get_var_mut(&mut self, name: &Id) -> Option<&mut VarInfo>
pub fn get_var_mut(&mut self, name: &Id) -> Option<&mut VarInfo>
This method does not search for parent scope.
sourcefn register_type(&mut self, name: Id, ty: Type, should_override: bool)
fn register_type(&mut self, name: Id, ty: Type, should_override: bool)
Add a type to the scope.
pub fn this(&self) -> Option<Cow<'_, Type>>
pub fn this_class_name(&self) -> Option<Id>
pub fn get_var(&self, sym: &Id) -> Option<&VarInfo>
pub fn search_parent(&self, sym: &Id) -> Option<&VarInfo>
pub fn mark_as_super_called(&self)
pub fn cannot_use_this_because_super_not_called(&self) -> bool
sourceimpl<'a> Scope<'a>
impl<'a> Scope<'a>
pub const fn kind(&self) -> ScopeKind
sourcepub fn is_this_ref_to_object_lit(&self) -> bool
pub fn is_this_ref_to_object_lit(&self) -> bool
Returns true if this
(from javascript) is a reference to an object
literal.
sourcepub fn is_this_ref_to_class(&self) -> bool
pub fn is_this_ref_to_class(&self) -> bool
Returns true if this
(from javascript) is a reference to a class.