Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 046d1e3

Browse files
author
Maxim
committed
Extract printing of "async " in a helper
1 parent 702d586 commit 046d1e3

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/res_printer.ml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ let addBraces doc =
7979
Doc.rbrace;
8080
])
8181

82+
let addAsync doc = Doc.concat [Doc.text "async "; doc]
83+
8284
let getFirstLeadingComment tbl loc =
8385
match Hashtbl.find tbl.CommentTable.leading loc with
8486
| comment :: _ -> Some comment
@@ -4597,7 +4599,7 @@ and printExprFunParameters ~customLayout ~inCallback ~async ~uncurried
45974599
let doc = if hasConstraint then Doc.text "(_)" else Doc.text "_" in
45984600
printComments doc cmtTbl ppat_loc
45994601
in
4600-
if async then Doc.concat [Doc.text "async "; any] else any
4602+
if async then addAsync any else any
46014603
(* let f = a => () *)
46024604
| [
46034605
ParsetreeViewer.Parameter
@@ -4612,7 +4614,7 @@ and printExprFunParameters ~customLayout ~inCallback ~async ~uncurried
46124614
let txtDoc =
46134615
let var = printIdentLike stringLoc.txt in
46144616
let var = if hasConstraint then addParens var else var in
4615-
if async then Doc.concat [Doc.text "async ("; var; Doc.rparen] else var
4617+
if async then addAsync (Doc.concat [Doc.lparen; var; Doc.rparen]) else var
46164618
in
46174619
printComments txtDoc cmtTbl stringLoc.loc
46184620
(* let f = () => () *)
@@ -4627,7 +4629,10 @@ and printExprFunParameters ~customLayout ~inCallback ~async ~uncurried
46274629
};
46284630
]
46294631
when not uncurried ->
4630-
let doc = if async then Doc.text "async ()" else Doc.text "()" in
4632+
let doc =
4633+
let lparenRparen = Doc.text "()" in
4634+
if async then addAsync lparenRparen else lparenRparen
4635+
in
46314636
printComments doc cmtTbl loc
46324637
(* let f = (~greeting, ~from as hometown, ~x=?) => () *)
46334638
| parameters ->
@@ -4637,11 +4642,8 @@ and printExprFunParameters ~customLayout ~inCallback ~async ~uncurried
46374642
| _ -> false
46384643
in
46394644
let maybeAsyncLparen =
4640-
match (async, uncurried) with
4641-
| true, true -> Doc.text "async (. "
4642-
| true, false -> Doc.text "async ("
4643-
| false, true -> Doc.text "(. "
4644-
| false, false -> Doc.lparen
4645+
let lparen = if uncurried then Doc.text "(. " else Doc.lparen in
4646+
if async then addAsync lparen else lparen
46454647
in
46464648
let shouldHug = ParsetreeViewer.parametersShouldHug parameters in
46474649
let printedParamaters =

0 commit comments

Comments
 (0)