Build const signature
(&self, declarator: &Node, source: &str)
| 1032 | |
| 1033 | /// Build const signature |
| 1034 | fn build_const_signature(&self, declarator: &Node, source: &str) -> String { |
| 1035 | let name = declarator |
| 1036 | .child_by_field_name("name") |
| 1037 | .and_then(|n| self.node_text(&n, source)) |
| 1038 | .unwrap_or_default(); |
| 1039 | |
| 1040 | // Get type annotation if present |
| 1041 | let type_ann = declarator |
| 1042 | .child_by_field_name("type") |
| 1043 | .map(|t| self.node_text(&t, source).unwrap_or_default()) |
| 1044 | .unwrap_or_default(); |
| 1045 | |
| 1046 | // Get a short preview of the value (first 50 chars) |
| 1047 | let value = declarator |
| 1048 | .child_by_field_name("value") |
| 1049 | .map(|v| { |
| 1050 | let text = self.node_text(&v, source).unwrap_or_default(); |
| 1051 | if text.len() > 50 { |
| 1052 | let end = truncate_to_char_boundary(&text, 50); |
| 1053 | format!("{}...", &text[..end]) |
| 1054 | } else { |
| 1055 | text |
| 1056 | } |
| 1057 | }) |
| 1058 | .unwrap_or_default(); |
| 1059 | |
| 1060 | if type_ann.is_empty() { |
| 1061 | format!("const {} = {}", name, value) |
| 1062 | } else { |
| 1063 | format!("const {}{} = {}", name, type_ann, value) |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | /// Build class signature |
| 1068 | fn build_class_signature(&self, node: &Node, source: &str) -> String { |
no test coverage detected