56
56
* type: "error" // or "warning" or "info"
57
57
* }
58
58
*)
59
- let mk_js_error loc msg =
60
- let (file,line,startchar) = Location. get_pos_info loc.Location. loc_start in
61
- let (file,endline,endchar) = Location. get_pos_info loc.Location. loc_end in
62
- Js.Unsafe. (obj
63
- [|
64
- " js_error_msg" ,
65
- inject @@ Js. string (Printf. sprintf " Line %d, %d:\n %s" line startchar msg);
66
- " row" , inject (line - 1 );
67
- " column" , inject startchar;
68
- " endRow" , inject (endline - 1 );
69
- " endColumn" , inject endchar;
70
- " text" , inject @@ Js. string msg;
71
- " type" , inject @@ Js. string " error"
72
- |]
73
- )
74
-
75
59
let () =
76
60
Bs_conditional_initial. setup_env () ;
77
61
Clflags. binary_annotations := false
@@ -88,7 +72,7 @@ let error_of_exn e =
88
72
89
73
type react_ppx_version = V2 | V3
90
74
91
- let implementation ~use_super_errors ?(react_ppx_version =V3 ) ? prefix impl str : Js.Unsafe.obj =
75
+ let implementation ~use_super_errors ?(react_ppx_version =V3 ) prefix impl str : Js.Unsafe.obj =
92
76
let modulename = " Test" in
93
77
(* let env = !Toploop.toplevel_env in *)
94
78
(* Compmisc.init_path false; *)
@@ -107,10 +91,9 @@ let implementation ~use_super_errors ?(react_ppx_version=V3) ?prefix impl str :
107
91
Warnings. parse_options false Bsb_warning. default_warning;
108
92
109
93
try
110
- let code = match prefix with
111
- | None -> str
112
- | Some (prefix ) -> prefix ^ str in
113
- let ast = impl (Lexing. from_string code) in
94
+ let ast = impl
95
+ (Lexing. from_string
96
+ (if prefix then " [@@@bs.config{no_export}]\n #1 \" repl.ml\"\n " ^ str else str )) in
114
97
let ast = match react_ppx_version with
115
98
| V2 -> Reactjs_jsx_ppx_v2. rewrite_implementation ast
116
99
| V3 -> Reactjs_jsx_ppx_v3. rewrite_implementation ast in
@@ -141,29 +124,38 @@ let implementation ~use_super_errors ?(react_ppx_version=V3) ?prefix impl str :
141
124
(* Format.fprintf output_ppf {| { "js_code" : %S }|} v ) *)
142
125
with
143
126
| e ->
144
- begin match error_of_exn e with
127
+ begin match error_of_exn e with
145
128
| Some error ->
146
- Location. report_error Format. err_formatter error;
147
- mk_js_error error.loc error.msg
129
+ Location. report_error Format. err_formatter error;
130
+ let (file,line,startchar) = Location. get_pos_info error.loc.loc_start in
131
+ let (file,endline,endchar) = Location. get_pos_info error.loc.loc_end in
132
+ Js.Unsafe. (obj
133
+ [|
134
+ " js_error_msg" ,
135
+ inject @@ Js. string (Printf. sprintf " Line %d, %d:\n %s" line startchar error.msg);
136
+ " row" , inject (line - 1 );
137
+ " column" , inject startchar;
138
+ " endRow" , inject (endline - 1 );
139
+ " endColumn" , inject endchar;
140
+ " text" , inject @@ Js. string error.msg;
141
+ " type" , inject @@ Js. string " error"
142
+ |]
143
+ );
144
+
148
145
| None ->
149
- let msg = Printexc. to_string e in
150
- match e with
151
- | Refmt_api.Migrate_parsetree.Def. Migration_error (_,loc)
152
- | Refmt_api.Reason_errors. Reason_error (_ ,loc ) ->
153
- mk_js_error loc msg
154
- | _ ->
155
- Js.Unsafe. (obj [|
156
- " js_error_msg" , inject @@ Js. string msg;
157
- " type" , inject @@ Js. string " error"
158
- |])
146
+ Js.Unsafe. (obj [|
147
+ " js_error_msg" , inject @@ Js. string (Printexc. to_string e)
148
+ |])
149
+
159
150
end
160
151
161
152
162
153
let compile impl ~use_super_errors ?react_ppx_version =
163
- implementation ~use_super_errors ?react_ppx_version impl
154
+ implementation ~use_super_errors ?react_ppx_version false impl
164
155
165
- let shake_compile impl ~use_super_errors ?react_ppx_version prefix =
166
- implementation ~use_super_errors ?react_ppx_version ~prefix impl
156
+ (* * TODO: add `[@@bs.config{no_export}]\n# 1 "repl.ml"`*)
157
+ let shake_compile impl ~use_super_errors ?react_ppx_version =
158
+ implementation ~use_super_errors ?react_ppx_version true impl
167
159
168
160
169
161
@@ -188,12 +180,7 @@ let dir_directory d =
188
180
let () =
189
181
dir_directory " /static/cmis"
190
182
191
- module Converter = Refmt_api.Migrate_parsetree. Convert (Refmt_api.Migrate_parsetree. OCaml_404 )(Refmt_api.Migrate_parsetree. OCaml_406 )
192
-
193
- let reason_parse lexbuf =
194
- Refmt_api.Reason_toolchain.RE. implementation lexbuf |> Converter. copy_structure;;
195
-
196
- let make_compiler name impl prefix =
183
+ let make_compiler name impl =
197
184
export name
198
185
(Js.Unsafe. (obj
199
186
[|" compile" ,
@@ -205,7 +192,7 @@ let make_compiler name impl prefix =
205
192
inject @@
206
193
Js. wrap_meth_callback
207
194
(fun _ code ->
208
- (shake_compile impl ~use_super_errors: false (Js. to_string code) prefix ));
195
+ (shake_compile impl ~use_super_errors: false (Js. to_string code)));
209
196
" compile_super_errors" ,
210
197
inject @@
211
198
Js. wrap_meth_callback
@@ -224,8 +211,8 @@ let make_compiler name impl prefix =
224
211
" shake_compile_super_errors" ,
225
212
inject @@
226
213
Js. wrap_meth_callback
227
- (fun _ code -> (shake_compile impl ~use_super_errors: true (Js. to_string code) prefix ));
228
- " version" , Js.Unsafe. inject (Js. string (match name with | "reason" -> Refmt_api. version | _ -> Bs_version. version));
214
+ (fun _ code -> (shake_compile impl ~use_super_errors: true (Js. to_string code)));
215
+ " version" , Js.Unsafe. inject (Js. string (Bs_version. version));
229
216
" load_module" ,
230
217
inject @@
231
218
Js. wrap_meth_callback
@@ -236,9 +223,7 @@ let make_compiler name impl prefix =
236
223
Js.Unsafe. set cmj_bytestring " t" 9 ;
237
224
load_module cmi_path cmi_content (Js. to_string cmj_name) cmj_bytestring);
238
225
|]))
239
-
240
- let () = make_compiler " ocaml" Parse. implementation " [@@@bs.config{no_export}]\n #1 \" repl.ml\"\n "
241
- let () = make_compiler " reason" reason_parse " [@bs.config {no_export: no_export}];\n #1 \" repl.re\" ;\n "
226
+ let () = make_compiler " ocaml" Parse. implementation
242
227
243
228
(* local variables: *)
244
229
(* compile-command: "ocamlbuild -use-ocamlfind -pkg compiler-libs -no-hygiene driver.cmo" *)
0 commit comments