@@ -1903,10 +1903,10 @@ let program ?(accept_unnamed_var = false) f ?source_map p =
1903
1903
let temp_mappings = ref [] in
1904
1904
let files = Hashtbl. create 17 in
1905
1905
let names = Hashtbl. create 17 in
1906
- let contents : string option list ref option =
1906
+ let contents : Source_map.Source_text.t list ref option =
1907
1907
match source_map with
1908
- | None | Some { Source_map. sources_content = None ; _ } -> None
1909
- | Some { Source_map. sources_content = Some _ ; _ } -> Some (ref [] )
1908
+ | None | Some { Source_map. sources_contents = None ; _ } -> None
1909
+ | Some { Source_map. sources_contents = Some _ ; _ } -> Some (ref [] )
1910
1910
in
1911
1911
let push_mapping, get_file_index, get_name_index, source_map_enabled =
1912
1912
let source_map_enabled =
@@ -1918,27 +1918,28 @@ let program ?(accept_unnamed_var = false) f ?source_map p =
1918
1918
| [] , _ -> ()
1919
1919
| x :: xs , [] ->
1920
1920
Hashtbl. add files x (Hashtbl. length files);
1921
- Option. iter contents ~f: (fun r -> r := None :: ! r);
1921
+ Option. iter contents ~f: (fun r -> r := Source_map.Source_text. empty :: ! r);
1922
1922
loop xs []
1923
1923
| x :: xs , y :: ys ->
1924
1924
Hashtbl. add files x (Hashtbl. length files);
1925
1925
Option. iter contents ~f: (fun r -> r := y :: ! r);
1926
1926
loop xs ys
1927
1927
in
1928
- loop sm.sources (Option. value ~default: [] sm.sources_content );
1928
+ loop sm.sources (Option. value ~default: [] sm.sources_contents );
1929
1929
List. iter sm.Source_map. names ~f: (fun f ->
1930
1930
Hashtbl. add names f (Hashtbl. length names));
1931
1931
true
1932
1932
in
1933
1933
let find_source file =
1934
- match Builtins. find file with
1935
- | Some f -> Some (Builtins.File. content f)
1936
- | None ->
1937
- if Sys. file_exists file && not (Sys. is_directory file)
1938
- then
1939
- let content = Fs. read_file file in
1940
- Some content
1941
- else None
1934
+ Source_map.Source_text. encode
1935
+ (match Builtins. find file with
1936
+ | Some f -> Some (Builtins.File. content f)
1937
+ | None ->
1938
+ if Sys. file_exists file && not (Sys. is_directory file)
1939
+ then
1940
+ let content = Fs. read_file file in
1941
+ Some content
1942
+ else None )
1942
1943
in
1943
1944
( (fun pos m -> temp_mappings := (pos, m) :: ! temp_mappings)
1944
1945
, (fun file ->
@@ -1979,19 +1980,20 @@ let program ?(accept_unnamed_var = false) f ?source_map p =
1979
1980
| Some sm ->
1980
1981
let sources = hashtbl_to_list files in
1981
1982
let names = hashtbl_to_list names in
1982
- let sources_content =
1983
- match contents with
1984
- | None -> None
1985
- | Some r -> Some (List. rev ! r)
1983
+ let sources_contents =
1984
+ let open Option.Syntax in
1985
+ let * r = contents in
1986
+ Option. return (List. rev ! r)
1986
1987
in
1987
1988
let sources =
1988
1989
List. map sources ~f: (fun filename ->
1989
1990
match Builtins. find filename with
1990
1991
| None -> filename
1991
1992
| Some _ -> Filename. concat " /builtin" filename)
1992
1993
in
1994
+ let sm_mappings = Source_map.Mappings. decode sm.mappings in
1993
1995
let mappings =
1994
- List. rev_append_map ! temp_mappings sm.mappings ~f: (fun (pos , m ) ->
1996
+ List. rev_append_map ! temp_mappings sm_mappings ~f: (fun (pos , m ) ->
1995
1997
let gen_line = pos.PP. p_line + 1 in
1996
1998
let gen_col = pos.PP. p_col in
1997
1999
match m with
@@ -2006,7 +2008,8 @@ let program ?(accept_unnamed_var = false) f ?source_map p =
2006
2008
Source_map. Gen_Ori_Name
2007
2009
{ gen_line; gen_col; ori_source; ori_line; ori_col; ori_name })
2008
2010
in
2009
- Some { sm with Source_map. sources; names; sources_content; mappings }
2011
+ let mappings = Source_map.Mappings. encode mappings in
2012
+ Some { sm with Source_map. sources; names; sources_contents; mappings }
2010
2013
in
2011
2014
PP. check f;
2012
2015
(if stats ()
0 commit comments