@@ -58,27 +58,14 @@ module Line_edits = struct
5858 let pp fmt = Format. (pp_print_list pp_action fmt)
5959end
6060
61- module Mappings : sig
62- type t = private Uninterpreted of string [@@ unboxed]
63-
64- external uninterpreted : string -> t = " %identity"
65-
66- val empty : t
67-
68- val decode : t -> map list
69-
70- val encode : map list -> t
71-
72- val edit : strict :bool -> t -> Line_edits .t -> t
73-
74- (* Not for export *)
75- val concat : source_count1 :int -> name_count1 :int -> t -> t -> t
76- end = struct
61+ module Mappings = struct
7762 type t = Uninterpreted of string [@@ unboxed]
7863
7964 let empty = Uninterpreted " "
8065
81- external uninterpreted : string -> t = " %identity"
66+ external of_string : string -> t = " %identity"
67+
68+ external to_string : t -> string = " %identity"
8269
8370 let update_carries_from_segment
8471 ~carry_source
@@ -573,71 +560,43 @@ end = struct
573560 readline 1 0 []
574561end
575562
576- module Sources_contents : sig
577- type t = private Uninterpreted of string [@@ unboxed]
563+ module Source_text = struct
564+ type t = Uninterpreted of string [@@ unboxed]
578565
579- external uninterpreted : string -> t = " %identity"
566+ external of_json_string : string -> t = " %identity"
580567
581- val decode : t -> string option list
568+ external to_json_string : t -> string = " %identity"
569+
570+ let to_json =
571+ function
572+ | None -> `Null
573+ | Some text -> `String text
582574
583- val encode : string option list -> t
584- end = struct
585- type t = Uninterpreted of string [ @@ unboxed]
575+ let encode t =
576+ let json = Yojson.Basic. to_string (to_json t) in
577+ Uninterpreted json
586578
587- external uninterpreted : string -> t = " %identity"
588-
589- let to_json (cs : string option list ) =
590- `List
591- (List. map
592- ~f: (function
593- | None -> `Null
594- | Some s -> `String s)
595- cs)
596-
597- let encode cs =
598- (* There are two stages to the encoding. First encoding the list as a JSON
599- array of strings... *)
600- let array = Yojson.Basic. to_string (to_json cs) in
601- (* ... and then reifying that array itself as a string, under the form of a
602- JSON string literal. *)
603- let reified = Yojson.Basic. to_string (`String array ) in
604- Uninterpreted reified
605-
606- let of_json json =
607- match json with
608- | `List l ->
609- List. map
610- ~f: (function
611- | `String s -> Some s
612- | `Null -> None
613- | _ -> invalid_arg " Source_map.Sources_contents.of_json" )
614- l
615- | _ -> invalid_arg " Source_map.Sources_contents.of_json"
616-
617- let decode (Uninterpreted s ) : string option list =
579+ let of_json =
580+ function
581+ | `String s -> Some s
582+ | `Null -> None
583+ | _ -> invalid_arg " Source_map.Sources_contents.of_json: expected string or null"
584+
585+ let decode (Uninterpreted s ) : string option =
618586 (* The two stages of the encoding, in reverse. *)
619- match Yojson.Basic. from_string s with
620- | `String array -> (
621- try of_json (Yojson.Basic. from_string array )
622- with Yojson. Json_error s ->
623- invalid_arg
624- (" Source_map.Sources_contents.decode: This is a valid JSON literal, but it \
625- does not encode a JSON array: "
626- ^ s))
627- | _ ->
628- invalid_arg
629- " Source_map.Sources_contents.decode: This is a valid JSON object but not a \
630- string literal"
631- | exception Yojson. Json_error s ->
632- invalid_arg (" Source_map.Sources_contents.decode: not a JSON string literal: " ^ s)
587+ try of_json (Yojson.Basic. from_string s) with
588+ | Yojson. Json_error s ->
589+ invalid_arg
590+ (" Source_map.Sources_contents.decode: This is not a valid JSON object: "
591+ ^ s)
633592end
634593
635594type t =
636595 { version : int
637596 ; file : string
638597 ; sourceroot : string option
639598 ; sources : string list
640- ; sources_contents : Sources_contents .t option
599+ ; sources_contents : Source_text .t list option
641600 ; names : string list
642601 ; mappings : Mappings .t
643602 }
@@ -662,10 +621,7 @@ let concat ~file ~sourceroot s1 s2 =
662621 ; sources_contents =
663622 (match s1.sources_contents, s2.sources_contents with
664623 | None , contents | contents , None -> contents
665- | Some c1 , Some c2 ->
666- let c1 = Sources_contents. decode c1 in
667- let c2 = Sources_contents. decode c2 in
668- Some (Sources_contents. encode (c1 @ c2)))
624+ | Some c1 , Some c2 -> Some (c1 @ c2))
669625 ; names = s1.names @ s2.names
670626 ; mappings =
671627 Mappings. concat
0 commit comments