Skip to content

Commit b021c2f

Browse files
committed
Preserve relative source paths in maps
1 parent d0ed388 commit b021c2f

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

compiler/core/js_source_map.ml

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,26 @@ let repeat x n =
7676
let rec loop acc n = if n <= 0 then acc else loop (x :: acc) (n - 1) in
7777
loop [] n
7878

79+
let drive_root parts =
80+
match parts with
81+
| drive :: _ when String.length drive = 2 && drive.[1] = ':' ->
82+
Some (String.uppercase_ascii drive)
83+
| _ -> None
84+
7985
let relative_path ~from_dir ~to_file =
8086
let from_dir = absolute_path from_dir in
8187
let to_file = absolute_path to_file in
8288
let from_parts = split_path from_dir in
8389
let to_parts = split_path to_file in
84-
match (from_parts, to_parts) with
85-
| from_root :: _, to_root :: _ when from_root = to_root ->
90+
match (drive_root from_parts, drive_root to_parts) with
91+
(* Cross-drive Windows paths cannot be represented as a filesystem-relative path. *)
92+
| Some from_drive, Some to_drive when from_drive <> to_drive ->
93+
normalize_slashes to_file
94+
| Some _, None | None, Some _ -> normalize_slashes to_file
95+
| _ ->
8696
let from_rest, to_rest = drop_common from_parts to_parts in
8797
let parts = repeat ".." (List.length from_rest) @ to_rest in
8898
if parts = [] then Filename.basename to_file else String.concat "/" parts
89-
| _ -> Filename.basename to_file
9099

91100
let make ~generated_file ~source_root ~sources_content =
92101
{

0 commit comments

Comments
 (0)