diff --git a/src/res_parsetree_viewer.ml b/src/res_parsetree_viewer.ml index 94679489..a6323709 100644 --- a/src/res_parsetree_viewer.ml +++ b/src/res_parsetree_viewer.ml @@ -73,6 +73,13 @@ let processFunctionAttributes attrs = in process false false [] attrs +let hasAsyncAttribute attrs = + List.exists + (function + | {Location.txt = "res.async"}, _ -> true + | _ -> false) + attrs + let hasAwaitAttribute attrs = List.exists (function @@ -177,6 +184,17 @@ let funExpr expr = pexp_attributes = attrs; } as expr -> collect attrs [] {expr with pexp_attributes = []} + | { + pexp_desc = Pexp_fun (_, _defaultExpr, _pattern, _returnExpr); + pexp_attributes = attrs; + } as expr + when hasAsyncAttribute attrs -> + let asyncAttr = + List.filter + (fun (({txt}, _) : Parsetree.attribute) -> txt = "res.async") + attrs + in + collect asyncAttr [] {expr with pexp_attributes = []} | expr -> collect [] [] expr let processBracesAttr expr = diff --git a/tests/printer/expr/asyncAwait.res b/tests/printer/expr/asyncAwait.res index 4265a891..0e75417b 100644 --- a/tests/printer/expr/asyncAwait.res +++ b/tests/printer/expr/asyncAwait.res @@ -80,4 +80,8 @@ let _ = await {x} let _ = await { let x = 1 Js.Promise.resolve(x) -} \ No newline at end of file +} + +let _ = async x => x +let _ = async (~x) => x +let _ = async (~x, ~y) => x + y \ No newline at end of file diff --git a/tests/printer/expr/expected/asyncAwait.res.txt b/tests/printer/expr/expected/asyncAwait.res.txt index 7a8642c4..3ee34b04 100644 --- a/tests/printer/expr/expected/asyncAwait.res.txt +++ b/tests/printer/expr/expected/asyncAwait.res.txt @@ -103,3 +103,7 @@ let _ = await { let x = 1 Js.Promise.resolve(x) } + +let _ = async (x) => x +let _ = async (~x) => x +let _ = async (~x, ~y) => x + y