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