Skip to content

Commit 9aa8594

Browse files
committed
WIP
1 parent 067fe15 commit 9aa8594

File tree

1 file changed

+42
-26
lines changed

1 file changed

+42
-26
lines changed

jscomp/syntax/src/res_printer.ml

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,46 +2635,62 @@ 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, _) -> x.Asttypes.loc.Location.loc_ghost == false)
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+
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
26422671
in
26432672
let printedExpression =
2644-
match e.pexp_desc with
2673+
match e_fun.pexp_desc with
26452674
| Pexp_fun
26462675
( Nolabel,
26472676
None,
26482677
{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 _} )
26532679
| Pexp_construct
26542680
( {txt = Lident "Function$"},
26552681
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+
} ) ->
26642690
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
26652691
printExpressionWithComments ~state
26662692
(ParsetreeViewer.rewriteUnderscoreApply e_fun)
26672693
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])
26782694
| Pexp_fun _ | Pexp_newtype _ -> printArrow e
26792695
| Parsetree.Pexp_constant c ->
26802696
printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c

0 commit comments

Comments
 (0)