(
source: &[u8],
node: TsNode<'_>,
clean: fn(&str) -> String,
)
| 75 | /// preceding `node`, cleaning each comment with `clean`. |
| 76 | #[allow(dead_code)] |
| 77 | pub(crate) fn docstring_from_preceding_comments( |
| 78 | source: &[u8], |
| 79 | node: TsNode<'_>, |
| 80 | clean: fn(&str) -> String, |
| 81 | ) -> Option<String> { |
| 82 | let mut comments = Vec::new(); |
| 83 | let mut current = node.prev_named_sibling(); |
| 84 | while let Some(sibling) = current { |
| 85 | if sibling.kind() == "comment" { |
| 86 | comments.push(node_text(source, sibling)); |
| 87 | current = sibling.prev_named_sibling(); |
| 88 | } else { |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | if comments.is_empty() { |
| 93 | return None; |
| 94 | } |
| 95 | // Comments are collected in reverse order (closest first). |
| 96 | comments.reverse(); |
| 97 | let cleaned: Vec<String> = comments.iter().map(|c| clean(c)).collect(); |
| 98 | let result = cleaned.join("\n").trim().to_string(); |
| 99 | if result.is_empty() { |
| 100 | None |
| 101 | } else { |
| 102 | Some(result) |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | /// Extract a docstring from the run of `#` comment siblings immediately |
| 107 | /// preceding `node`. |
no test coverage detected