@@ -324,11 +324,12 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
324
324
let sm_for_file = ref None in
325
325
let ic = Line_reader. open_ file in
326
326
let skip ic = Line_reader. drop ic in
327
+ let line_offset = Line_writer. lnum oc in
327
328
let reloc = ref [] in
328
329
let copy ic oc =
329
330
let line = Line_reader. next ic in
330
331
Line_writer. write ~source: ic oc line;
331
- reloc := (Line_reader. lnum ic, Line_writer. lnum oc) :: ! reloc
332
+ reloc := (Line_reader. lnum ic, Line_writer. lnum oc - line_offset ) :: ! reloc
332
333
in
333
334
let rec read () =
334
335
match Line_reader. peek ic with
@@ -432,7 +433,7 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
432
433
Line_writer. write_lines oc content);
433
434
(match ! sm_for_file with
434
435
| None -> ()
435
- | Some x -> sm := (x, ! reloc) :: ! sm);
436
+ | Some x -> sm := (x, ! reloc, line_offset ) :: ! sm);
436
437
match ! build_info, build_info_for_file with
437
438
| None , None -> ()
438
439
| Some _ , None -> ()
@@ -445,33 +446,32 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
445
446
match source_map with
446
447
| None -> ()
447
448
| Some (file , init_sm ) ->
448
- let sm =
449
- List. rev_map ! sm ~f: (fun (sm , reloc ) ->
449
+ let sections =
450
+ List. rev_map ! sm ~f: (fun (sm , reloc , offset ) ->
450
451
let tbl = Hashtbl. create 17 in
451
452
List. iter reloc ~f: (fun (a , b ) -> Hashtbl. add tbl a b);
452
- Source_map.Standard. filter_map sm ~f: (Hashtbl. find_opt tbl))
453
+ ( { Source_map.Index. gen_line = offset; gen_column = 0 }
454
+ , `Map (Source_map.Standard. filter_map sm ~f: (Hashtbl. find_opt tbl)) ))
453
455
in
454
- (match Source_map.Standard. merge (init_sm :: sm) with
455
- | None -> ()
456
- | Some sm -> (
457
- (* preserve some info from [init_sm] *)
458
- let sm =
459
- `Standard
460
- { sm with
461
- version = init_sm.version
462
- ; file = init_sm.file
463
- ; sourceroot = init_sm.sourceroot
464
- }
465
- in
466
- match file with
467
- | None ->
468
- let data = Source_map. to_string sm in
469
- let s = sourceMappingURL_base64 ^ Base64. encode_exn data in
470
- Line_writer. write oc s
471
- | Some file ->
472
- Source_map. to_file sm file;
473
- let s = sourceMappingURL ^ Filename. basename file in
474
- Line_writer. write oc s));
456
+ let sm =
457
+ { Source_map.Index. version = init_sm.Source_map.Standard. version
458
+ ; file = init_sm.file
459
+ ; sections =
460
+ (* preserve some info from [init_sm] *)
461
+ List. map sections ~f: (fun (ofs , `Map sm ) ->
462
+ ofs, `Map { sm with sourceroot = init_sm.sourceroot })
463
+ }
464
+ in
465
+ let sm = `Index sm in
466
+ (match file with
467
+ | None ->
468
+ let data = Source_map. to_string sm in
469
+ let s = sourceMappingURL_base64 ^ Base64. encode_exn data in
470
+ Line_writer. write oc s
471
+ | Some file ->
472
+ Source_map. to_file sm file;
473
+ let s = sourceMappingURL ^ Filename. basename file in
474
+ Line_writer. write oc s);
475
475
if times () then Format. eprintf " sourcemap: %a@." Timer. print t
476
476
477
477
let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source_map =
0 commit comments