(
node: Node<'_>,
source: &str,
scope: &[String],
prefix: &[String],
imports: &mut Vec<ImportBinding>,
)
| 339 | } |
| 340 | |
| 341 | fn rust_import( |
| 342 | node: Node<'_>, |
| 343 | source: &str, |
| 344 | scope: &[String], |
| 345 | prefix: &[String], |
| 346 | imports: &mut Vec<ImportBinding>, |
| 347 | ) { |
| 348 | match node.kind() { |
| 349 | "use_list" => { |
| 350 | for child in children(node) { |
| 351 | rust_import(child, source, scope, prefix, imports); |
| 352 | } |
| 353 | } |
| 354 | "scoped_use_list" => { |
| 355 | let Some(qualified) = node |
| 356 | .child_by_field_name("path") |
| 357 | .and_then(|node| qualified_path(text(node, source), "::")) |
| 358 | else { |
| 359 | return; |
| 360 | }; |
| 361 | let mut prefix = prefix.to_vec(); |
| 362 | prefix.extend(qualified); |
| 363 | for list in children(node) |
| 364 | .into_iter() |
| 365 | .filter(|node| node.kind() == "use_list") |
| 366 | { |
| 367 | rust_import(list, source, scope, &prefix, imports); |
| 368 | } |
| 369 | } |
| 370 | "use_wildcard" => {} |
| 371 | _ => { |
| 372 | // A scoped_identifier's `path` is only its prefix; unwrapping it |
| 373 | // drops the imported symbol. Only an alias wraps a complete path. |
| 374 | let argument = if node.kind() == "use_as_clause" { |
| 375 | node.child_by_field_name("path").unwrap_or(node) |
| 376 | } else { |
| 377 | node |
| 378 | }; |
| 379 | let Some(target) = qualified_path(text(argument, source), "::") else { |
| 380 | return; |
| 381 | }; |
| 382 | let mut full = prefix.to_vec(); |
| 383 | full.extend(target); |
| 384 | if full.last().is_some_and(|name| name == "self") { |
| 385 | full.pop(); |
| 386 | } |
| 387 | if let Some(local) = node |
| 388 | .child_by_field_name("alias") |
| 389 | .map(|node| text(node, source).to_owned()) |
| 390 | .or_else(|| full.last().cloned()) |
| 391 | { |
| 392 | let lexical = lexical_container(node); |
| 393 | imports.push(ImportBinding { |
| 394 | scope: scope.to_vec(), |
| 395 | local, |
| 396 | target: full, |
| 397 | script_module: None, |
| 398 | namespace: false, |
no test coverage detected