Node `path.posix.normalize` for the require_relative path join (emitRubyRequireRefs): resolve `.`/`..` lexically, collapse `//`, keep unresolvable leading `..`s, preserve a trailing slash.
(p: &str)
| 57 | /// (emitRubyRequireRefs): resolve `.`/`..` lexically, collapse `//`, keep |
| 58 | /// unresolvable leading `..`s, preserve a trailing slash. |
| 59 | fn posix_normalize(p: &str) -> String { |
| 60 | let is_abs = p.starts_with('/'); |
| 61 | let had_trailing = p.len() > 1 && p.ends_with('/'); |
| 62 | let mut out: Vec<&str> = Vec::new(); |
| 63 | for seg in p.split('/') { |
| 64 | match seg { |
| 65 | "" | "." => {} |
| 66 | ".." => { |
| 67 | if matches!(out.last(), Some(&last) if last != "..") { |
| 68 | out.pop(); |
| 69 | } else if !is_abs { |
| 70 | out.push(".."); |
| 71 | } |
| 72 | } |
| 73 | s => out.push(s), |
| 74 | } |
| 75 | } |
| 76 | let mut joined = out.join("/"); |
| 77 | if is_abs { |
| 78 | joined = format!("/{joined}"); |
| 79 | } |
| 80 | if joined.is_empty() || joined == "/" { |
| 81 | return if is_abs { "/".to_string() } else { ".".to_string() }; |
| 82 | } |
| 83 | if had_trailing { |
| 84 | joined.push('/'); |
| 85 | } |
| 86 | joined |
| 87 | } |
| 88 | |
| 89 | struct Scope { |
| 90 | row: u32, |
no test coverage detected