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