Skip to main content

luaur_analysis/methods/
expr_or_local_get_name.rs

1use crate::records::expr_or_local::ExprOrLocal;
2use luaur_ast::functions::get_identifier::get_identifier;
3use luaur_ast::records::ast_name::AstName;
4
5impl ExprOrLocal {
6    pub fn get_name(&self) -> Option<AstName> {
7        let expr = self.get_expr();
8        if !expr.is_null() {
9            let name = get_identifier(expr);
10            if !name.value.is_null() {
11                return Some(name);
12            }
13        } else {
14            let local = self.get_local();
15            if !local.is_null() {
16                return Some(unsafe { (*local).name });
17            }
18        }
19        None
20    }
21}