Skip to content

Commit

Permalink
fix offset
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Oct 15, 2024
1 parent ecc5724 commit dc991bd
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/lib/link_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -324,11 +324,12 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
let sm_for_file = ref None in
let ic = Line_reader.open_ file in
let skip ic = Line_reader.drop ic in
let line_offset = Line_writer.lnum oc in
let reloc = ref [] in
let copy ic oc =
let line = Line_reader.next ic in
Line_writer.write ~source:ic oc line;
reloc := (Line_reader.lnum ic, Line_writer.lnum oc) :: !reloc
reloc := (Line_reader.lnum ic, Line_writer.lnum oc - line_offset) :: !reloc
in
let rec read () =
match Line_reader.peek ic with
Expand Down Expand Up @@ -432,7 +433,7 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
Line_writer.write_lines oc content);
(match !sm_for_file with
| None -> ()
| Some x -> sm := (x, !reloc) :: !sm);
| Some x -> sm := (x, !reloc, line_offset) :: !sm);
match !build_info, build_info_for_file with
| None, None -> ()
| Some _, None -> ()
Expand All @@ -446,10 +447,10 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
| None -> ()
| Some (file, init_sm) ->
let sections =
List.rev_map !sm ~f:(fun (sm, reloc) ->
List.rev_map !sm ~f:(fun (sm, reloc, offset) ->
let tbl = Hashtbl.create 17 in
List.iter reloc ~f:(fun (a, b) -> Hashtbl.add tbl a b);
( { Source_map.Index.gen_line = 0; gen_column = 0 }
( { Source_map.Index.gen_line = offset; gen_column = 0 }
, `Map (Source_map.Standard.filter_map sm ~f:(Hashtbl.find_opt tbl)) ))
in
let sm =
Expand Down

0 comments on commit dc991bd

Please sign in to comment.