Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Oct 17, 2024
1 parent 14d52f1 commit 81aec6d
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions compiler/lib/link_js.ml
Original file line number Diff line number Diff line change
Expand Up @@ -471,23 +471,37 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
, gen_column
, sm ))
in
List.concat_map reloc ~f:(function
| `Drop _ -> []
| `Copy (src, dst, len) ->
List.filter_map sm ~f:(fun (first, last, gen_line, gen_column, sm) ->
if first > src + len || last < src
then None
else (
assert (src <= first && last <= src + len);
Some (gen_line + dst - src, gen_column, sm)))))
(* select sourcemaps that cover copied section *)
let maps =
List.concat_map reloc ~f:(function
| `Drop _ -> []
| `Copy (src, dst, len) ->
List.filter_map
sm
~f:(fun (first, last, gen_line, gen_column, sm) ->
if first > src + len || last < src
then None
else (
(* We don't want to deal with overlapping but not included
sourcemap, but we could in theory filter out part of it. *)
assert (src <= first && last <= src + len);
Some (first, last, gen_line + dst - src, gen_column, sm))))
in
(* Make sure dropped sections are not overlapping selected sourcemap. *)
List.iter reloc ~f:(function
| `Copy _ -> ()
| `Drop (src, len) ->
List.iter maps ~f:(fun (first, last, _, _, _) ->
if first > src + len || last < src then () else assert false));
maps)
in
let sections = List.concat sections in
let sm =
{ Source_map.Index.version = init_sm.Source_map.Standard.version
; file = init_sm.file
; sections =
(* preserve some info from [init_sm] *)
List.map sections ~f:(fun (gen_line, gen_column, sm) ->
List.map sections ~f:(fun (_, _, gen_line, gen_column, sm) ->
( { Source_map.Index.gen_line; gen_column }
, `Map { sm with sourceroot = init_sm.sourceroot } ))
}
Expand Down

0 comments on commit 81aec6d

Please sign in to comment.