@@ -476,14 +476,13 @@ module Standard = struct
476476 ; ( " file"
477477 , match t.file with
478478 | None -> None
479- | Some file -> Some (stringlit (rewrite_path file) ) )
479+ | Some file -> Some (stringlit file) )
480480 ; ( " sourceRoot"
481481 , match t.sourceroot with
482482 | None -> None
483- | Some s -> Some (stringlit (rewrite_path s) ) )
483+ | Some s -> Some (stringlit s ) )
484484 ; " names" , Some (`List (List. map t.names ~f: (fun s -> stringlit s)))
485- ; ( " sources"
486- , Some (`List (List. map t.sources ~f: (fun s -> stringlit (rewrite_path s)))) )
485+ ; " sources" , Some (`List (List. map t.sources ~f: (fun s -> stringlit s)))
487486 ; " mappings" , Some (stringlit (Mappings. to_string t.mappings))
488487 ; ( " sourcesContent"
489488 , match t.sources_content with
@@ -570,9 +569,16 @@ module Standard = struct
570569
571570 let of_file ?tmp_buf f = of_json ?tmp_buf (Yojson.Raw. from_file ?buf:tmp_buf f )
572571
573- let to_string m = Yojson.Raw. to_string (json m)
572+ let rewrite_paths sm =
573+ { sm with
574+ file = Option. map ~f: rewrite_path sm.file
575+ ; sourceroot = Option. map ~f: rewrite_path sm.sourceroot
576+ ; sources = List. map ~f: rewrite_path sm.sources
577+ }
578+
579+ let to_string m = Yojson.Raw. to_string (json (rewrite_paths m))
574580
575- let to_file m file = Yojson.Raw. to_file file (json m )
581+ let to_file m file = Yojson.Raw. to_file file (json (rewrite_paths m) )
576582
577583 let invariant
578584 { version
@@ -628,7 +634,7 @@ module Index = struct
628634 ; ( " file"
629635 , match t.file with
630636 | None -> None
631- | Some file -> Some (stringlit (rewrite_path file) ) )
637+ | Some file -> Some (stringlit file) )
632638 ; ( " sections"
633639 , Some
634640 (`List
@@ -703,9 +709,16 @@ module Index = struct
703709 invalid_arg " Source_map.Index.of_json: no `sections` field" )
704710 | _ -> invalid_arg " Source_map.Index.of_json"
705711
706- let to_string m = Yojson.Raw. to_string (json m)
712+ let rewrite_paths m =
713+ { m with
714+ file = Option. map ~f: rewrite_path m.file
715+ ; sections =
716+ List. map ~f: (fun m -> { m with map = Standard. rewrite_paths m.map }) m.sections
717+ }
718+
719+ let to_string m = Yojson.Raw. to_string (json (rewrite_paths m))
707720
708- let to_file m file = Yojson.Raw. to_file file (json m )
721+ let to_file m file = Yojson.Raw. to_file file (json (rewrite_paths m) )
709722
710723 let invariant { version; file = _ ; sections } =
711724 if not (version_is_valid version)
0 commit comments