| 2398 | } |
| 2399 | |
| 2400 | pub(super) fn extract_instantiation(&mut self, node: Node<'t>) { |
| 2401 | if self.stack.is_empty() { |
| 2402 | return; |
| 2403 | } |
| 2404 | let ctor = node |
| 2405 | .child_by_field_name("constructor") |
| 2406 | .or_else(|| node.child_by_field_name("type")) |
| 2407 | .or_else(|| node.child_by_field_name("name")) |
| 2408 | .or_else(|| node.named_child(0)); |
| 2409 | let Some(ctor) = ctor else { return }; |
| 2410 | |
| 2411 | let mut class_name = self.text(ctor).to_string(); |
| 2412 | // `new Map<K, V>()` → Map. |
| 2413 | if let Some(lt) = class_name.find('<') { |
| 2414 | if lt > 0 { |
| 2415 | class_name.truncate(lt); |
| 2416 | } |
| 2417 | } |
| 2418 | // `new ns.Foo()` → Foo. |
| 2419 | let last_dot = class_name |
| 2420 | .rfind('.') |
| 2421 | .map(|i| i as isize) |
| 2422 | .unwrap_or(-1) |
| 2423 | .max(class_name.rfind("::").map(|i| i as isize).unwrap_or(-1)); |
| 2424 | if last_dot >= 0 { |
| 2425 | class_name = class_name[(last_dot as usize + 1)..].to_string(); |
| 2426 | // TS: .replace(/^[:.]/, '') — one leading colon-or-dot. |
| 2427 | if class_name.starts_with(':') || class_name.starts_with('.') { |
| 2428 | class_name.remove(0); |
| 2429 | } |
| 2430 | } |
| 2431 | let class_name = class_name.trim().to_string(); |
| 2432 | if !class_name.is_empty() { |
| 2433 | let from = self.top_row(); |
| 2434 | self.push_ref(from, &class_name, edge_kind_index("instantiates").unwrap(), node); |
| 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | // --- extractDecoratorsFor -------------------------------------------------------------- |
| 2439 | |