From 04090be4ad14df752bcb256b5cb7eb126a943b69 Mon Sep 17 00:00:00 2001 From: Olivier Nicole Date: Tue, 20 Aug 2024 14:55:37 +0200 Subject: [PATCH] Adapt Source_map after ocsigen/js_of_ocaml#1640 --- compiler/bin-wasm_of_ocaml/compile.ml | 2 +- compiler/lib/source_map.ml | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/compiler/bin-wasm_of_ocaml/compile.ml b/compiler/bin-wasm_of_ocaml/compile.ml index 77668c3af..006b9184f 100644 --- a/compiler/bin-wasm_of_ocaml/compile.ml +++ b/compiler/bin-wasm_of_ocaml/compile.ml @@ -40,7 +40,7 @@ let update_sourcemap ~sourcemap_root ~sourcemap_don't_inline_content sourcemap_f Some (List.map source_map.sources ~f:(fun file -> if Sys.file_exists file && not (Sys.is_directory file) - then Some (Fs.read_file file) + then Some (Source_map.Source_content.create (Fs.read_file file)) else None)) in let source_map = diff --git a/compiler/lib/source_map.ml b/compiler/lib/source_map.ml index e66dc3871..50aa2d0b3 100644 --- a/compiler/lib/source_map.ml +++ b/compiler/lib/source_map.ml @@ -331,7 +331,10 @@ let json ?replace_mappings t = | Some s -> rewrite_path s) ) ; "names", `List (List.map t.names ~f:(fun s -> stringlit s)) ; "sources", `List (List.map t.sources ~f:(fun s -> stringlit (rewrite_path s))) - ; "mappings", stringlit (Option.value ~default:(string_of_mapping t.mappings) replace_mappings) + ; ( "mappings" + , stringlit (match replace_mappings with + | None -> string_of_mapping t.mappings + | Some m -> m) ) ; ( "sourcesContent" , `List (match t.sources_content with @@ -409,10 +412,12 @@ let of_json ~parse_mappings (json : Yojson.Raw.t) = | None -> None | Some s -> Some (Source_content.of_stringlit s))) in + let mappings_str = string "mappings" rest in let mappings = - match string "mappings" rest with - | None -> mapping_of_string "" - | Some s -> mapping_of_string s + match parse_mappings, mappings_str with + | false, _ -> mapping_of_string "" + | true, None -> mapping_of_string "" + | true, Some s -> mapping_of_string s in ( { version = int_of_float (float_of_string version) ; file @@ -422,7 +427,7 @@ let of_json ~parse_mappings (json : Yojson.Raw.t) = ; sources ; mappings } - , if parse_mappings then None else Some mappings ) + , if parse_mappings then None else mappings_str ) | _ -> invalid () let of_string s = of_json ~parse_mappings:true (Yojson.Raw.from_string s) |> fst