@@ -259,17 +259,17 @@ let list_stringlit_opt name rest =
259
259
module Standard = struct
260
260
type t =
261
261
{ version : int
262
- ; file : string
262
+ ; file : string option
263
263
; sourceroot : string option
264
264
; sources : string list
265
265
; sources_content : Source_content .t option list option
266
266
; names : string list
267
267
; mappings : Mappings .t
268
268
}
269
269
270
- let empty ~ filename =
270
+ let empty =
271
271
{ version = 3
272
- ; file = filename
272
+ ; file = None
273
273
; sourceroot = None
274
274
; sources = []
275
275
; sources_content = None
@@ -356,7 +356,7 @@ module Standard = struct
356
356
in
357
357
let acc_rev, mappings_rev =
358
358
loop
359
- { ( empty ~filename: " " ) with sources_content = Some [] }
359
+ { empty with sources_content = Some [] }
360
360
[]
361
361
~sources_offset: 0
362
362
~names_offset: 0
@@ -379,7 +379,10 @@ module Standard = struct
379
379
| None -> None
380
380
| Some v -> Some (name, v))
381
381
[ " 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)) )
383
386
; ( " sourceRoot"
384
387
, match t.sourceroot with
385
388
| None -> None
@@ -403,11 +406,7 @@ module Standard = struct
403
406
match json with
404
407
| `Assoc (("version" , `Intlit version ) :: rest ) when int_of_string version = 3 ->
405
408
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
411
410
let sourceroot = string " sourceRoot" rest in
412
411
let names =
413
412
match list_stringlit " names" rest with
@@ -457,29 +456,38 @@ module Index = struct
457
456
458
457
type t =
459
458
{ version : int
460
- ; file : string
459
+ ; file : string option
461
460
; sections : (offset * [ `Map of Standard .t ]) list
462
461
}
463
462
464
463
let json t =
465
464
let stringlit s = `Stringlit (Yojson.Safe. to_string (`String s)) in
466
465
`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
+ ])
483
491
484
492
let intlit ~errmsg name json =
485
493
match List. assoc name json with
@@ -534,7 +542,7 @@ module Index = struct
534
542
match List. assoc " sections" fields with
535
543
| `List sections ->
536
544
let sections = List. map ~f: section_of_json sections in
537
- { version = 3 ; file = Option. value file ~default: " " ; sections }
545
+ { version = 3 ; file; sections }
538
546
| _ -> invalid_arg " Source_map_io.Index.of_json: `sections` is not an array"
539
547
| exception Not_found ->
540
548
invalid_arg " Source_map_io.Index.of_json: no `sections` field" )
0 commit comments