luaur-analysis 0.1.3

Luau type checker and type inference (Rust).
Documentation
use crate::records::scope::Scope;
use crate::type_aliases::def_id_def::DefId;
use crate::type_aliases::type_id::TypeId;

impl Scope {
    /// `std::optional<TypeId> Scope::lookup(DefId def) const` (Scope.cpp:98-110).
    pub fn lookup_def_id(&self, def: DefId) -> Option<TypeId> {
        let mut current: Option<&Scope> = Some(self);
        while let Some(scope) = current {
            if let Some(ty) = scope.rvalue_refinements.find(&def) {
                return Some(*ty);
            }
            if let Some(ty) = scope.lvalue_types.find(&def) {
                return Some(*ty);
            }

            current = scope.parent.as_ref().map(|scoped| scoped.as_ref());
        }

        None
    }
}