(&mut self, node: Node<'t>)
| 743 | // --- the main walk (visitNode, tree-sitter.ts:936-1303) --------------- |
| 744 | |
| 745 | fn visit(&mut self, node: Node<'t>) { |
| 746 | stack_guard!(); |
| 747 | // The visitNode hook (dart.ts:144-157) — the constants branch. |
| 748 | if node.kind() == "static_final_declaration" { |
| 749 | let mut cursor = node.walk(); |
| 750 | let name_node = node.named_children(&mut cursor).find(|c| c.kind() == "identifier"); |
| 751 | if let Some(name_node) = name_node { |
| 752 | // signature = first value sibling's text, sliced to 100 |
| 753 | // UTF-16 units (a flattened chain captures just its head). |
| 754 | let signature = name_node.next_named_sibling().map(|v| { |
| 755 | let (sliced, _) = util::slice_utf16(self.text(v), 100); |
| 756 | if util::utf16_len(&sliced) >= 100 { |
| 757 | format!("= {sliced}...") |
| 758 | } else { |
| 759 | format!("= {sliced}") |
| 760 | } |
| 761 | }); |
| 762 | let name = self.text(name_node).to_string(); |
| 763 | let constant = self.create_node("constant", &name, node, Extra { signature, ..Default::default() }); |
| 764 | // The initializer is code the constant runs — its calls, |
| 765 | // instantiations, reads and the types it names (#2327) are |
| 766 | // the constant's. walkInitializer: the body walk, and the |
| 767 | // dispatcher's fn-ref scan skips what it walked. |
| 768 | if let Some(constant) = constant { |
| 769 | self.stack.push(Scope { row: constant, kind: "constant", name }); |
| 770 | self.visit_body(node); |
| 771 | self.stack.pop(); |
| 772 | return; |
| 773 | } |
| 774 | } |
| 775 | self.scan_fn_ref_subtree(node, 0); |
| 776 | return; |
| 777 | } |
| 778 | |
| 779 | // A field's or top-level variable's initializer is code its class or |
| 780 | // the file runs (neither mints a node) — the hook's |
| 781 | // `initialized_identifier` row, walked like a body (walkInitializer). |
| 782 | if node.kind() == "initialized_identifier" && self.is_field_or_top_level_entry(node) { |
| 783 | self.visit_body(node); |
| 784 | return; |
| 785 | } |
| 786 | |
| 787 | // A field's declared type is its class's (Dart fields mint no nodes); |
| 788 | // a top-level variable's is the file's (#2327). The visitNode hook's |
| 789 | // `declaration` / `program` rows (dart.ts). (Parent lookups walk down |
| 790 | // from the root, so only the node kinds that can be these positions |
| 791 | // ask for theirs.) |
| 792 | if node.kind() == "declaration" { |
| 793 | let in_body = node |
| 794 | .parent() |
| 795 | .map(|p| matches!(p.kind(), "class_body" | "extension_body" | "enum_body")) |
| 796 | .unwrap_or(false); |
| 797 | let mut cursor = node.walk(); |
| 798 | let kids: Vec<Node<'t>> = node.named_children(&mut cursor).collect(); |
| 799 | let is_field = in_body |
| 800 | && kids |
| 801 | .iter() |
| 802 | .any(|c| matches!(c.kind(), "initialized_identifier_list" | "static_final_declaration_list")); |
no test coverage detected