26
26
`jsoo_refmt_main` is the JSOO compilation entry point for building BuckleScript + Refmt as one bundle.
27
27
This is usually the file you want to build for the full playground experience.
28
28
*)
29
- module Js = struct
30
- module Unsafe = struct
31
- type any
32
- external inject : 'a -> any = "%identity"
33
- external get : 'a -> 'b -> 'c = "caml_js_get"
34
- external set : 'a -> 'b -> 'c -> unit = "caml_js_set"
35
- external pure_js_expr : string -> 'a = "caml_pure_js_expr"
36
- let global = pure_js_expr " joo_global_object"
37
- type obj
38
- external obj : (string * any ) array -> obj = "caml_js_object"
39
- end
40
- type (-'a, +'b) meth_callback
41
- type 'a callback = (unit , 'a ) meth_callback
42
- external wrap_callback : ('a -> 'b ) -> ('c , 'a -> 'b ) meth_callback = "caml_js_wrap_callback"
43
- external wrap_meth_callback : ('a -> 'b ) -> ('a , 'b ) meth_callback = "caml_js_wrap_meth_callback"
44
- type + 'a t
45
- type js_string
46
- external string : string -> js_string t = "caml_js_from_string"
47
- external to_string : js_string t -> string = "caml_js_to_string"
48
- external create_file : js_string t -> js_string t -> unit = "caml_create_file"
49
- external to_bytestring : js_string t -> string = "caml_js_to_byte_string"
50
- end
51
-
52
-
53
- (*
54
- Error:
55
- * {
56
- * row: 12,
57
- * column: 2, //can be undefined
58
- * text: "Missing argument",
59
- * type: "error" // or "warning" or "info"
60
- * }
61
- *)
62
- let mk_js_error loc msg =
63
- let (file,line,startchar) = Location. get_pos_info loc.Location. loc_start in
64
- let (file,endline,endchar) = Location. get_pos_info loc.Location. loc_end in
65
- Js.Unsafe. (obj
66
- [|
67
- " js_error_msg" ,
68
- inject @@ Js. string (Printf. sprintf " Line %d, %d:\n %s" line startchar msg);
69
- " row" , inject (line - 1 );
70
- " column" , inject startchar;
71
- " endRow" , inject (endline - 1 );
72
- " endColumn" , inject endchar;
73
- " text" , inject @@ Js. string msg;
74
- " type" , inject @@ Js. string " error"
75
- |]
76
- )
29
+
30
+ module Js = Jsoo_common. Js
77
31
78
32
let () =
79
33
Bs_conditional_initial. setup_env () ;
@@ -147,13 +101,13 @@ let implementation ~use_super_errors ?(react_ppx_version=V3) ?prefix impl str :
147
101
begin match error_of_exn e with
148
102
| Some error ->
149
103
Location. report_error Format. err_formatter error;
150
- mk_js_error error.loc error.msg
104
+ Jsoo_common. mk_js_error error.loc error.msg
151
105
| None ->
152
106
let msg = Printexc. to_string e in
153
107
match e with
154
108
| Refmt_api.Migrate_parsetree.Def. Migration_error (_,loc)
155
109
| Refmt_api.Reason_errors. Reason_error (_ ,loc ) ->
156
- mk_js_error loc msg
110
+ Jsoo_common. mk_js_error loc msg
157
111
| _ ->
158
112
Js.Unsafe. (obj [|
159
113
" js_error_msg" , inject @@ Js. string msg;
@@ -168,15 +122,11 @@ let compile impl ~use_super_errors ?react_ppx_version =
168
122
let shake_compile impl ~use_super_errors ?react_ppx_version prefix =
169
123
implementation ~use_super_errors ?react_ppx_version ~prefix impl
170
124
171
-
172
-
173
125
let load_module cmi_path cmi_content cmj_name cmj_content =
174
126
Js. create_file cmi_path cmi_content;
175
127
Js_cmj_datasets. data_sets :=
176
128
String_map. add ! Js_cmj_datasets. data_sets
177
129
cmj_name (lazy (Js_cmj_format. from_string cmj_content))
178
-
179
-
180
130
181
131
let export (field : string ) v =
182
132
Js.Unsafe. set (Js.Unsafe. global) field v
@@ -187,7 +137,6 @@ let export (field : string) v =
187
137
let dir_directory d =
188
138
Config. load_path := d :: ! Config. load_path
189
139
190
-
191
140
let () =
192
141
dir_directory " /static/cmis"
193
142
@@ -243,8 +192,6 @@ let make_compiler name impl prefix =
243
192
let () = make_compiler " ocaml" Parse. implementation " [@@@bs.config{no_export}]\n #1 \" repl.ml\"\n "
244
193
let () = make_compiler " reason" reason_parse " [@bs.config {no_export: no_export}];\n #1 \" repl.re\" ;\n "
245
194
246
- let _ = 1
247
-
248
195
(* local variables: *)
249
196
(* compile-command: "ocamlbuild -use-ocamlfind -pkg compiler-libs -no-hygiene driver.cmo" *)
250
197
(* end: *)
0 commit comments