Skip to content

Commit cb499d0

Browse files
committed
WIP
1 parent 067fe15 commit cb499d0

File tree

1 file changed

+43
-26
lines changed

1 file changed

+43
-26
lines changed

jscomp/syntax/src/res_printer.ml

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,46 +2635,63 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
26352635
Doc.concat [Doc.text ": "; typDoc]
26362636
| _ -> Doc.nil
26372637
in
2638+
let nonGhostAttrs =
2639+
List.filter
2640+
(fun (x, _) -> not x.Asttypes.loc.Location.loc_ghost)
2641+
attrs
2642+
in
26382643
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
26422672
in
26432673
let printedExpression =
2644-
match e.pexp_desc with
2674+
match e_fun.pexp_desc with
26452675
| Pexp_fun
26462676
( Nolabel,
26472677
None,
26482678
{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 _} )
26532680
| Pexp_construct
26542681
( {txt = Lident "Function$"},
26552682
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+
} ) ->
26642691
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
26652692
printExpressionWithComments ~state
26662693
(ParsetreeViewer.rewriteUnderscoreApply e_fun)
26672694
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])
26782695
| Pexp_fun _ | Pexp_newtype _ -> printArrow e
26792696
| Parsetree.Pexp_constant c ->
26802697
printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c

0 commit comments

Comments
 (0)