@@ -259,17 +259,17 @@ let list_stringlit_opt name rest =
259259module Standard = struct
260260 type t =
261261 { version : int
262- ; file : string
262+ ; file : string option
263263 ; sourceroot : string option
264264 ; sources : string list
265265 ; sources_content : Source_content .t option list option
266266 ; names : string list
267267 ; mappings : Mappings .t
268268 }
269269
270- let empty ~ filename =
270+ let empty =
271271 { version = 3
272- ; file = filename
272+ ; file = None
273273 ; sourceroot = None
274274 ; sources = []
275275 ; sources_content = None
@@ -356,7 +356,7 @@ module Standard = struct
356356 in
357357 let acc_rev, mappings_rev =
358358 loop
359- { ( empty ~filename: " " ) with sources_content = Some [] }
359+ { empty with sources_content = Some [] }
360360 []
361361 ~sources_offset: 0
362362 ~names_offset: 0
@@ -379,7 +379,10 @@ module Standard = struct
379379 | None -> None
380380 | Some v -> Some (name, v))
381381 [ " version" , Some (`Intlit (string_of_int t.version))
382- ; " file" , Some (stringlit (rewrite_path t.file))
382+ ; ( " file"
383+ , match t.file with
384+ | None -> None
385+ | Some file -> Some (stringlit (rewrite_path file)) )
383386 ; ( " sourceRoot"
384387 , match t.sourceroot with
385388 | None -> None
@@ -403,11 +406,7 @@ module Standard = struct
403406 match json with
404407 | `Assoc (("version" , `Intlit version ) :: rest ) when int_of_string version = 3 ->
405408 let string name json = Option. map ~f: string_of_stringlit (stringlit name json) in
406- let file =
407- match string " file" rest with
408- | None -> " "
409- | Some s -> s
410- in
409+ let file = string " file" rest in
411410 let sourceroot = string " sourceRoot" rest in
412411 let names =
413412 match list_stringlit " names" rest with
@@ -457,29 +456,38 @@ module Index = struct
457456
458457 type t =
459458 { version : int
460- ; file : string
459+ ; file : string option
461460 ; sections : (offset * [ `Map of Standard .t ]) list
462461 }
463462
464463 let json t =
465464 let stringlit s = `Stringlit (Yojson.Safe. to_string (`String s)) in
466465 `Assoc
467- [ " version" , `Intlit (string_of_int t.version)
468- ; " file" , stringlit (rewrite_path t.file)
469- ; ( " sections"
470- , `List
471- (List. map
472- ~f: (fun ({ gen_line; gen_column } , `Map sm ) ->
473- `Assoc
474- [ ( " offset"
475- , `Assoc
476- [ " line" , `Intlit (string_of_int gen_line)
477- ; " column" , `Intlit (string_of_int gen_column)
478- ] )
479- ; " map" , Standard. json sm
480- ])
481- t.sections) )
482- ]
466+ (List. filter_map
467+ ~f: (fun (name , v ) ->
468+ match v with
469+ | None -> None
470+ | Some v -> Some (name, v))
471+ [ " version" , Some (`Intlit (string_of_int t.version))
472+ ; ( " file"
473+ , match t.file with
474+ | None -> None
475+ | Some file -> Some (stringlit (rewrite_path file)) )
476+ ; ( " sections"
477+ , Some
478+ (`List
479+ (List. map
480+ ~f: (fun ({ gen_line; gen_column } , `Map sm ) ->
481+ `Assoc
482+ [ ( " offset"
483+ , `Assoc
484+ [ " line" , `Intlit (string_of_int gen_line)
485+ ; " column" , `Intlit (string_of_int gen_column)
486+ ] )
487+ ; " map" , Standard. json sm
488+ ])
489+ t.sections)) )
490+ ])
483491
484492 let intlit ~errmsg name json =
485493 match List. assoc name json with
@@ -534,7 +542,7 @@ module Index = struct
534542 match List. assoc " sections" fields with
535543 | `List sections ->
536544 let sections = List. map ~f: section_of_json sections in
537- { version = 3 ; file = Option. value file ~default: " " ; sections }
545+ { version = 3 ; file; sections }
538546 | _ -> invalid_arg " Source_map_io.Index.of_json: `sections` is not an array"
539547 | exception Not_found ->
540548 invalid_arg " Source_map_io.Index.of_json: no `sections` field" )
0 commit comments