Skip to content

Commit 1a611c7

Browse files
committed
Adapt Source_map after ocsigen/js_of_ocaml#1640
1 parent bcad8dd commit 1a611c7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

compiler/bin-wasm_of_ocaml/compile.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let update_sourcemap ~sourcemap_root ~sourcemap_don't_inline_content sourcemap_f
4040
Some
4141
(List.map source_map.sources ~f:(fun file ->
4242
if Sys.file_exists file && not (Sys.is_directory file)
43-
then Some (Fs.read_file file)
43+
then Some (Source_map.Source_content.create (Fs.read_file file))
4444
else None))
4545
in
4646
let source_map =

compiler/lib/source_map.ml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,10 @@ let json ?replace_mappings t =
331331
| Some s -> rewrite_path s) )
332332
; "names", `List (List.map t.names ~f:(fun s -> stringlit s))
333333
; "sources", `List (List.map t.sources ~f:(fun s -> stringlit (rewrite_path s)))
334-
; "mappings", stringlit (Option.value ~default:(string_of_mapping t.mappings) replace_mappings)
334+
; ( "mappings"
335+
, stringlit (match replace_mappings with
336+
| None -> string_of_mapping t.mappings
337+
| Some m -> m) )
335338
; ( "sourcesContent"
336339
, `List
337340
(match t.sources_content with
@@ -409,10 +412,12 @@ let of_json ~parse_mappings (json : Yojson.Raw.t) =
409412
| None -> None
410413
| Some s -> Some (Source_content.of_stringlit s)))
411414
in
415+
let mappings_str = string "mappings" rest in
412416
let mappings =
413-
match string "mappings" rest with
414-
| None -> mapping_of_string ""
415-
| Some s -> mapping_of_string s
417+
match parse_mappings, mappings_str with
418+
| false, _ -> mapping_of_string ""
419+
| true, None -> mapping_of_string ""
420+
| true, Some s -> mapping_of_string s
416421
in
417422
( { version = int_of_float (float_of_string version)
418423
; file
@@ -422,7 +427,7 @@ let of_json ~parse_mappings (json : Yojson.Raw.t) =
422427
; sources
423428
; mappings
424429
}
425-
, if parse_mappings then None else Some mappings )
430+
, if parse_mappings then None else mappings_str )
426431
| _ -> invalid ()
427432

428433
let of_string s = of_json ~parse_mappings:true (Yojson.Raw.from_string s) |> fst

0 commit comments

Comments
 (0)