Skip to content
js_of_ocaml custom syntax extension
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is a fork of the pa_js syntax extension of js_of_ocaml. The official source tree is here. The original file is here.

This version contains a custom syntax extension to express Javascript object literals, that is used by ocaml-extjs.


class type js_class = object
  method p1 : Js.js_string Js.t Js.prop
  method p2 : bool Js.t Js.prop

let obj : js_class Js.t = {|
  p1 = Js.string "string property";
  p2 = Js._true;

is expanded to:

let obj : js_class Js.t =
  Js.Unsafe.obj [|
    ("p1", Js.Unsafe.inject (Js.string "string property"));
    ("p2", Js.Unsafe.inject Js._true);

and properties p1 and p2 are also type checked with respect to their arguments. So that, for example:

let obj : js_class Js.t = {|
  p1 = Js._true;
  p2 = Js.string "string property";

won't compile.


This feature was inspired by Jacques Garrigue's OO syntax extension.

Something went wrong with that request. Please try again.