Skip to content

Commit 593f9bd

Browse files
vouillonhhugo
authored andcommitted
ppx_optcomp_light: conditional inclusion of modules in signatures
1 parent 77f3f78 commit 593f9bd

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

compiler/ppx/ppx_optcomp_light.ml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
]}
2525
on module (Pstr_module),
2626
toplevel bindings (Pstr_value, Pstr_primitive)
27-
and pattern in case (pc_lhs)
27+
pattern in case (pc_lhs)
28+
and module in signature (Psig_module)
2829
*)
2930

3031
open StdLabels
@@ -296,7 +297,21 @@ let traverse =
296297
| Some pattern -> Some { case with pc_lhs = pattern })
297298
in
298299
super#cases cases
300+
301+
method! signature_item item =
302+
match item.psig_desc with
303+
| Psig_module { pmd_attributes; pmd_loc; _ } ->
304+
if keep pmd_loc pmd_attributes
305+
then item
306+
else
307+
let open Ppxlib.Ast_builder.Default in
308+
let loc = Location.none in
309+
psig_include ~loc (include_infos ~loc (pmty_signature ~loc []))
310+
| _ -> item
299311
end
300312

301313
let () =
302-
Ppxlib.Driver.register_transformation ~impl:traverse#structure "ppx_optcomp_light"
314+
Ppxlib.Driver.register_transformation
315+
~impl:traverse#structure
316+
~intf:traverse#signature
317+
"ppx_optcomp_light"

0 commit comments

Comments
 (0)