Skip to content

Commit d2e3864

Browse files
authored
[Playground] activate super-errors (#2695)
* [Playground] activate super-errors RFC. Feedback welcome. cc @bobzhang Huge quality improvement for the online experience. This activates color (needed, otherwise it's a wall of white text). I use a small lib to parse the raw ANSI color escape chars into html styles. It'd not look good in the BS playground currently. This doesn't activate Reason syntax for outcome printer, since it's compiling ocaml. * Add dep in makefile * Make it into an option jsoo doesn't support variadic functions, so instead of exposing an optional toggle on the function, I'm exposing two new functions
1 parent 74ac5bc commit d2e3864

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

jscomp/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ bin/jsoo_reactjs_jsx_ppx_v2.ml:./bin/reactjs_jsx_ppx_v2.bspp.ml ../lib/bspp.exe
559559
BS_COMPILER_IN_BROWSER=true ../lib/bspp.exe $^ > $@
560560

561561
bin/js_compiler.ml:./bin/bspack.exe
562-
./bin/bspack.exe -D BS_COMPILER_IN_BROWSER=true -U BS_DEBUG -bs-MD -module-alias Config=Config_whole_compiler -bs-exclude-I config -o $@ -bs-main Jsoo_main -I $(OCAML_SRC_UTILS) -I $(OCAML_SRC_PARSING) -I $(OCAML_SRC_TYPING) -I $(OCAML_SRC_BYTECOMP) -I $(OCAML_SRC_DRIVER) -I stubs -I ext -I syntax -I depends -I common -I core -I outcome_printer
562+
./bin/bspack.exe -D BS_COMPILER_IN_BROWSER=true -U BS_DEBUG -bs-MD -module-alias Config=Config_whole_compiler -bs-exclude-I config -o $@ -bs-main Jsoo_main -I $(OCAML_SRC_UTILS) -I $(OCAML_SRC_PARSING) -I $(OCAML_SRC_TYPING) -I $(OCAML_SRC_BYTECOMP) -I $(OCAML_SRC_DRIVER) -I stubs -I ext -I syntax -I depends -I common -I core -I super_errors -I outcome_printer
563563

564564
bin/all_ounit_tests.ml:./bin/bspack.exe
565565
$< -bs-MD -I ounit -I ounit_tests -I stubs -I bsb -I common -I ext -I syntax -I depends -I bspp -I core -bs-main Ounit_tests_main -o $@

jscomp/core/jsoo_main.ml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let () =
6565
Clflags.unsafe_string := false;
6666
Clflags.record_event_when_debug := false
6767

68-
let implementation prefix impl str : Js.Unsafe.obj =
68+
let implementation ~use_super_errors prefix impl str : Js.Unsafe.obj =
6969
let modulename = "Test" in
7070
(* let env = !Toploop.toplevel_env in *)
7171
(* Compmisc.init_path false; *)
@@ -99,6 +99,10 @@ let implementation prefix impl str : Js.Unsafe.obj =
9999
(* Format.fprintf output_ppf {| { "js_code" : %S }|} v ) *)
100100
with
101101
| e ->
102+
if use_super_errors then begin
103+
Misc.Color.setup Clflags.Always;
104+
Super_main.setup ();
105+
end;
102106
begin match Location.error_of_exn e with
103107
| Some error ->
104108
Location.report_error Format.std_formatter error;
@@ -107,7 +111,7 @@ let implementation prefix impl str : Js.Unsafe.obj =
107111
Js.Unsafe.(obj
108112
[|
109113
"js_error_msg",
110-
inject @@ Js.string (Printf.sprintf "Line %d, %d: %s" line startchar error.msg);
114+
inject @@ Js.string (Printf.sprintf "Line %d, %d:\n %s" line startchar error.msg);
111115
"row" , inject (line - 1);
112116
"column" , inject startchar;
113117
"endRow" , inject (endline - 1);
@@ -125,14 +129,12 @@ let implementation prefix impl str : Js.Unsafe.obj =
125129
end
126130

127131

132+
let compile impl ~use_super_errors =
133+
implementation ~use_super_errors false impl
128134

129-
let compile impl : string -> Js.Unsafe.obj =
130-
implementation false impl
131135
(** TODO: add `[@@bs.config{no_export}]\n# 1 "repl.ml"`*)
132-
let shake_compile impl : string -> Js.Unsafe.obj =
133-
implementation true impl
134-
135-
136+
let shake_compile impl ~use_super_errors =
137+
implementation ~use_super_errors true impl
136138

137139

138140

@@ -157,21 +159,28 @@ let dir_directory d =
157159
let () =
158160
dir_directory "/static/cmis"
159161

160-
161-
162162
let make_compiler name impl =
163163
export name
164164
(Js.Unsafe.(obj
165165
[|"compile",
166166
inject @@
167167
Js.wrap_meth_callback
168168
(fun _ code ->
169-
(compile impl (Js.to_string code)));
169+
(compile impl ~use_super_errors:false (Js.to_string code)));
170170
"shake_compile",
171171
inject @@
172172
Js.wrap_meth_callback
173173
(fun _ code ->
174-
(shake_compile impl (Js.to_string code)));
174+
(shake_compile impl ~use_super_errors:false (Js.to_string code)));
175+
"compile_super_errors",
176+
inject @@
177+
Js.wrap_meth_callback
178+
(fun _ code ->
179+
(compile impl ~use_super_errors:true (Js.to_string code)));
180+
"shake_compile_super_errors",
181+
inject @@
182+
Js.wrap_meth_callback
183+
(fun _ code -> (shake_compile impl ~use_super_errors:true (Js.to_string code)));
175184
"version", Js.Unsafe.inject (Js.string (Bs_version.version));
176185
"load_module",
177186
inject @@

0 commit comments

Comments
 (0)