1- let is_async : Parsetree.attribute -> bool =
2- fun ({txt} , _ ) -> txt = " async" || txt = " res.async"
1+ let is_async : Parsetree.attribute -> bool = fun ({txt} , _ ) -> txt = " res.async"
2+
3+ let has_async_payload attrs = Ext_list. exists attrs is_async
4+
5+ let make_async_attr loc = (Location. mkloc " res.async" loc, Parsetree. PStr [] )
6+
7+ let add_async_attribute ~async (body : Parsetree.expression ) =
8+ if async then
9+ {
10+ body with
11+ pexp_attributes =
12+ ({txt = " res.async" ; loc = Location. none}, PStr [] )
13+ :: body.pexp_attributes;
14+ }
15+ else body
16+
17+ let extract_async_attribute attrs =
18+ let rec process async acc attrs =
19+ match attrs with
20+ | [] -> (async, List. rev acc)
21+ | ({Location. txt = "res.async" } , _ ) :: rest -> process true acc rest
22+ | attr :: rest -> process async (attr :: acc) rest
23+ in
24+ process false [] attrs
325
426let add_promise_type ?(loc = Location. none) ~async
527 (result : Parsetree.expression ) =
@@ -11,33 +33,6 @@ let add_promise_type ?(loc = Location.none) ~async
1133 Ast_helper.Exp. apply ~loc unsafe_async [(Nolabel , result)]
1234 else result
1335
14- let add_async_attribute ~async (body : Parsetree.expression ) =
15- if async then
16- match body.pexp_desc with
17- | Pexp_construct (x, Some e) when Ast_uncurried. expr_is_uncurried_fun body
18- ->
19- {
20- body with
21- pexp_desc =
22- Pexp_construct
23- ( x,
24- Some
25- {
26- e with
27- pexp_attributes =
28- ({txt = " res.async" ; loc = Location. none}, PStr [] )
29- :: e.pexp_attributes;
30- } );
31- }
32- | _ ->
33- {
34- body with
35- pexp_attributes =
36- ({txt = " res.async" ; loc = Location. none}, PStr [] )
37- :: body.pexp_attributes;
38- }
39- else body
40-
4136let rec add_promise_to_result ~loc (e : Parsetree.expression ) =
4237 match e.pexp_desc with
4338 | Pexp_fun f ->
0 commit comments