Build const signature
(&self, declarator: &Node, source: &str)
| 1004 | |
| 1005 | /// Build const signature |
| 1006 | fn build_const_signature(&self, declarator: &Node, source: &str) -> String { |
| 1007 | let name = declarator |
| 1008 | .child_by_field_name("name") |
| 1009 | .and_then(|n| self.node_text(&n, source)) |
| 1010 | .unwrap_or_default(); |
| 1011 | |
| 1012 | // Get type annotation if present |
| 1013 | let type_ann = declarator |
| 1014 | .child_by_field_name("type") |
| 1015 | .map(|t| self.node_text(&t, source).unwrap_or_default()) |
| 1016 | .unwrap_or_default(); |
| 1017 | |
| 1018 | // Get a short preview of the value (first 50 chars) |
| 1019 | let value = declarator |
| 1020 | .child_by_field_name("value") |
| 1021 | .map(|v| { |
| 1022 | let text = self.node_text(&v, source).unwrap_or_default(); |
| 1023 | if text.len() > 50 { |
| 1024 | let end = truncate_to_char_boundary(&text, 50); |
| 1025 | format!("{}...", &text[..end]) |
| 1026 | } else { |
| 1027 | text |
| 1028 | } |
| 1029 | }) |
| 1030 | .unwrap_or_default(); |
| 1031 | |
| 1032 | if type_ann.is_empty() { |
| 1033 | format!("const {} = {}", name, value) |
| 1034 | } else { |
| 1035 | format!("const {}{} = {}", name, type_ann, value) |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | /// Build class signature |
| 1040 | fn build_class_signature(&self, node: &Node, source: &str) -> String { |
no test coverage detected