(&mut self, node: Node<'t>)
| 627 | // --- extractProperty (#808 property-classified class fields) --------------------- |
| 628 | |
| 629 | pub(super) fn extract_property(&mut self, node: Node<'t>) -> Option<(u32, String)> { |
| 630 | let docstring = crate::docstring::preceding_docstring(node, self.src); |
| 631 | let visibility = self.visibility_of(node); |
| 632 | let is_static = Some(self.is_static(node).unwrap_or(false)); // `?? false` — always present |
| 633 | |
| 634 | let name_node = node |
| 635 | .child_by_field_name("name") |
| 636 | .or_else(|| node.child_by_field_name("property")) |
| 637 | .or_else(|| { |
| 638 | (0..node.named_child_count()) |
| 639 | .filter_map(|i| node.named_child(i)) |
| 640 | .find(|c| c.kind() == "identifier") |
| 641 | })?; |
| 642 | let name = self.text(name_node).to_string(); |
| 643 | |
| 644 | // TS/JS field definitions carry an explicit `type` field; the generic |
| 645 | // scan is for other languages (#808). A `property_signature` (an |
| 646 | // interface member, #1638) carries a `type` field and no value, so it |
| 647 | // reads the type field too: the generic scan's exclusion list covers |
| 648 | // `identifier` but not the `property_identifier` an interface member is |
| 649 | // named with, so it would stop on the name and make the signature repeat |
| 650 | // it (`counts counts`) instead of naming the type. Mirrors |
| 651 | // extractProperty's isTsJsField. |
| 652 | let is_ts_js_field = matches!( |
| 653 | node.kind(), |
| 654 | "public_field_definition" | "field_definition" | "property_signature" |
| 655 | ); |
| 656 | let type_node = if is_ts_js_field { |
| 657 | node.child_by_field_name("type") |
| 658 | } else { |
| 659 | (0..node.named_child_count()).filter_map(|i| node.named_child(i)).find(|c| { |
| 660 | !matches!( |
| 661 | c.kind(), |
| 662 | "modifier" |
| 663 | | "modifiers" |
| 664 | | "identifier" |
| 665 | | "accessor_list" |
| 666 | | "accessors" |
| 667 | | "equals_value_clause" |
| 668 | ) |
| 669 | }) |
| 670 | }; |
| 671 | let type_text = type_node.map(|t| { |
| 672 | let raw = self.text(t); |
| 673 | raw.strip_prefix(':').unwrap_or(raw).trim_start().to_string() |
| 674 | }); |
| 675 | let signature = match &type_text { |
| 676 | Some(t) => format!("{t} {name}"), |
| 677 | None => name.clone(), |
| 678 | }; |
| 679 | |
| 680 | let row = self.create_node( |
| 681 | "property", |
| 682 | &name, |
| 683 | node, |
| 684 | Extra { docstring, signature: Some(signature), visibility, is_static, ..Extra::default() }, |
| 685 | )?; |
| 686 | self.extract_decorators_for(node, row); |
no test coverage detected