@@ -49806,7 +49806,7 @@ let funExpr expr =
49806
49806
collectNewTypes (stringLoc :: acc) returnExpr
49807
49807
| returnExpr -> (List.rev acc, returnExpr)
49808
49808
in
49809
- let rec collect ~uncurried attrsBefore acc expr =
49809
+ let rec collect ~uncurried ~nFun attrsBefore acc expr =
49810
49810
match expr with
49811
49811
| {
49812
49812
pexp_desc =
@@ -49820,29 +49820,36 @@ let funExpr expr =
49820
49820
| {pexp_desc = Pexp_newtype (stringLoc, rest); pexp_attributes = attrs} ->
49821
49821
let stringLocs, returnExpr = collectNewTypes [stringLoc] rest in
49822
49822
let param = NewTypes {attrs; locs = stringLocs} in
49823
- collect ~uncurried attrsBefore (param :: acc) returnExpr
49823
+ collect ~uncurried ~nFun attrsBefore (param :: acc) returnExpr
49824
49824
| {
49825
49825
pexp_desc = Pexp_fun (lbl, defaultExpr, pattern, returnExpr);
49826
49826
pexp_attributes = [];
49827
49827
} ->
49828
49828
let parameter = Parameter {attrs = []; lbl; defaultExpr; pat = pattern} in
49829
- collect ~uncurried attrsBefore (parameter :: acc) returnExpr
49829
+ collect ~uncurried ~nFun:(nFun + 1) attrsBefore (parameter :: acc)
49830
+ returnExpr
49830
49831
(* If a fun has an attribute, then it stops here and makes currying.
49831
49832
i.e attributes outside of (...), uncurried `(.)` and `async` make currying *)
49832
49833
| {pexp_desc = Pexp_fun _} -> (uncurried, attrsBefore, List.rev acc, expr)
49834
+ | {
49835
+ pexp_desc =
49836
+ Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, expr)], None);
49837
+ }
49838
+ when nFun = 0 ->
49839
+ collect ~uncurried:true ~nFun attrsBefore acc expr
49833
49840
| expr -> (uncurried, attrsBefore, List.rev acc, expr)
49834
49841
in
49835
49842
match expr with
49836
49843
| {pexp_desc = Pexp_fun _} ->
49837
- collect ~uncurried:false expr.pexp_attributes []
49844
+ collect ~uncurried:false ~nFun:0 expr.pexp_attributes []
49838
49845
{expr with pexp_attributes = []}
49839
49846
| {
49840
49847
pexp_desc =
49841
49848
Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, expr)], None);
49842
49849
} ->
49843
- collect ~uncurried:true expr.pexp_attributes []
49850
+ collect ~uncurried:true ~nFun:0 expr.pexp_attributes []
49844
49851
{expr with pexp_attributes = []}
49845
- | _ -> collect ~uncurried:false [] [] expr
49852
+ | _ -> collect ~uncurried:false ~nFun:0 [] [] expr
49846
49853
49847
49854
let processBracesAttr expr =
49848
49855
match expr.pexp_attributes with
@@ -58043,6 +58050,7 @@ and printExpFunParameter ~state parameter cmtTbl =
58043
58050
[
58044
58051
printAttributes ~state attrs cmtTbl;
58045
58052
Doc.text "type ";
58053
+ (* XX *)
58046
58054
Doc.join ~sep:Doc.space
58047
58055
(List.map
58048
58056
(fun lbl ->
@@ -163461,31 +163469,34 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context
163461
163469
| None -> parseParameters p
163462
163470
in
163463
163471
let parameters =
163472
+ let updateAttrs attrs = arrowAttrs @ attrs in
163473
+ let updatePos pos =
163474
+ match arrowStartPos with
163475
+ | Some startPos -> startPos
163476
+ | None -> pos
163477
+ in
163464
163478
match parameters with
163465
163479
| TermParameter p :: rest ->
163466
- TermParameter
163467
- {
163468
- p with
163469
- attrs = arrowAttrs @ p.attrs;
163470
- pos =
163471
- (match arrowStartPos with
163472
- | Some startPos -> startPos
163473
- | None -> p.pos);
163474
- }
163480
+ TermParameter {p with attrs = updateAttrs p.attrs; pos = updatePos p.pos}
163475
163481
:: rest
163476
163482
| TypeParameter p :: rest ->
163477
- TypeParameter
163478
- {
163479
- p with
163480
- attrs = arrowAttrs @ p.attrs;
163481
- pos =
163482
- (match arrowStartPos with
163483
- | Some startPos -> startPos
163484
- | None -> p.pos);
163485
- }
163483
+ TypeParameter {p with attrs = updateAttrs p.attrs; pos = updatePos p.pos}
163486
163484
:: rest
163487
163485
| [] -> parameters
163488
163486
in
163487
+ let parameters =
163488
+ (* Propagate any dots from type parameters to the first term *)
163489
+ let rec loop ~dotInType params =
163490
+ match params with
163491
+ | (TypeParameter {dotted} as p) :: rest ->
163492
+ p :: loop ~dotInType:(dotInType || dotted) rest
163493
+ | TermParameter termParam :: rest ->
163494
+ TermParameter {termParam with dotted = dotInType || termParam.dotted}
163495
+ :: rest
163496
+ | [] -> []
163497
+ in
163498
+ loop ~dotInType:false parameters
163499
+ in
163489
163500
let returnType =
163490
163501
match p.Parser.token with
163491
163502
| Colon ->
@@ -163505,13 +163516,19 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context
163505
163516
in
163506
163517
Parser.eatBreadcrumb p;
163507
163518
let endPos = p.prevEndPos in
163519
+ let termParameters =
163520
+ parameters
163521
+ |> List.filter (function
163522
+ | TermParameter _ -> true
163523
+ | TypeParameter _ -> false)
163524
+ in
163508
163525
let bodyNeedsBraces =
163509
163526
let isFun =
163510
163527
match body.pexp_desc with
163511
163528
| Pexp_fun _ -> true
163512
163529
| _ -> false
163513
163530
in
163514
- match parameters with
163531
+ match termParameters with
163515
163532
| TermParameter {dotted} :: _
163516
163533
when (if p.uncurried_by_default then not dotted else dotted) && isFun ->
163517
163534
true
@@ -163532,7 +163549,7 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context
163532
163549
in
163533
163550
let _paramNum, arrowExpr, _arity =
163534
163551
List.fold_right
163535
- (fun parameter (paramNum , expr, arity) ->
163552
+ (fun parameter (termParamNum , expr, arity) ->
163536
163553
match parameter with
163537
163554
| TermParameter
163538
163555
{
@@ -163550,8 +163567,8 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context
163550
163567
let uncurried =
163551
163568
if p.uncurried_by_default then not dotted else dotted
163552
163569
in
163553
- if uncurried && (paramNum = 1 || not p.uncurried_by_default) then
163554
- ( paramNum - 1,
163570
+ if uncurried && (termParamNum = 1 || not p.uncurried_by_default) then
163571
+ ( termParamNum - 1,
163555
163572
(if true then
163556
163573
Ast_helper.Exp.record ~loc
163557
163574
[
@@ -163566,17 +163583,13 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context
163566
163583
None
163567
163584
else funExpr),
163568
163585
1 )
163569
- else (paramNum - 1, funExpr, arity + 1)
163570
- | TypeParameter {dotted; attrs; locs = newtypes; pos = startPos} ->
163571
- let uncurried =
163572
- if p.uncurried_by_default then not dotted else dotted
163573
- in
163574
- let attrs = if uncurried then uncurriedAppAttr :: attrs else attrs in
163575
- ( paramNum - 1,
163586
+ else (termParamNum - 1, funExpr, arity + 1)
163587
+ | TypeParameter {dotted = _; attrs; locs = newtypes; pos = startPos} ->
163588
+ ( termParamNum,
163576
163589
makeNewtypes ~attrs ~loc:(mkLoc startPos endPos) newtypes expr,
163577
163590
arity ))
163578
163591
parameters
163579
- (List.length parameters , body, 1)
163592
+ (List.length termParameters , body, 1)
163580
163593
in
163581
163594
{arrowExpr with pexp_loc = {arrowExpr.pexp_loc with loc_start = startPos}}
163582
163595
@@ -163797,6 +163810,8 @@ and parseParameters p =
163797
163810
match parseParameterList p with
163798
163811
| TermParameter p :: rest ->
163799
163812
TermParameter {p with dotted = true; pos = startPos} :: rest
163813
+ | TypeParameter p :: rest ->
163814
+ TypeParameter {p with dotted = true; pos = startPos} :: rest
163800
163815
| parameters -> parameters))
163801
163816
| _ -> parseParameterList p)
163802
163817
| token ->
0 commit comments