| 2011 | } |
| 2012 | |
| 2013 | pub(super) fn extract_instantiation(&mut self, node: Node<'t>) { |
| 2014 | if self.stack.is_empty() { |
| 2015 | return; |
| 2016 | } |
| 2017 | let ctor = node |
| 2018 | .child_by_field_name("constructor") |
| 2019 | .or_else(|| node.child_by_field_name("type")) |
| 2020 | .or_else(|| node.child_by_field_name("name")) |
| 2021 | .or_else(|| node.named_child(0)); |
| 2022 | let Some(ctor) = ctor else { return }; |
| 2023 | |
| 2024 | let mut class_name = self.text(ctor).to_string(); |
| 2025 | // `new Map<K, V>()` → Map. |
| 2026 | if let Some(lt) = class_name.find('<') { |
| 2027 | if lt > 0 { |
| 2028 | class_name.truncate(lt); |
| 2029 | } |
| 2030 | } |
| 2031 | // `new ns.Foo()` → Foo. |
| 2032 | let last_dot = class_name |
| 2033 | .rfind('.') |
| 2034 | .map(|i| i as isize) |
| 2035 | .unwrap_or(-1) |
| 2036 | .max(class_name.rfind("::").map(|i| i as isize).unwrap_or(-1)); |
| 2037 | if last_dot >= 0 { |
| 2038 | class_name = class_name[(last_dot as usize + 1)..].to_string(); |
| 2039 | // TS: .replace(/^[:.]/, '') — one leading colon-or-dot. |
| 2040 | if class_name.starts_with(':') || class_name.starts_with('.') { |
| 2041 | class_name.remove(0); |
| 2042 | } |
| 2043 | } |
| 2044 | let class_name = class_name.trim().to_string(); |
| 2045 | if !class_name.is_empty() { |
| 2046 | let from = self.top_row(); |
| 2047 | self.push_ref(from, &class_name, edge_kind_index("instantiates").unwrap(), node); |
| 2048 | } |
| 2049 | } |
| 2050 | |
| 2051 | // --- extractDecoratorsFor -------------------------------------------------------------- |
| 2052 | |