fob_graph/analysis/resolver/aliases.rs
1//! Path alias handling for module resolution.
2//!
3//! This module handles resolution of path aliases (e.g., "@" → "./src").
4
5use std::path::Path;
6
7/// Resolve a path alias (e.g., "@/components" → "./src/components").
8pub fn resolve_path_alias(
9 specifier: &str,
10 _from: &Path,
11 path_aliases: &rustc_hash::FxHashMap<String, String>,
12) -> Option<String> {
13 for (alias, target) in path_aliases {
14 if specifier.starts_with(alias) {
15 let rest = &specifier[alias.len()..];
16 // Remove leading slash if present
17 let rest = rest.strip_prefix('/').unwrap_or(rest);
18
19 // Build resolved path - ensure it starts with ./ for relative resolution
20 let resolved = if target.starts_with('/') {
21 // Absolute path - shouldn't happen but handle it
22 format!("{target}/{rest}")
23 } else if target.starts_with('.') {
24 // Already relative
25 if rest.is_empty() {
26 target.clone()
27 } else {
28 format!("{target}/{rest}")
29 }
30 } else {
31 // Make it relative
32 if rest.is_empty() {
33 format!("./{target}")
34 } else {
35 format!("./{target}/{rest}")
36 }
37 };
38
39 return Some(resolved);
40 }
41 }
42 None
43}