Skip to content

Commit c957bfb

Browse files
Compiler: Decode sourcemap mappings only when necessary (#1664)
1 parent 613cbcc commit c957bfb

File tree

8 files changed

+230
-189
lines changed

8 files changed

+230
-189
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Misc: yojson is no longer optional
77
* Compiler: speedup global_flow/global_deadcode pass on large bytecode
88
* Compiler: speedup json parsing, relying on Yojson.Raw (#1640)
9+
* Compiler: Decode sourcemap mappings only when necessary (#1664)
910
* Compiler: make indirect call using sequence instead of using the call method
1011
[f.call(null, args)] becomes [(0,f)(args)]
1112
* Runtime: change Sys.os_type on windows (Cygwin -> Win32)

compiler/bin-js_of_ocaml/cmd_arg.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ let options =
314314
; sources = []
315315
; sources_content = (if sourcemap_don't_inline_content then None else Some [])
316316
; names = []
317-
; mappings = []
317+
; mappings = Source_map.Mappings.empty
318318
} )
319319
else None
320320
in
@@ -543,7 +543,7 @@ let options_runtime_only =
543543
; sources = []
544544
; sources_content = (if sourcemap_don't_inline_content then None else Some [])
545545
; names = []
546-
; mappings = []
546+
; mappings = Source_map.Mappings.empty
547547
} )
548548
else None
549549
in

compiler/bin-js_of_ocaml/link.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ let options =
108108
; sources = []
109109
; sources_content = Some []
110110
; names = []
111-
; mappings = []
111+
; mappings = Source_map.Mappings.empty
112112
} )
113113
else None
114114
in

compiler/lib/js_output.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,8 +1996,9 @@ let program ?(accept_unnamed_var = false) f ?source_map p =
19961996
| None -> filename
19971997
| Some _ -> Filename.concat "/builtin" filename)
19981998
in
1999+
let sm_mappings = Source_map.Mappings.decode sm.mappings in
19992000
let mappings =
2000-
List.rev_append_map !temp_mappings sm.mappings ~f:(fun (pos, m) ->
2001+
List.rev_append_map !temp_mappings sm_mappings ~f:(fun (pos, m) ->
20012002
let gen_line = pos.PP.p_line + 1 in
20022003
let gen_col = pos.PP.p_col in
20032004
match m with
@@ -2012,6 +2013,7 @@ let program ?(accept_unnamed_var = false) f ?source_map p =
20122013
Source_map.Gen_Ori_Name
20132014
{ gen_line; gen_col; ori_source; ori_line; ori_col; ori_name })
20142015
in
2016+
let mappings = Source_map.Mappings.encode mappings in
20152017
Some { sm with Source_map.sources; names; sources_content; mappings }
20162018
in
20172019
PP.check f;

0 commit comments

Comments
 (0)