@@ -85,6 +85,19 @@ let get_mapper ~config =
8585 | 4 -> module_binding4 mapper mb
8686 | _ -> default_mapper.module_binding mapper mb
8787 in
88+ let module_expr mapper me =
89+ match (config.version, me.pmod_desc) with
90+ | 4 , Pmod_functor _ -> (
91+ config.functor_depth < - config.functor_depth + 1 ;
92+ try
93+ let m = default_mapper.module_expr mapper me in
94+ config.functor_depth < - config.functor_depth - 1 ;
95+ m
96+ with e ->
97+ config.functor_depth < - config.functor_depth - 1 ;
98+ raise e)
99+ | _ -> default_mapper.module_expr mapper me
100+ in
88101 let save_config () =
89102 {
90103 config with
@@ -142,7 +155,7 @@ let get_mapper ~config =
142155 result
143156 in
144157
145- {default_mapper with expr; module_binding; signature; structure}
158+ {default_mapper with expr; module_binding; module_expr; signature; structure}
146159
147160let rewrite_implementation ~jsx_version ~jsx_module (code : Parsetree.structure )
148161 : Parsetree.structure =
@@ -154,6 +167,7 @@ let rewrite_implementation ~jsx_version ~jsx_module (code : Parsetree.structure)
154167 has_component = false ;
155168 hoisted_structure_items = [] ;
156169 structure_depth = 0 ;
170+ functor_depth = 0 ;
157171 }
158172 in
159173 let mapper = get_mapper ~config in
@@ -169,6 +183,7 @@ let rewrite_signature ~jsx_version ~jsx_module (code : Parsetree.signature) :
169183 has_component = false ;
170184 hoisted_structure_items = [] ;
171185 structure_depth = 0 ;
186+ functor_depth = 0 ;
172187 }
173188 in
174189 let mapper = get_mapper ~config in
0 commit comments