normalizeImport converts various import syntaxes to a path-like format
(imp string)
| 204 | |
| 205 | // normalizeImport converts various import syntaxes to a path-like format |
| 206 | func normalizeImport(imp string) string { |
| 207 | // Remove quotes |
| 208 | imp = strings.Trim(imp, "\"'`") |
| 209 | |
| 210 | // Python dots to slashes: app.core.config -> app/core/config |
| 211 | if strings.Contains(imp, ".") && !strings.Contains(imp, "/") && !strings.HasPrefix(imp, ".") { |
| 212 | imp = strings.ReplaceAll(imp, ".", string(filepath.Separator)) |
| 213 | } |
| 214 | |
| 215 | // Rust :: to slashes: crate::foo::bar -> foo/bar |
| 216 | if strings.HasPrefix(imp, "crate::") { |
| 217 | imp = strings.TrimPrefix(imp, "crate::") |
| 218 | imp = strings.ReplaceAll(imp, "::", string(filepath.Separator)) |
| 219 | } |
| 220 | if strings.HasPrefix(imp, "super::") { |
| 221 | imp = strings.ReplaceAll(imp, "::", string(filepath.Separator)) |
| 222 | } |
| 223 | |
| 224 | return imp |
| 225 | } |
| 226 | |
| 227 | // resolveRelative handles ./foo and ../bar style imports |
| 228 | func resolveRelative(imp, fromDir string, idx *fileIndex) []string { |
no outgoing calls