@@ -2635,46 +2635,62 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
2635
2635
Doc. concat [Doc. text " : " ; typDoc]
2636
2636
| _ -> Doc. nil
2637
2637
in
2638
+ let nonGhostAttrs =
2639
+ List. filter
2640
+ (fun (x , _ ) -> x.Asttypes. loc.Location. loc_ghost == false )
2641
+ attrs
2642
+ in
2638
2643
let attrs = printAttributes ~state attrs cmtTbl in
2639
- Doc. group
2640
- (Doc. concat
2641
- [attrs; parametersDoc; typConstraintDoc; Doc. text " =>" ; returnExprDoc])
2644
+ match nonGhostAttrs with
2645
+ | [] ->
2646
+ Doc. group
2647
+ (Doc. concat
2648
+ [
2649
+ attrs;
2650
+ parametersDoc;
2651
+ typConstraintDoc;
2652
+ Doc. text " =>" ;
2653
+ returnExprDoc;
2654
+ ])
2655
+ | _ ->
2656
+ Doc. group
2657
+ (Doc. concat
2658
+ [
2659
+ attrs;
2660
+ Doc. lparen;
2661
+ parametersDoc;
2662
+ typConstraintDoc;
2663
+ Doc. text " =>" ;
2664
+ returnExprDoc;
2665
+ Doc. rparen;
2666
+ ])
2667
+ in
2668
+ let uncurried = Ast_uncurried. exprIsUncurriedFun e in
2669
+ let e_fun =
2670
+ if uncurried then Ast_uncurried. exprExtractUncurriedFun e else e
2642
2671
in
2643
2672
let printedExpression =
2644
- match e .pexp_desc with
2673
+ match e_fun .pexp_desc with
2645
2674
| Pexp_fun
2646
2675
( Nolabel ,
2647
2676
None ,
2648
2677
{ppat_desc = Ppat_var {txt = " __x" }},
2649
- {pexp_desc = Pexp_apply _} ) ->
2650
- printExpressionWithComments ~state
2651
- (ParsetreeViewer. rewriteUnderscoreApply e)
2652
- cmtTbl
2678
+ {pexp_desc = Pexp_apply _} )
2653
2679
| Pexp_construct
2654
2680
( {txt = Lident " Function$" },
2655
2681
Some
2656
- ( {
2657
- pexp_desc =
2658
- Pexp_fun
2659
- ( Nolabel ,
2660
- None ,
2661
- {ppat_desc = Ppat_var {txt = " __x" }},
2662
- {pexp_desc = Pexp_apply _} );
2663
- } as e_fun) ) ->
2682
+ {
2683
+ pexp_desc =
2684
+ Pexp_fun
2685
+ ( Nolabel ,
2686
+ None ,
2687
+ {ppat_desc = Ppat_var {txt = " __x" }},
2688
+ {pexp_desc = Pexp_apply _} );
2689
+ } ) ->
2664
2690
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
2665
2691
printExpressionWithComments ~state
2666
2692
(ParsetreeViewer. rewriteUnderscoreApply e_fun)
2667
2693
cmtTbl
2668
- | Pexp_construct ({txt = Lident "Function$" } , Some expr ) -> (
2669
- let nonGhostAttrs =
2670
- List. filter
2671
- (fun (x , _ ) -> x.Asttypes. loc.Location. loc_ghost == false )
2672
- e.pexp_attributes
2673
- in
2674
- let doc = printExpressionWithComments ~state expr cmtTbl in
2675
- match nonGhostAttrs with
2676
- | [] -> doc
2677
- | _attrs -> Doc. concat [Doc. lparen; doc; Doc. rparen])
2678
2694
| Pexp_fun _ | Pexp_newtype _ -> printArrow e
2679
2695
| Parsetree. Pexp_constant c ->
2680
2696
printConstant ~template Literal:(ParsetreeViewer. isTemplateLiteral e) c
0 commit comments