gen_js_api
gen_js_api copied to clipboard
Conversion functions not included in module signature
Input (.ml
file):
include [%js:
module M: sig
type t
end
]
Generates (simplified):
include (
struct
module M = struct
type t = Ojs.t
let rec (t_of_js : Ojs.t -> t) = fun x2 -> x2
and (t_to_js : t -> Ojs.t) = fun x1 -> x1
end
end :
sig
module M : sig
type t
end
end )
One has to include the conversion functions t_of_js
and t_to_js
manually on the signature, which is quite tedious. Maybe gen_js_api could include them as well there?
Yes I known it's tedious but currently [%js: ] behaves like the standalone tool; it does not rewrite the signature at all (ie. interfaces are not preprocessed: you could compile the .mli without preprocessing it and it should be a valid interface for the generated structure).
This design decision was taken a long time ago because it was convenient to integrate with ancient build systems.
With the advent of dune this maybe its time to change that (in particular, this may be needed to support ppxlib).
We could do a quick fix for the [%js: extension] but I prefer to wait at least for the ppxlib integration to take a decision.