Skip to content

Commit

Permalink
Decode sourcemap mappings only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole committed Sep 3, 2024
1 parent 613cbcc commit ffb084c
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 182 deletions.
4 changes: 2 additions & 2 deletions compiler/bin-js_of_ocaml/cmd_arg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ let options =
; sources = []
; sources_content = (if sourcemap_don't_inline_content then None else Some [])
; names = []
; mappings = []
; mappings = Source_map.Mappings.empty
} )
else None
in
Expand Down Expand Up @@ -543,7 +543,7 @@ let options_runtime_only =
; sources = []
; sources_content = (if sourcemap_don't_inline_content then None else Some [])
; names = []
; mappings = []
; mappings = Source_map.Mappings.empty
} )
else None
in
Expand Down
2 changes: 1 addition & 1 deletion compiler/bin-js_of_ocaml/link.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ let options =
; sources = []
; sources_content = Some []
; names = []
; mappings = []
; mappings = Source_map.Mappings.empty
} )
else None
in
Expand Down
4 changes: 3 additions & 1 deletion compiler/lib/js_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1996,8 +1996,9 @@ let program ?(accept_unnamed_var = false) f ?source_map p =
| None -> filename
| Some _ -> Filename.concat "/builtin" filename)
in
let sm_mappings = Source_map.Mappings.decode sm.mappings in
let mappings =
List.rev_append_map !temp_mappings sm.mappings ~f:(fun (pos, m) ->
List.rev_append_map !temp_mappings sm_mappings ~f:(fun (pos, m) ->
let gen_line = pos.PP.p_line + 1 in
let gen_col = pos.PP.p_col in
match m with
Expand All @@ -2012,6 +2013,7 @@ let program ?(accept_unnamed_var = false) f ?source_map p =
Source_map.Gen_Ori_Name
{ gen_line; gen_col; ori_source; ori_line; ori_col; ori_name })
in
let mappings = Source_map.Mappings.encode mappings in
Some { sm with Source_map.sources; names; sources_content; mappings }
in
PP.check f;
Expand Down
Loading

0 comments on commit ffb084c

Please sign in to comment.