Returns the text of the rightmost identifier-like child of `node`.
(node: TsNode<'_>, source: &[u8])
| 258 | |
| 259 | /// Returns the text of the rightmost identifier-like child of `node`. |
| 260 | fn rightmost_identifier(node: TsNode<'_>, source: &[u8]) -> String { |
| 261 | // If node itself is a simple identifier, return it. |
| 262 | let nk = node.kind(); |
| 263 | if nk == "identifier" || nk == "field_identifier" || nk == "property_identifier" { |
| 264 | return node.utf8_text(source).unwrap_or("").to_string(); |
| 265 | } |
| 266 | // Walk children via cursor and remember the rightmost match — `node.child(i)` |
| 267 | // would be O(N²) for the right-to-left scan the previous revision did. |
| 268 | let mut cursor = node.walk(); |
| 269 | let mut found = String::new(); |
| 270 | if cursor.goto_first_child() { |
| 271 | loop { |
| 272 | let child = cursor.node(); |
| 273 | let ck = child.kind(); |
| 274 | if ck == "identifier" || ck == "field_identifier" || ck == "property_identifier" { |
| 275 | if let Ok(text) = child.utf8_text(source) { |
| 276 | found = text.to_string(); |
| 277 | } |
| 278 | } |
| 279 | if !cursor.goto_next_sibling() { |
| 280 | break; |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | found |
| 285 | } |
| 286 | |
| 287 | // --------------------------------------------------------------------------- |
| 288 | // Per-language configurations |
no test coverage detected