Standard explicit relative script import candidates. Full source inventory is consulted even when only matching files are parsed, preserving ambiguity.
(importer: &str, module: &str, paths: &BTreeSet<String>)
| 66 | /// Standard explicit relative script import candidates. Full source inventory is |
| 67 | /// consulted even when only matching files are parsed, preserving ambiguity. |
| 68 | pub fn script_candidates(importer: &str, module: &str, paths: &BTreeSet<String>) -> Vec<String> { |
| 69 | let script = |path: &str| { |
| 70 | matches!( |
| 71 | Path::new(path) |
| 72 | .extension() |
| 73 | .and_then(|extension| extension.to_str()), |
| 74 | Some("ts" | "tsx" | "mts" | "cts" | "js" | "jsx" | "mjs" | "cjs") |
| 75 | ) |
| 76 | }; |
| 77 | if !script(importer) || !module.starts_with('.') { |
| 78 | return vec![]; |
| 79 | } |
| 80 | let Some(requested) = Path::new(importer) |
| 81 | .parent() |
| 82 | .and_then(|base| normalize(base.join(module))) |
| 83 | else { |
| 84 | return vec![]; |
| 85 | }; |
| 86 | paths |
| 87 | .iter() |
| 88 | .filter(|target| { |
| 89 | if !script(target) { |
| 90 | return false; |
| 91 | } |
| 92 | let target = Path::new(target); |
| 93 | let stem = target.with_extension(""); |
| 94 | target == requested || stem == requested || stem == requested.join("index") |
| 95 | }) |
| 96 | .cloned() |
| 97 | .collect() |
| 98 | } |
| 99 | |
| 100 | /// Declaration/import context needed to interpret a selected source file. |
| 101 | /// This returns paths only; repository adapters own recorded-byte retrieval. |
no test coverage detected