Skip to content

Commit 5601292

Browse files
committed
WIP
1 parent 067fe15 commit 5601292

File tree

1 file changed

+41
-22
lines changed

1 file changed

+41
-22
lines changed

jscomp/syntax/src/res_printer.ml

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,13 +2635,42 @@ 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,
@@ -2653,28 +2682,18 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
26532682
| Pexp_construct
26542683
( {txt = Lident "Function$"},
26552684
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) ) ->
2685+
{
2686+
pexp_desc =
2687+
Pexp_fun
2688+
( Nolabel,
2689+
None,
2690+
{ppat_desc = Ppat_var {txt = "__x"}},
2691+
{pexp_desc = Pexp_apply _} );
2692+
} ) ->
26642693
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
26652694
printExpressionWithComments ~state
26662695
(ParsetreeViewer.rewriteUnderscoreApply e_fun)
26672696
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])
26782697
| Pexp_fun _ | Pexp_newtype _ -> printArrow e
26792698
| Parsetree.Pexp_constant c ->
26802699
printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c

0 commit comments

Comments
 (0)