@@ -84,8 +84,8 @@ let find_source file =
8484 Some (Source_map.Source_content. create content)
8585 else None
8686
87- let build_source_map_with_offset
88- (sm : Source_map.Standard.t )
87+ let sourcemap_section_of_info
88+ ~ base : (sm : Source_map.Standard.t )
8989 { Source_map. sources; names; mappings } =
9090 let sources_content =
9191 match sm.sources_content with
@@ -98,27 +98,25 @@ let build_source_map_with_offset
9898 | None -> filename
9999 | Some _ -> Filename. concat " /builtin" filename)
100100 in
101- let line_offset, mappings = Source_map.Mappings. encode_with_offset mappings in
102- ( line_offset
103- , { (sm : Source_map.Standard.t ) with sources; sources_content; names; mappings } )
101+ let offset, mappings = Source_map.Mappings. encode_with_offset mappings in
102+ let map =
103+ { (sm : Source_map.Standard.t ) with sources; sources_content; names; mappings }
104+ in
105+ { Source_map.Index. offset; map }
104106
105- let build_source_map_many base l =
107+ let sourcemap_of_infos ~ base l =
106108 match base with
107109 | None -> None
108110 | Some (sm : Source_map.Standard.t ) ->
109- let sections =
110- List. map l ~f: (fun info ->
111- let line_offset, sm = build_source_map_with_offset sm info in
112- { Source_map.Index. gen_line = line_offset; gen_column = 0 }, `Map sm)
113- in
111+ let sections = List. map l ~f: (sourcemap_section_of_info ~base: sm) in
114112 Some
115113 (Source_map. Index
116114 { Source_map.Index. version = sm.Source_map.Standard. version
117115 ; file = sm.file
118116 ; sections
119117 })
120118
121- let build_source_map_one base info = build_source_map_many base [ info ]
119+ let sourcemap_of_info ~ base info = sourcemap_of_infos ~ base [ info ]
122120
123121let run
124122 { Cmd_arg. common
@@ -373,7 +371,7 @@ let run
373371 ~standalone
374372 ~link: `All
375373 output_file
376- |> build_source_map_one source_map_base)
374+ |> sourcemap_of_info ~base: source_map_base)
377375 | (`Stdin | `File _ ) as bytecode ->
378376 let kind, ic, close_ic, include_dirs =
379377 match bytecode with
@@ -419,7 +417,7 @@ let run
419417 ~source_map
420418 ~link: (if linkall then `All else `Needed )
421419 output_file
422- |> build_source_map_one source_map_base)
420+ |> sourcemap_of_info ~base: source_map_base)
423421 | `Cmo cmo ->
424422 let output_file =
425423 match output_file, keep_unit_names with
@@ -454,10 +452,10 @@ let run
454452 | true ->
455453 let sm1 = output_partial_runtime ~standalone ~source_map output in
456454 let sm2 = output_partial cmo code ~standalone ~source_map output in
457- build_source_map_many source_map_base [ sm1; sm2 ]
455+ sourcemap_of_infos ~base: source_map_base [ sm1; sm2 ]
458456 | false ->
459457 output_partial cmo code ~standalone ~source_map output
460- |> build_source_map_one source_map_base)
458+ |> sourcemap_of_info ~base: source_map_base)
461459 | `Cma cma when keep_unit_names ->
462460 (if include_runtime
463461 then
@@ -480,7 +478,7 @@ let run
480478 (`Name output_file)
481479 (fun ~standalone ~source_map output ->
482480 output_partial_runtime ~standalone ~source_map output
483- |> build_source_map_one source_map_base));
481+ |> sourcemap_of_info ~base: source_map_base));
484482 List. iter cma.lib_units ~f: (fun cmo ->
485483 let output_file =
486484 match output_file with
@@ -516,7 +514,7 @@ let run
516514 (`Name output_file)
517515 (fun ~standalone ~source_map output ->
518516 output_partial ~standalone ~source_map cmo code output
519- |> build_source_map_one source_map_base))
517+ |> sourcemap_of_info ~base: source_map_base))
520518 | `Cma cma ->
521519 let f ~standalone ~source_map output =
522520 let source_map_runtime =
@@ -550,7 +548,7 @@ let run
550548 | None -> source_map_units
551549 | Some x -> x :: source_map_units
552550 in
553- build_source_map_many source_map_base sm
551+ sourcemap_of_infos ~base: source_map_base sm
554552 in
555553 output_gen
556554 ~standalone: false
0 commit comments