| 1858 | } |
| 1859 | |
| 1860 | pub(super) fn extract_instantiation(&mut self, node: Node<'t>) { |
| 1861 | if self.stack.is_empty() { |
| 1862 | return; |
| 1863 | } |
| 1864 | let ctor = node |
| 1865 | .child_by_field_name("constructor") |
| 1866 | .or_else(|| node.child_by_field_name("type")) |
| 1867 | .or_else(|| node.child_by_field_name("name")) |
| 1868 | .or_else(|| node.named_child(0)); |
| 1869 | let Some(ctor) = ctor else { return }; |
| 1870 | |
| 1871 | let mut class_name = self.text(ctor).to_string(); |
| 1872 | // `new Map<K, V>()` → Map. |
| 1873 | if let Some(lt) = class_name.find('<') { |
| 1874 | if lt > 0 { |
| 1875 | class_name.truncate(lt); |
| 1876 | } |
| 1877 | } |
| 1878 | // `new ns.Foo()` → Foo. |
| 1879 | let last_dot = class_name |
| 1880 | .rfind('.') |
| 1881 | .map(|i| i as isize) |
| 1882 | .unwrap_or(-1) |
| 1883 | .max(class_name.rfind("::").map(|i| i as isize).unwrap_or(-1)); |
| 1884 | if last_dot >= 0 { |
| 1885 | class_name = class_name[(last_dot as usize + 1)..].to_string(); |
| 1886 | // TS: .replace(/^[:.]/, '') — one leading colon-or-dot. |
| 1887 | if class_name.starts_with(':') || class_name.starts_with('.') { |
| 1888 | class_name.remove(0); |
| 1889 | } |
| 1890 | } |
| 1891 | let class_name = class_name.trim().to_string(); |
| 1892 | if !class_name.is_empty() { |
| 1893 | let from = self.top_row(); |
| 1894 | self.push_ref(from, &class_name, edge_kind_index("instantiates").unwrap(), node); |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | // --- extractDecoratorsFor -------------------------------------------------------------- |
| 1899 | |