Skip to content

Commit

Permalink
Adapt Source_map after ocsigen/js_of_ocaml#1640
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole committed Aug 22, 2024
1 parent bcad8dd commit 1a611c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion compiler/bin-wasm_of_ocaml/compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
15 changes: 10 additions & 5 deletions compiler/lib/source_map.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 1a611c7

Please sign in to comment.