Skip to content

Commit a2c61c7

Browse files
Simplify dev playground api
1 parent 070e753 commit a2c61c7

3 files changed

Lines changed: 14 additions & 36 deletions

File tree

compiler/jsoo/jsoo_playground_main.ml

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
* modules in the playground.
5252
* v5: Removed .ml support.
5353
* v6: Added `config.experimental_features` and `config.jsx_preserve_mode` to the BundleConfig.
54-
* v7: Added opt-in debug dump output APIs for developer playground tooling.
54+
* v7: Added debug dump output APIs for developer playground tooling.
5555
* *)
5656
let api_version = "7"
5757

@@ -315,23 +315,6 @@ module Printer = struct
315315
(Printtyp.tree_of_type_declaration (Ident.create name) decl rec_status))
316316
end
317317

318-
module DebugOutput = struct
319-
type t = ParseTree | TypedTree | Lambda | Lam
320-
321-
let from_string = function
322-
| "parsetree" -> Some ParseTree
323-
| "typedtree" -> Some TypedTree
324-
| "lambda" -> Some Lambda
325-
| "lam" -> Some Lam
326-
| _ -> None
327-
328-
let from_js_array value =
329-
value |> Js.to_array |> Array.to_list
330-
|> List.filter_map (fun item -> from_string (Js.to_string item))
331-
332-
let has output outputs = List.exists (fun item -> item = output) outputs
333-
end
334-
335318
module Compile = struct
336319
(* Apparently it's not possible to retrieve the loc info from
337320
* Location.error_of_exn properly, so we need to do some extra
@@ -496,7 +479,8 @@ module Compile = struct
496479
| Some value -> Js.Unsafe.[|(name, inject @@ Js.string value)|]
497480
| None -> [||]
498481

499-
let implementation ?(debug_outputs = []) ~(config : BundleConfig.t) ~lang str
482+
let implementation ?(include_debug_outputs = false)
483+
~(config : BundleConfig.t) ~lang str
500484
=
501485
let {
502486
BundleConfig.module_system;
@@ -531,7 +515,7 @@ module Compile = struct
531515
let ast = impl str in
532516
let ast = Ppx_entry.rewrite_implementation ast in
533517
let debug_parsetree =
534-
if DebugOutput.has DebugOutput.ParseTree debug_outputs then
518+
if include_debug_outputs then
535519
Some (Printer.to_string Printast.implementation ast)
536520
else None
537521
in
@@ -545,7 +529,7 @@ module Compile = struct
545529
(a, b)
546530
in
547531
let debug_typedtree =
548-
if DebugOutput.has DebugOutput.TypedTree debug_outputs then
532+
if include_debug_outputs then
549533
Some
550534
(Printer.to_string Printtyped.implementation_with_coercion
551535
typed_tree)
@@ -554,12 +538,12 @@ module Compile = struct
554538
typed_tree |> Translmod.transl_implementation modulename
555539
|> fun (lambda, exports) ->
556540
let debug_lambda =
557-
if DebugOutput.has DebugOutput.Lambda debug_outputs then
541+
if include_debug_outputs then
558542
Some (Printer.to_string Printlambda.lambda lambda)
559543
else None
560544
in
561545
let debug_lam =
562-
if DebugOutput.has DebugOutput.Lam debug_outputs then
546+
if include_debug_outputs then
563547
let export_ident_sets = Set_ident.of_list exports in
564548
let lam, _ = Lam_convert.convert export_ident_sets lambda in
565549
Some (Lam_print.lambda_to_string lam)
@@ -644,10 +628,9 @@ module Export = struct
644628
Compile.implementation ~config ~lang (Js.to_string code)) );
645629
( "compileWithDebug",
646630
inject
647-
@@ Js.wrap_meth_callback (fun _ code debug_outputs ->
648-
Compile.implementation
649-
~debug_outputs:(DebugOutput.from_js_array debug_outputs)
650-
~config ~lang (Js.to_string code)) );
631+
@@ Js.wrap_meth_callback (fun _ code ->
632+
Compile.implementation ~include_debug_outputs:true ~config
633+
~lang (Js.to_string code)) );
651634
("version", inject @@ Js.string Bs_version.version);
652635
|]
653636
in

docs/dev-playground.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Implemented:
2323
- `make dev-playground-build` verifies the local staged bundle and frontend production build.
2424
- `compiler/jsoo/jsoo_playground_main.ml` exposes additive API version `7`.
2525
- `rescript.compile(source)` stays compatible with the existing end-user playground.
26-
- `rescript.compileWithDebug(source, outputs)` exposes requested internal artifacts for the developer playground.
26+
- `rescript.compileWithDebug(source)` exposes internal artifacts for the developer playground.
2727
- The local playground supports source editing, line numbers, lightweight ReScript highlighting, output tabs, settings, URL state, and loading the current checkout's compiler bundle through `playground-bundles/local`.
2828

2929
This follow-up adds the master-only GitHub Pages deployment:
@@ -155,8 +155,8 @@ Introduce an API version bump in `compiler/jsoo/jsoo_playground_main.ml`.
155155
The initial v7 API should stay additive:
156156

157157
- Keep `rescript.compile(source)` unchanged for the end-user playground and existing CDN bundles.
158-
- Add `rescript.compileWithDebug(source, outputs)` for developer tooling.
159-
- Return the same success/error shape as `compile`, plus only the requested debug output string fields.
158+
- Add `rescript.compileWithDebug(source)` for developer tooling.
159+
- Return the same success/error shape as `compile`, plus all debug output string fields.
160160

161161
This keeps `rescript-lang.org/try` compatible while allowing the developer playground to feature-detect `api_version >= 7`.
162162

packages/dev-playground/src/CompilerRuntime.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,7 @@ export async function compile(source, config) {
265265

266266
const start = performance.now();
267267
const result = hasFunction(instance.rescript, "compileWithDebug")
268-
? instance.rescript.compileWithDebug(source, [
269-
"parsetree",
270-
"typedtree",
271-
"lambda",
272-
"lam",
273-
])
268+
? instance.rescript.compileWithDebug(source)
274269
: instance.rescript.compile(source);
275270
const elapsedMs = performance.now() - start;
276271

0 commit comments

Comments
 (0)