Build const signature
(&self, declarator: &Node, source: &str)
| 987 | |
| 988 | /// Build const signature |
| 989 | fn build_const_signature(&self, declarator: &Node, source: &str) -> String { |
| 990 | let name = declarator |
| 991 | .child_by_field_name("name") |
| 992 | .and_then(|n| self.node_text(&n, source)) |
| 993 | .unwrap_or_default(); |
| 994 | |
| 995 | // Get type annotation if present |
| 996 | let type_ann = declarator |
| 997 | .child_by_field_name("type") |
| 998 | .map(|t| self.node_text(&t, source).unwrap_or_default()) |
| 999 | .unwrap_or_default(); |
| 1000 | |
| 1001 | // Get a short preview of the value (first 50 chars) |
| 1002 | let value = declarator |
| 1003 | .child_by_field_name("value") |
| 1004 | .map(|v| { |
| 1005 | let text = self.node_text(&v, source).unwrap_or_default(); |
| 1006 | if text.len() > 50 { |
| 1007 | let end = truncate_to_char_boundary(&text, 50); |
| 1008 | format!("{}...", &text[..end]) |
| 1009 | } else { |
| 1010 | text |
| 1011 | } |
| 1012 | }) |
| 1013 | .unwrap_or_default(); |
| 1014 | |
| 1015 | if type_ann.is_empty() { |
| 1016 | format!("const {} = {}", name, value) |
| 1017 | } else { |
| 1018 | format!("const {}{} = {}", name, type_ann, value) |
| 1019 | } |
| 1020 | } |
| 1021 | |
| 1022 | /// Build class signature |
| 1023 | fn build_class_signature(&self, node: &Node, source: &str) -> String { |
no test coverage detected