Registering an attribute transformation with ppxlib

I want to register a rewriter for ppxlib that matches expressions like this:

([@JSX] div ~children:[] ())

Generally it should match any expression with a [@JSX] attribute. The payload is always empty.

Is there an API to do this conveniently? The only one that’s documented is the Extension one.

Doesn’t look like there’s any “canonical” way to do this yet like there is for extensions, but the most convenient is to inherit from and override the #expression method:

let map_exprs = object
  inherit as super

  method! expression expr =
    let expr = super#expression expr in
    if contains_jsx expr.pexp_attributes then
      (* do the transform *)

And then register the transformation with ~impl and ~intf:

let () =
1 Like