Skip to content

Commit 81aec6d

Browse files
committed
CR
1 parent 14d52f1 commit 81aec6d

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

compiler/lib/link_js.ml

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -471,23 +471,37 @@ let link ~output ~linkall ~mklib ~toplevel ~files ~resolve_sourcemap_url ~source
471471
, gen_column
472472
, sm ))
473473
in
474-
List.concat_map reloc ~f:(function
475-
| `Drop _ -> []
476-
| `Copy (src, dst, len) ->
477-
List.filter_map sm ~f:(fun (first, last, gen_line, gen_column, sm) ->
478-
if first > src + len || last < src
479-
then None
480-
else (
481-
assert (src <= first && last <= src + len);
482-
Some (gen_line + dst - src, gen_column, sm)))))
474+
(* select sourcemaps that cover copied section *)
475+
let maps =
476+
List.concat_map reloc ~f:(function
477+
| `Drop _ -> []
478+
| `Copy (src, dst, len) ->
479+
List.filter_map
480+
sm
481+
~f:(fun (first, last, gen_line, gen_column, sm) ->
482+
if first > src + len || last < src
483+
then None
484+
else (
485+
(* We don't want to deal with overlapping but not included
486+
sourcemap, but we could in theory filter out part of it. *)
487+
assert (src <= first && last <= src + len);
488+
Some (first, last, gen_line + dst - src, gen_column, sm))))
489+
in
490+
(* Make sure dropped sections are not overlapping selected sourcemap. *)
491+
List.iter reloc ~f:(function
492+
| `Copy _ -> ()
493+
| `Drop (src, len) ->
494+
List.iter maps ~f:(fun (first, last, _, _, _) ->
495+
if first > src + len || last < src then () else assert false));
496+
maps)
483497
in
484498
let sections = List.concat sections in
485499
let sm =
486500
{ Source_map.Index.version = init_sm.Source_map.Standard.version
487501
; file = init_sm.file
488502
; sections =
489503
(* preserve some info from [init_sm] *)
490-
List.map sections ~f:(fun (gen_line, gen_column, sm) ->
504+
List.map sections ~f:(fun (_, _, gen_line, gen_column, sm) ->
491505
( { Source_map.Index.gen_line; gen_column }
492506
, `Map { sm with sourceroot = init_sm.sourceroot } ))
493507
}

0 commit comments

Comments
 (0)