@@ -250,23 +250,82 @@ end
250250module M = struct
251251 (* Value expressions for the module language *)
252252
253- let map sub {pmod_loc = loc ; pmod_desc = desc ; pmod_attributes = attrs } =
254- let open Mod in
253+ let rec map sub ({Parsetree0. pmod_loc = loc ; pmod_desc = desc ; pmod_attributes = attrs } : Parsetree0.module_expr ) =
255254 let loc = sub.location sub loc in
256255 let attrs = sub.attributes sub attrs in
256+ let has_await_attribute =
257+ List. exists (fun (attr : Parsetree.attribute ) ->
258+ match attr with
259+ | ({Location. txt = "res.await" } , _ ) -> true
260+ | _ -> false
261+ ) attrs
262+ in
263+ let attrs_without_await =
264+ List. filter (fun (attr : Parsetree.attribute ) ->
265+ match attr with
266+ | ({Location. txt = "res.await" } , _ ) -> false
267+ | _ -> true
268+ ) attrs
269+ in
257270 match desc with
258- | Pmod_ident x -> ident ~loc ~attrs (map_loc sub x)
259- | Pmod_structure str -> structure ~loc ~attrs (sub.structure sub str)
260- | Pmod_functor (arg , arg_ty , body ) ->
261- functor_ ~loc ~attrs (map_loc sub arg)
262- (Misc. may_map (sub.module_type sub) arg_ty)
263- (sub.module_expr sub body)
264- | Pmod_apply (m1 , m2 ) ->
265- apply ~loc ~attrs (sub.module_expr sub m1) (sub.module_expr sub m2)
266- | Pmod_constraint (m , mty ) ->
267- constraint_ ~loc ~attrs (sub.module_expr sub m) (sub.module_type sub mty)
268- | Pmod_unpack e -> unpack ~loc ~attrs (sub.expr sub e)
269- | Pmod_extension x -> extension ~loc ~attrs (sub.extension sub x)
271+ | Parsetree0. Pmod_ident x when has_await_attribute ->
272+ let inner_mod = {
273+ Parsetree. pmod_loc = loc;
274+ pmod_desc = Parsetree. Pmod_ident (map_loc sub x);
275+ pmod_attributes = []
276+ } in
277+ {
278+ Parsetree. pmod_loc = loc;
279+ pmod_desc = Parsetree. Pmod_await inner_mod;
280+ pmod_attributes = attrs_without_await
281+ }
282+ | Parsetree0. Pmod_ident x ->
283+ {
284+ Parsetree. pmod_loc = loc;
285+ pmod_desc = Parsetree. Pmod_ident (map_loc sub x);
286+ pmod_attributes = attrs
287+ }
288+ | Parsetree0. Pmod_structure s ->
289+ {
290+ Parsetree. pmod_loc = loc;
291+ pmod_desc = Parsetree. Pmod_structure (sub.structure sub s);
292+ pmod_attributes = attrs
293+ }
294+ | Parsetree0. Pmod_functor (arg , arg_type , body ) ->
295+ {
296+ Parsetree. pmod_loc = loc;
297+ pmod_desc = Parsetree. Pmod_functor (
298+ map_loc sub arg,
299+ Option. map (sub.module_type sub) arg_type,
300+ map sub body
301+ );
302+ pmod_attributes = attrs
303+ }
304+ | Parsetree0. Pmod_apply (me1 , me2 ) ->
305+ {
306+ Parsetree. pmod_loc = loc;
307+ pmod_desc = Parsetree. Pmod_apply (map sub me1, map sub me2);
308+ pmod_attributes = attrs
309+ }
310+ | Parsetree0. Pmod_constraint (me , mt ) ->
311+ {
312+ Parsetree. pmod_loc = loc;
313+ pmod_desc = Parsetree. Pmod_constraint (map sub me, sub.module_type sub mt);
314+ pmod_attributes = attrs
315+ }
316+ | Parsetree0. Pmod_unpack e ->
317+ {
318+ Parsetree. pmod_loc = loc;
319+ pmod_desc = Parsetree. Pmod_unpack (sub.expr sub e);
320+ pmod_attributes = attrs
321+ }
322+ | Parsetree0. Pmod_extension x ->
323+ {
324+ Parsetree. pmod_loc = loc;
325+ pmod_desc = Parsetree. Pmod_extension (sub.extension sub x);
326+ pmod_attributes = attrs
327+ }
328+ | _ -> assert false
270329
271330 let map_structure_item sub {pstr_loc = loc ; pstr_desc = desc } =
272331 let open Str in
0 commit comments