Skip to content

Commit

Permalink
Compiler: Decode sourcemap mappings only when necessary (#1664)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierNicole authored Sep 4, 2024
1 parent 613cbcc commit c957bfb
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 189 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Misc: yojson is no longer optional
* Compiler: speedup global_flow/global_deadcode pass on large bytecode
* Compiler: speedup json parsing, relying on Yojson.Raw (#1640)
* Compiler: Decode sourcemap mappings only when necessary (#1664)
* Compiler: make indirect call using sequence instead of using the call method
[f.call(null, args)] becomes [(0,f)(args)]
* Runtime: change Sys.os_type on windows (Cygwin -> Win32)
Expand Down
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 c957bfb

Please sign in to comment.