@@ -49434,7 +49434,7 @@ val processBsAttribute : Parsetree.attributes -> bool * Parsetree.attributes
49434
49434
49435
49435
type functionAttributesInfo = {
49436
49436
async: bool;
49437
- uncurried : bool;
49437
+ bs : bool;
49438
49438
attributes: Parsetree.attributes;
49439
49439
}
49440
49440
@@ -49470,7 +49470,7 @@ type funParamKind =
49470
49470
49471
49471
val funExpr :
49472
49472
Parsetree.expression ->
49473
- Parsetree.attributes * funParamKind list * Parsetree.expression
49473
+ bool * Parsetree.attributes * funParamKind list * Parsetree.expression
49474
49474
49475
49475
(* example:
49476
49476
* `makeCoordinate({
@@ -49570,6 +49570,8 @@ val hasIfLetAttribute : Parsetree.attributes -> bool
49570
49570
49571
49571
val isRewrittenUnderscoreApplySugar : Parsetree.expression -> bool
49572
49572
49573
+ val isFunNewtype : Parsetree.expression_desc -> bool
49574
+
49573
49575
end = struct
49574
49576
#1 "res_parsetree_viewer.ml"
49575
49577
open Parsetree
@@ -49633,18 +49635,17 @@ let processBsAttribute attrs =
49633
49635
49634
49636
type functionAttributesInfo = {
49635
49637
async: bool;
49636
- uncurried : bool;
49638
+ bs : bool;
49637
49639
attributes: Parsetree.attributes;
49638
49640
}
49639
49641
49640
49642
let processFunctionAttributes attrs =
49641
- let rec process async uncurried acc attrs =
49643
+ let rec process async bs acc attrs =
49642
49644
match attrs with
49643
- | [] -> {async; uncurried ; attributes = List.rev acc}
49645
+ | [] -> {async; bs ; attributes = List.rev acc}
49644
49646
| ({Location.txt = "bs"}, _) :: rest -> process async true acc rest
49645
- | ({Location.txt = "res.async"}, _) :: rest ->
49646
- process true uncurried acc rest
49647
- | attr :: rest -> process async uncurried (attr :: acc) rest
49647
+ | ({Location.txt = "res.async"}, _) :: rest -> process true bs acc rest
49648
+ | attr :: rest -> process async bs (attr :: acc) rest
49648
49649
in
49649
49650
process false false [] attrs
49650
49651
@@ -49711,7 +49712,7 @@ let funExpr expr =
49711
49712
collectNewTypes (stringLoc :: acc) returnExpr
49712
49713
| returnExpr -> (List.rev acc, returnExpr)
49713
49714
in
49714
- let rec collect attrsBefore acc expr =
49715
+ let rec collect ~uncurried attrsBefore acc expr =
49715
49716
match expr with
49716
49717
| {
49717
49718
pexp_desc =
@@ -49721,29 +49722,33 @@ let funExpr expr =
49721
49722
{ppat_desc = Ppat_var {txt = "__x"}},
49722
49723
{pexp_desc = Pexp_apply _} );
49723
49724
} ->
49724
- (attrsBefore, List.rev acc, rewriteUnderscoreApply expr)
49725
+ (uncurried, attrsBefore, List.rev acc, rewriteUnderscoreApply expr)
49725
49726
| {pexp_desc = Pexp_newtype (stringLoc, rest); pexp_attributes = attrs} ->
49726
49727
let stringLocs, returnExpr = collectNewTypes [stringLoc] rest in
49727
49728
let param = NewTypes {attrs; locs = stringLocs} in
49728
- collect attrsBefore (param :: acc) returnExpr
49729
+ collect ~uncurried attrsBefore (param :: acc) returnExpr
49729
49730
| {
49730
49731
pexp_desc = Pexp_fun (lbl, defaultExpr, pattern, returnExpr);
49731
49732
pexp_attributes = [];
49732
49733
} ->
49733
49734
let parameter = Parameter {attrs = []; lbl; defaultExpr; pat = pattern} in
49734
- collect attrsBefore (parameter :: acc) returnExpr
49735
+ collect ~uncurried attrsBefore (parameter :: acc) returnExpr
49735
49736
(* If a fun has an attribute, then it stops here and makes currying.
49736
49737
i.e attributes outside of (...), uncurried `(.)` and `async` make currying *)
49737
- | {pexp_desc = Pexp_fun _} -> (attrsBefore, List.rev acc, expr)
49738
- | expr -> (attrsBefore, List.rev acc, expr)
49738
+ | {pexp_desc = Pexp_fun _} -> (uncurried, attrsBefore, List.rev acc, expr)
49739
+ | expr -> (uncurried, attrsBefore, List.rev acc, expr)
49739
49740
in
49740
49741
match expr with
49742
+ | {pexp_desc = Pexp_fun _} ->
49743
+ collect ~uncurried:false expr.pexp_attributes []
49744
+ {expr with pexp_attributes = []}
49741
49745
| {
49742
- pexp_desc = Pexp_fun (_, _defaultExpr, _pattern, _returnExpr);
49743
- pexp_attributes = attrs;
49744
- } as expr ->
49745
- collect attrs [] {expr with pexp_attributes = []}
49746
- | expr -> collect [] [] expr
49746
+ pexp_desc =
49747
+ Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, expr)], None);
49748
+ } ->
49749
+ collect ~uncurried:true expr.pexp_attributes []
49750
+ {expr with pexp_attributes = []}
49751
+ | _ -> collect ~uncurried:false [] [] expr
49747
49752
49748
49753
let processBracesAttr expr =
49749
49754
match expr.pexp_attributes with
@@ -50102,12 +50107,19 @@ let filterPrintableAttributes attrs = List.filter isPrintableAttribute attrs
50102
50107
let partitionPrintableAttributes attrs =
50103
50108
List.partition isPrintableAttribute attrs
50104
50109
50110
+ let isFunNewtype = function
50111
+ | Pexp_fun _ | Pexp_newtype _ -> true
50112
+ | Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), name)}, _)], None)
50113
+ when String.length name >= 1 && name.[0] = 'I' ->
50114
+ true
50115
+ | _ -> false
50116
+
50105
50117
let requiresSpecialCallbackPrintingLastArg args =
50106
50118
let rec loop args =
50107
50119
match args with
50108
50120
| [] -> false
50109
- | [(_, {pexp_desc = Pexp_fun _ | Pexp_newtype _ })] -> true
50110
- | (_, {pexp_desc = Pexp_fun _ | Pexp_newtype _ }) :: _ -> false
50121
+ | [(_, {pexp_desc})] when isFunNewtype pexp_desc -> true
50122
+ | (_, {pexp_desc}) :: _ when isFunNewtype pexp_desc -> false
50111
50123
| _ :: rest -> loop rest
50112
50124
in
50113
50125
loop args
@@ -50116,12 +50128,12 @@ let requiresSpecialCallbackPrintingFirstArg args =
50116
50128
let rec loop args =
50117
50129
match args with
50118
50130
| [] -> true
50119
- | (_, {pexp_desc = Pexp_fun _ | Pexp_newtype _ }) :: _ -> false
50131
+ | (_, {pexp_desc}) :: _ when isFunNewtype pexp_desc -> false
50120
50132
| _ :: rest -> loop rest
50121
50133
in
50122
50134
match args with
50123
- | [(_, {pexp_desc = Pexp_fun _ | Pexp_newtype _ })] -> false
50124
- | (_, {pexp_desc = Pexp_fun _ | Pexp_newtype _ }) :: rest -> loop rest
50135
+ | [(_, {pexp_desc})] when isFunNewtype pexp_desc -> false
50136
+ | (_, {pexp_desc}) :: rest when isFunNewtype pexp_desc -> loop rest
50125
50137
| _ -> false
50126
50138
50127
50139
let modExprApply modExpr =
@@ -52489,8 +52501,8 @@ let ternaryOperand expr =
52489
52501
} ->
52490
52502
Nothing
52491
52503
| {pexp_desc = Pexp_constraint _} -> Parenthesized
52492
- | {pexp_desc = Pexp_fun _ | Pexp_newtype _} -> (
52493
- let _attrsOnArrow, _parameters, returnExpr =
52504
+ | {pexp_desc} when Res_parsetree_viewer.isFunNewtype pexp_desc -> (
52505
+ let _uncurried, _attrsOnArrow, _parameters, returnExpr =
52494
52506
ParsetreeViewer.funExpr expr
52495
52507
in
52496
52508
match returnExpr.pexp_desc with
@@ -54648,7 +54660,6 @@ and printLabelDeclaration ~state (ld : Parsetree.label_declaration) cmtTbl =
54648
54660
54649
54661
and printTypExpr ~state (typExpr : Parsetree.core_type) cmtTbl =
54650
54662
let printArrow ~uncurried ?(arity = max_int) typExpr =
54651
- (* XXX *)
54652
54663
let attrsBefore, args, returnType =
54653
54664
ParsetreeViewer.arrowType ~arity typExpr
54654
54665
in
@@ -55065,7 +55076,9 @@ and printValueBinding ~state ~recFlag (vb : Parsetree.value_binding) cmtTbl i =
55065
55076
};
55066
55077
pvb_expr = {pexp_desc = Pexp_newtype _} as expr;
55067
55078
} -> (
55068
- let _attrs, parameters, returnExpr = ParsetreeViewer.funExpr expr in
55079
+ let _uncurried, _attrs, parameters, returnExpr =
55080
+ ParsetreeViewer.funExpr expr
55081
+ in
55069
55082
let abstractType =
55070
55083
match parameters with
55071
55084
| [NewTypes {locs = vars}] ->
@@ -55703,12 +55716,14 @@ and printIfChain ~state pexp_attributes ifs elseExpr cmtTbl =
55703
55716
Doc.concat [printAttributes ~state attrs cmtTbl; ifDocs; elseDoc]
55704
55717
55705
55718
and printExpression ~state (e : Parsetree.expression) cmtTbl =
55706
- let printArrow ~isUncurried e =
55707
- let attrsOnArrow, parameters, returnExpr = ParsetreeViewer.funExpr e in
55708
- let ParsetreeViewer.{async; uncurried; attributes = attrs} =
55719
+ let printArrow e =
55720
+ let uncurried, attrsOnArrow, parameters, returnExpr =
55721
+ ParsetreeViewer.funExpr e
55722
+ in
55723
+ let ParsetreeViewer.{async; bs; attributes = attrs} =
55709
55724
ParsetreeViewer.processFunctionAttributes attrsOnArrow
55710
55725
in
55711
- let uncurried = uncurried || isUncurried in
55726
+ let uncurried = uncurried || bs in
55712
55727
let returnExpr, typConstraint =
55713
55728
match returnExpr.pexp_desc with
55714
55729
| Pexp_constraint (expr, typ) ->
@@ -56033,11 +56048,15 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
56033
56048
printExpressionWithComments ~state
56034
56049
(ParsetreeViewer.rewriteUnderscoreApply e)
56035
56050
cmtTbl
56036
- | Pexp_fun _ | Pexp_newtype _ -> printArrow ~isUncurried:false e
56051
+ | Pexp_fun _
56037
56052
| Pexp_record
56038
- ([({txt = Ldot (Ldot (Lident "Js", "Fn"), name)}, funExpr)], None)
56039
- when String.length name >= 1 && name.[0] = 'I' ->
56040
- printArrow ~isUncurried:true funExpr
56053
+ ( [
56054
+ ( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
56055
+ {pexp_desc = Pexp_fun _} );
56056
+ ],
56057
+ None )
56058
+ | Pexp_newtype _ ->
56059
+ printArrow e
56041
56060
| Pexp_record (rows, spreadExpr) ->
56042
56061
if rows = [] then
56043
56062
Doc.concat
@@ -56411,10 +56430,13 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
56411
56430
| _ -> exprWithAwait
56412
56431
56413
56432
and printPexpFun ~state ~inCallback e cmtTbl =
56414
- let attrsOnArrow, parameters, returnExpr = ParsetreeViewer.funExpr e in
56415
- let ParsetreeViewer.{async; uncurried; attributes = attrs} =
56433
+ let uncurried, attrsOnArrow, parameters, returnExpr =
56434
+ ParsetreeViewer.funExpr e
56435
+ in
56436
+ let ParsetreeViewer.{async; bs; attributes = attrs} =
56416
56437
ParsetreeViewer.processFunctionAttributes attrsOnArrow
56417
56438
in
56439
+ let uncurried = bs || uncurried in
56418
56440
let returnExpr, typConstraint =
56419
56441
match returnExpr.pexp_desc with
56420
56442
| Pexp_constraint (expr, typ) ->
0 commit comments