Skip to content

Commit 0506ae1

Browse files
committed
Clean up treatment of async attribute.
1 parent 6993154 commit 0506ae1

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

example-async/src/AA.res

+1-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ testFetch->addTest1("https://www.google.comsdkjdkghdsg")
9898
let withCallback =
9999
@async
100100
(. ()) => {
101-
let callback = @async (. x) => @await (x->Js.Promise.resolve) + 1
102-
callback
101+
@async (. x) => @await (x->Js.Promise.resolve) + 1
103102
}
104103

105104
let testWithCallback =

jscomp/frontend/ast_attributes.ml

+7-4
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,15 @@ let process_method_attributes_rev (attrs : t) =
8181
type attr_kind =
8282
| Nothing
8383
| Meth_callback of attr
84-
| Uncurry of attr * bool
84+
| Uncurry of attr
8585
| Method of attr
8686

8787
let process_attributes_rev (attrs : t) : attr_kind * t =
8888
Ext_list.fold_left attrs (Nothing, [])
8989
(fun (st, acc) (({ txt; loc }, _) as attr) ->
9090
match (txt, st) with
91-
| "async", Uncurry (attr, _async) -> (Uncurry (attr, true), attr :: acc)
9291
| "bs", (Nothing | Uncurry _) ->
93-
(Uncurry (attr, (* async *) false), acc) (* TODO: warn unused/duplicated attribute *)
92+
(Uncurry attr, acc) (* TODO: warn unused/duplicated attribute *)
9493
| ("bs.this" | "this"), (Nothing | Meth_callback _) ->
9594
(Meth_callback attr, acc)
9695
| ("bs.meth" | "meth"), (Nothing | Method _) -> (Method attr, acc)
@@ -166,8 +165,12 @@ let has_inline_payload (attrs : t) = Ext_list.find_first attrs is_inline
166165

167166
let is_await : attr -> bool =
168167
fun ({ txt }, _) -> txt = "await"
169-
168+
169+
let is_async : attr -> bool =
170+
fun ({ txt }, _) -> txt = "async"
171+
170172
let has_await_payload (attrs : t) = Ext_list.find_first attrs is_await
173+
let has_async_payload (attrs : t) = Ext_list.find_first attrs is_async
171174

172175

173176
type derive_attr = { bs_deriving : Ast_payload.action list option } [@@unboxed]

jscomp/frontend/ast_attributes.mli

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ val process_method_attributes_rev :
3333
type attr_kind =
3434
| Nothing
3535
| Meth_callback of attr
36-
| Uncurry of attr * bool(* async *)
36+
| Uncurry of attr
3737
| Method of attr
3838

3939
val process_attributes_rev : t -> attr_kind * t
@@ -45,6 +45,7 @@ val process_bs : t -> bool * t
4545
val has_inline_payload : t -> attr option
4646

4747
val has_await_payload : t -> attr option
48+
val has_async_payload : t -> attr option
4849

4950
type derive_attr = { bs_deriving : Ast_payload.action list option } [@@unboxed]
5051

jscomp/frontend/ast_core_type_class_type.ml

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
147147
let attrs, core_type =
148148
match Ast_attributes.process_attributes_rev attrs with
149149
| Nothing, attrs -> (attrs, ty) (* #1678 *)
150-
| Uncurry (attr, _async), attrs -> (attrs, attr +> ty)
150+
| Uncurry attr, attrs -> (attrs, attr +> ty)
151151
| Method _, _ ->
152152
Location.raise_errorf ~loc
153153
"%@get/set conflicts with %@meth"
@@ -160,7 +160,7 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
160160
let attrs, core_type =
161161
match Ast_attributes.process_attributes_rev attrs with
162162
| Nothing, attrs -> (attrs, ty)
163-
| Uncurry (attr, _async), attrs -> (attrs, attr +> ty)
163+
| Uncurry attr, attrs -> (attrs, attr +> ty)
164164
| Method _, _ ->
165165
Location.raise_errorf ~loc
166166
"%@get/set conflicts with %@meth"
@@ -174,7 +174,7 @@ let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
174174
let attrs, core_type =
175175
match Ast_attributes.process_attributes_rev ptyp_attrs with
176176
| Nothing, attrs -> (attrs, ty)
177-
| Uncurry (attr, _async), attrs -> (attrs, attr +> ty)
177+
| Uncurry attr, attrs -> (attrs, attr +> ty)
178178
| Method attr, attrs -> (attrs, attr +> ty)
179179
| Meth_callback attr, attrs -> (attrs, attr +> ty)
180180
in

jscomp/frontend/bs_builtin_ppx.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ let expr_mapper (self : mapper) (e : Parsetree.expression) =
125125
begin match Ast_attributes.process_attributes_rev e.pexp_attributes with
126126
| Nothing, _
127127
-> default_expr_mapper self e
128-
| Uncurry (_, async), pexp_attributes
128+
| Uncurry (_, _async), pexp_attributes
129129
->
130+
let async = Ast_attributes.has_async_payload e.pexp_attributes <> None in
130131
{e with
131132
pexp_desc = Ast_uncurry_gen.to_uncurry_fn e.pexp_loc self label pat body async;
132133
pexp_attributes}

0 commit comments

Comments
 (0)