(&mut self, node: Node<'t>, class_row: u32)
| 2125 | // --- extractInheritance (TS/JS clauses) --------------------------------------------------- |
| 2126 | |
| 2127 | pub(super) fn extract_inheritance(&mut self, node: Node<'t>, class_row: u32) { |
| 2128 | stack_guard!(); |
| 2129 | let extends_kind = edge_kind_index("extends").unwrap(); |
| 2130 | let implements_kind = edge_kind_index("implements").unwrap(); |
| 2131 | for child in node.named_children(&mut node.walk()) { |
| 2132 | match child.kind() { |
| 2133 | // TS `extends_clause` (the other spellings are other grammars'). |
| 2134 | "extends_clause" | "superclass" | "base_clause" | "extends_interfaces" => { |
| 2135 | if let Some(target) = child.named_child(0) { |
| 2136 | let name = self.supertype_name(target); |
| 2137 | self.push_ref(class_row, &name, extends_kind, target); |
| 2138 | } |
| 2139 | } |
| 2140 | "implements_clause" | "class_interface_clause" | "super_interfaces" | "interfaces" => { |
| 2141 | for iface in child.named_children(&mut child.walk()) { |
| 2142 | let name = self.supertype_name(iface); |
| 2143 | self.push_ref(class_row, &name, implements_kind, iface); |
| 2144 | } |
| 2145 | } |
| 2146 | // TS `interface Repo<T> extends Base, ns.Shape, Store<T>` — each |
| 2147 | // supertype is a `type` of the clause; a `generic_type` is named |
| 2148 | // by its `name` field (`Store`, never `Store<T>`). |
| 2149 | "extends_type_clause" => { |
| 2150 | let mut cursor = child.walk(); |
| 2151 | let targets: Vec<Node<'t>> = child.children_by_field_name("type", &mut cursor).collect(); |
| 2152 | for target in targets { |
| 2153 | let named = if target.kind() == "generic_type" { |
| 2154 | target.child_by_field_name("name").unwrap_or(target) |
| 2155 | } else { |
| 2156 | target |
| 2157 | }; |
| 2158 | let name = self.text(named).to_string(); |
| 2159 | self.push_ref(class_row, &name, extends_kind, target); |
| 2160 | } |
| 2161 | } |
| 2162 | // JS `class Foo extends Bar` — class_heritage holds a bare |
| 2163 | // identifier without an extends_clause wrapper. |
| 2164 | "identifier" | "type_identifier" if node.kind() == "class_heritage" => { |
| 2165 | let name = self.text(child).to_string(); |
| 2166 | self.push_ref(class_row, &name, extends_kind, child); |
| 2167 | } |
| 2168 | // TS class_heritage wraps extends/implements — recurse. |
| 2169 | "field_declaration_list" | "class_heritage" => { |
| 2170 | self.extract_inheritance(child, class_row); |
| 2171 | } |
| 2172 | _ => {} |
| 2173 | } |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | /// supertypeName — a parameterized supertype (`generic_type`) by the name |
| 2178 | /// before its type arguments: `Store` for `implements Store<string>`. |
no test coverage detected