| 1996 | } |
| 1997 | |
| 1998 | pub(super) fn extract_instantiation(&mut self, node: Node<'t>) { |
| 1999 | if self.stack.is_empty() { |
| 2000 | return; |
| 2001 | } |
| 2002 | let ctor = node |
| 2003 | .child_by_field_name("constructor") |
| 2004 | .or_else(|| node.child_by_field_name("type")) |
| 2005 | .or_else(|| node.child_by_field_name("name")) |
| 2006 | .or_else(|| node.named_child(0)); |
| 2007 | let Some(ctor) = ctor else { return }; |
| 2008 | |
| 2009 | let mut class_name = self.text(ctor).to_string(); |
| 2010 | // `new Map<K, V>()` → Map. |
| 2011 | if let Some(lt) = class_name.find('<') { |
| 2012 | if lt > 0 { |
| 2013 | class_name.truncate(lt); |
| 2014 | } |
| 2015 | } |
| 2016 | // `new ns.Foo()` → Foo. |
| 2017 | let last_dot = class_name |
| 2018 | .rfind('.') |
| 2019 | .map(|i| i as isize) |
| 2020 | .unwrap_or(-1) |
| 2021 | .max(class_name.rfind("::").map(|i| i as isize).unwrap_or(-1)); |
| 2022 | if last_dot >= 0 { |
| 2023 | class_name = class_name[(last_dot as usize + 1)..].to_string(); |
| 2024 | // TS: .replace(/^[:.]/, '') — one leading colon-or-dot. |
| 2025 | if class_name.starts_with(':') || class_name.starts_with('.') { |
| 2026 | class_name.remove(0); |
| 2027 | } |
| 2028 | } |
| 2029 | let class_name = class_name.trim().to_string(); |
| 2030 | if !class_name.is_empty() { |
| 2031 | let from = self.top_row(); |
| 2032 | self.push_ref(from, &class_name, edge_kind_index("instantiates").unwrap(), node); |
| 2033 | } |
| 2034 | } |
| 2035 | |
| 2036 | // --- extractDecoratorsFor -------------------------------------------------------------- |
| 2037 | |