@@ -49496,6 +49496,77 @@ let debug t =
49496
49496
toString ~width:10 doc |> print_endline
49497
49497
[@@live]
49498
49498
49499
+ end
49500
+ module Res_uncurried
49501
+ = struct
49502
+ #1 "res_uncurried.ml"
49503
+ type config = Legacy | Default
49504
+
49505
+ let init = Legacy
49506
+
49507
+ let isDefault = function
49508
+ | Legacy -> false
49509
+ | Default -> true
49510
+
49511
+ (* For parsing *)
49512
+ let fromDotted ~dotted = function
49513
+ | Legacy -> dotted
49514
+ | Default -> not dotted
49515
+
49516
+ (* For printing *)
49517
+ let getDotted ~uncurried = function
49518
+ | Legacy -> uncurried
49519
+ | Default -> not uncurried
49520
+
49521
+ let uncurriedType ~loc ~arity tArg =
49522
+ Ast_helper.Typ.constr ~loc
49523
+ {txt = Ldot (Ldot (Lident "Js", "Fn"), "arity" ^ string_of_int arity); loc}
49524
+ [tArg]
49525
+
49526
+ let uncurriedFun ~loc ~arity funExpr =
49527
+ Ast_helper.Exp.record ~loc
49528
+ [
49529
+ ( {txt = Ldot (Ldot (Lident "Js", "Fn"), "I" ^ string_of_int arity); loc},
49530
+ funExpr );
49531
+ ]
49532
+ None
49533
+
49534
+ let exprIsUncurriedFun (expr : Parsetree.expression) =
49535
+ match expr with
49536
+ | {
49537
+ pexp_desc =
49538
+ Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, _e)], None);
49539
+ } ->
49540
+ true
49541
+ | _ -> false
49542
+
49543
+ let exprExtractUncurriedFun (expr : Parsetree.expression) =
49544
+ match expr with
49545
+ | {
49546
+ pexp_desc =
49547
+ Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None);
49548
+ } ->
49549
+ e
49550
+ | _ -> assert false
49551
+
49552
+ let typeIsUncurriedFun (typ : Parsetree.core_type) =
49553
+ match typ.ptyp_desc with
49554
+ | Ptyp_constr
49555
+ ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [{ptyp_desc = Ptyp_arrow _}])
49556
+ ->
49557
+ true
49558
+ | _ -> false
49559
+
49560
+ let typeExtractUncurriedFun (typ : Parsetree.core_type) =
49561
+ match typ.ptyp_desc with
49562
+ | Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), arity)}, [tArg]) ->
49563
+ let arity =
49564
+ (int_of_string [@doesNotRaise])
49565
+ ((String.sub [@doesNotRaise]) arity 5 (String.length arity - 5))
49566
+ in
49567
+ (arity, tArg)
49568
+ | _ -> assert false
49569
+
49499
49570
end
49500
49571
module Res_parsetree_viewer : sig
49501
49572
#1 "res_parsetree_viewer.mli"
@@ -49659,7 +49730,7 @@ val hasIfLetAttribute : Parsetree.attributes -> bool
49659
49730
49660
49731
val isRewrittenUnderscoreApplySugar : Parsetree.expression -> bool
49661
49732
49662
- val isFunNewtype : Parsetree.expression_desc -> bool
49733
+ val isFunNewtype : Parsetree.expression -> bool
49663
49734
49664
49735
end = struct
49665
49736
#1 "res_parsetree_viewer.ml"
@@ -49841,22 +49912,17 @@ let funExpr expr =
49841
49912
(* If a fun has an attribute, then it stops here and makes currying.
49842
49913
i.e attributes outside of (...), uncurried `(.)` and `async` make currying *)
49843
49914
| {pexp_desc = Pexp_fun _} -> (uncurried, attrsBefore, List.rev acc, expr)
49844
- | {
49845
- pexp_desc =
49846
- Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, expr)], None);
49847
- }
49848
- when nFun = 0 ->
49915
+ | expr when nFun = 0 && Res_uncurried.exprIsUncurriedFun expr ->
49916
+ let expr = Res_uncurried.exprExtractUncurriedFun expr in
49849
49917
collect ~uncurried:true ~nFun attrsBefore acc expr
49850
49918
| expr -> (uncurried, attrsBefore, List.rev acc, expr)
49851
49919
in
49852
49920
match expr with
49853
49921
| {pexp_desc = Pexp_fun _} ->
49854
49922
collect ~uncurried:false ~nFun:0 expr.pexp_attributes []
49855
49923
{expr with pexp_attributes = []}
49856
- | {
49857
- pexp_desc =
49858
- Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, expr)], None);
49859
- } ->
49924
+ | _ when Res_uncurried.exprIsUncurriedFun expr ->
49925
+ let expr = Res_uncurried.exprExtractUncurriedFun expr in
49860
49926
collect ~uncurried:true ~nFun:0 expr.pexp_attributes []
49861
49927
{expr with pexp_attributes = []}
49862
49928
| _ -> collect ~uncurried:false ~nFun:0 [] [] expr
@@ -50218,19 +50284,17 @@ let filterPrintableAttributes attrs = List.filter isPrintableAttribute attrs
50218
50284
let partitionPrintableAttributes attrs =
50219
50285
List.partition isPrintableAttribute attrs
50220
50286
50221
- let isFunNewtype = function
50287
+ let isFunNewtype expr =
50288
+ match expr.pexp_desc with
50222
50289
| Pexp_fun _ | Pexp_newtype _ -> true
50223
- | Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), name)}, _)], None)
50224
- when String.length name >= 1 && (name.[0] [@doesNotRaise]) = 'I' ->
50225
- true
50226
- | _ -> false
50290
+ | _ -> Res_uncurried.exprIsUncurriedFun expr
50227
50291
50228
50292
let requiresSpecialCallbackPrintingLastArg args =
50229
50293
let rec loop args =
50230
50294
match args with
50231
50295
| [] -> false
50232
- | [(_, {pexp_desc} )] when isFunNewtype pexp_desc -> true
50233
- | (_, {pexp_desc} ) :: _ when isFunNewtype pexp_desc -> false
50296
+ | [(_, expr )] when isFunNewtype expr -> true
50297
+ | (_, expr ) :: _ when isFunNewtype expr -> false
50234
50298
| _ :: rest -> loop rest
50235
50299
in
50236
50300
loop args
@@ -50239,12 +50303,12 @@ let requiresSpecialCallbackPrintingFirstArg args =
50239
50303
let rec loop args =
50240
50304
match args with
50241
50305
| [] -> true
50242
- | (_, {pexp_desc} ) :: _ when isFunNewtype pexp_desc -> false
50306
+ | (_, expr ) :: _ when isFunNewtype expr -> false
50243
50307
| _ :: rest -> loop rest
50244
50308
in
50245
50309
match args with
50246
- | [(_, {pexp_desc} )] when isFunNewtype pexp_desc -> false
50247
- | (_, {pexp_desc} ) :: rest when isFunNewtype pexp_desc -> loop rest
50310
+ | [(_, expr )] when isFunNewtype expr -> false
50311
+ | (_, expr ) :: rest when isFunNewtype expr -> loop rest
50248
50312
| _ -> false
50249
50313
50250
50314
let modExprApply modExpr =
@@ -52612,7 +52676,7 @@ let ternaryOperand expr =
52612
52676
} ->
52613
52677
Nothing
52614
52678
| {pexp_desc = Pexp_constraint _} -> Parenthesized
52615
- | {pexp_desc} when Res_parsetree_viewer.isFunNewtype pexp_desc -> (
52679
+ | _ when Res_parsetree_viewer.isFunNewtype expr -> (
52616
52680
let _uncurried, _attrsOnArrow, _parameters, returnExpr =
52617
52681
ParsetreeViewer.funExpr expr
52618
52682
in
@@ -53029,28 +53093,6 @@ let isKeywordTxt str =
53029
53093
53030
53094
let catch = Lident "catch"
53031
53095
53032
- end
53033
- module Res_uncurried
53034
- = struct
53035
- #1 "res_uncurried.ml"
53036
- type t = Legacy | Default
53037
-
53038
- let init = Legacy
53039
-
53040
- let isDefault = function
53041
- | Legacy -> false
53042
- | Default -> true
53043
-
53044
- (* For parsing *)
53045
- let fromDotted ~dotted = function
53046
- | Legacy -> dotted
53047
- | Default -> not dotted
53048
-
53049
- (* For printing *)
53050
- let getDotted ~uncurried = function
53051
- | Legacy -> uncurried
53052
- | Default -> not uncurried
53053
-
53054
53096
end
53055
53097
module Res_utf8 : sig
53056
53098
#1 "res_utf8.mli"
@@ -53819,9 +53861,9 @@ let printOptionalLabel attrs =
53819
53861
module State = struct
53820
53862
let customLayoutThreshold = 2
53821
53863
53822
- type t = {customLayout: int; mutable res_uncurried : Res_uncurried.t }
53864
+ type t = {customLayout: int; mutable uncurried_config : Res_uncurried.config }
53823
53865
53824
- let init = {customLayout = 0; res_uncurried = Res_uncurried.init}
53866
+ let init = {customLayout = 0; uncurried_config = Res_uncurried.init}
53825
53867
53826
53868
let nextCustomLayout t = {t with customLayout = t.customLayout + 1}
53827
53869
@@ -54797,7 +54839,9 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
54797
54839
ParsetreeViewer.arrowType ~arity typExpr
54798
54840
in
54799
54841
let dotted, attrsBefore =
54800
- let dotted = state.res_uncurried |> Res_uncurried.getDotted ~uncurried in
54842
+ let dotted =
54843
+ state.uncurried_config |> Res_uncurried.getDotted ~uncurried
54844
+ in
54801
54845
(* Converting .ml code to .res requires processing uncurried attributes *)
54802
54846
let hasBs, attrs = ParsetreeViewer.processBsAttribute attrsBefore in
54803
54847
(dotted || hasBs, attrs)
@@ -54824,11 +54868,8 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
54824
54868
let typDoc =
54825
54869
let doc = printTypExpr ~state n cmtTbl in
54826
54870
match n.ptyp_desc with
54827
- | Ptyp_constr
54828
- ( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
54829
- [{ptyp_desc = Ptyp_arrow _}] )
54830
- | Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ ->
54831
- addParens doc
54871
+ | Ptyp_arrow _ | Ptyp_tuple _ | Ptyp_alias _ -> addParens doc
54872
+ | _ when Res_uncurried.typeIsUncurriedFun n -> addParens doc
54832
54873
| _ -> doc
54833
54874
in
54834
54875
Doc.group
@@ -54900,13 +54941,8 @@ and printTypExpr ~(state : State.t) (typExpr : Parsetree.core_type) cmtTbl =
54900
54941
| Ptyp_object (fields, openFlag) ->
54901
54942
printObject ~state ~inline:false fields openFlag cmtTbl
54902
54943
| Ptyp_arrow _ -> printArrow ~uncurried:false typExpr
54903
- | Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), arity)}, [tArg])
54904
- when String.length arity >= 5
54905
- && (String.sub [@doesNotRaise]) arity 0 5 = "arity" ->
54906
- let arity =
54907
- (int_of_string [@doesNotRaise])
54908
- ((String.sub [@doesNotRaise]) arity 5 (String.length arity - 5))
54909
- in
54944
+ | Ptyp_constr _ when Res_uncurried.typeIsUncurriedFun typExpr ->
54945
+ let arity, tArg = Res_uncurried.typeExtractUncurriedFun typExpr in
54910
54946
printArrow ~uncurried:true ~arity tArg
54911
54947
| Ptyp_constr (longidentLoc, [{ptyp_desc = Ptyp_object (fields, openFlag)}])
54912
54948
->
@@ -55919,6 +55955,17 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
55919
55955
in
55920
55956
let printedExpression =
55921
55957
match e.pexp_desc with
55958
+ | Pexp_fun
55959
+ ( Nolabel,
55960
+ None,
55961
+ {ppat_desc = Ppat_var {txt = "__x"}},
55962
+ {pexp_desc = Pexp_apply _} ) ->
55963
+ (* (__x) => f(a, __x, c) -----> f(a, _, c) *)
55964
+ printExpressionWithComments ~state
55965
+ (ParsetreeViewer.rewriteUnderscoreApply e)
55966
+ cmtTbl
55967
+ | _ when Res_uncurried.exprIsUncurriedFun e -> printArrow e
55968
+ | Pexp_fun _ | Pexp_newtype _ -> printArrow e
55922
55969
| Parsetree.Pexp_constant c ->
55923
55970
printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c
55924
55971
| Pexp_construct _ when ParsetreeViewer.hasJsxAttribute e.pexp_attributes ->
@@ -56165,24 +56212,6 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
56165
56212
]
56166
56213
in
56167
56214
Doc.group (Doc.concat [variantName; args])
56168
- | Pexp_fun
56169
- ( Nolabel,
56170
- None,
56171
- {ppat_desc = Ppat_var {txt = "__x"}},
56172
- {pexp_desc = Pexp_apply _} ) ->
56173
- (* (__x) => f(a, __x, c) -----> f(a, _, c) *)
56174
- printExpressionWithComments ~state
56175
- (ParsetreeViewer.rewriteUnderscoreApply e)
56176
- cmtTbl
56177
- | Pexp_fun _
56178
- | Pexp_record
56179
- ( [
56180
- ( {txt = Ldot (Ldot (Lident "Js", "Fn"), _)},
56181
- {pexp_desc = Pexp_fun _} );
56182
- ],
56183
- None )
56184
- | Pexp_newtype _ ->
56185
- printArrow e
56186
56215
| Pexp_record (rows, spreadExpr) ->
56187
56216
if rows = [] then
56188
56217
Doc.concat
@@ -57198,7 +57227,7 @@ and printPexpApply ~state expr cmtTbl =
57198
57227
let uncurried, attrs =
57199
57228
ParsetreeViewer.processUncurriedAppAttribute expr.pexp_attributes
57200
57229
in
57201
- let dotted = state.res_uncurried |> Res_uncurried.getDotted ~uncurried in
57230
+ let dotted = state.uncurried_config |> Res_uncurried.getDotted ~uncurried in
57202
57231
let callExprDoc =
57203
57232
let doc = printExpressionWithComments ~state callExpr cmtTbl in
57204
57233
match Parens.callExpr callExpr with
@@ -57973,7 +58002,7 @@ and printCase ~state (case : Parsetree.case) cmtTbl =
57973
58002
57974
58003
and printExprFunParameters ~state ~inCallback ~async ~uncurried ~hasConstraint
57975
58004
parameters cmtTbl =
57976
- let dotted = state.res_uncurried |> Res_uncurried.getDotted ~uncurried in
58005
+ let dotted = state.uncurried_config |> Res_uncurried.getDotted ~uncurried in
57977
58006
match parameters with
57978
58007
(* let f = _ => () *)
57979
58008
| [
@@ -58520,10 +58549,10 @@ and printAttribute ?(standalone = false) ~state
58520
58549
let id =
58521
58550
match id.txt with
58522
58551
| "uncurried" ->
58523
- state.res_uncurried <- Res_uncurried.Default;
58552
+ state.uncurried_config <- Res_uncurried.Default;
58524
58553
id
58525
58554
| "toUncurried" ->
58526
- state.res_uncurried <- Res_uncurried.Default;
58555
+ state.uncurried_config <- Res_uncurried.Default;
58527
58556
{id with txt = "uncurried"}
58528
58557
| _ -> id
58529
58558
in
@@ -154127,9 +154156,10 @@ let transformStructureItem ~config mapper item =
154127
154156
check_string_int_attribute_iter.structure_item
154128
154157
check_string_int_attribute_iter item;
154129
154158
let pval_type =
154130
- match pval_type.ptyp_desc with
154131
- | Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [t]) -> t
154132
- | _ -> pval_type
154159
+ if Res_uncurried.typeIsUncurriedFun pval_type then
154160
+ let _arity, t = Res_uncurried.typeExtractUncurriedFun pval_type in
154161
+ t
154162
+ else pval_type
154133
154163
in
154134
154164
let coreTypeOfAttr = React_jsx_common.coreTypeOfAttrs pval_attributes in
154135
154165
let typVarsOfCoreType =
@@ -154199,9 +154229,8 @@ let transformStructureItem ~config mapper item =
154199
154229
config.hasReactComponent <- true;
154200
154230
let rec removeArityRecord expr =
154201
154231
match expr.pexp_desc with
154202
- | Pexp_record
154203
- ([({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, e)], None) ->
154204
- e
154232
+ | _ when Res_uncurried.exprIsUncurriedFun expr ->
154233
+ Res_uncurried.exprExtractUncurriedFun expr
154205
154234
| Pexp_apply (forwardRef, [(label, e)]) ->
154206
154235
{
154207
154236
expr with
@@ -154626,9 +154655,10 @@ let transformSignatureItem ~config _mapper item =
154626
154655
React_jsx_common.raiseErrorMultipleReactComponent ~loc:psig_loc
154627
154656
else config.hasReactComponent <- true;
154628
154657
let pval_type =
154629
- match pval_type.ptyp_desc with
154630
- | Ptyp_constr ({txt = Ldot (Ldot (Lident "Js", "Fn"), _)}, [t]) -> t
154631
- | _ -> pval_type
154658
+ if Res_uncurried.typeIsUncurriedFun pval_type then
154659
+ let _arity, t = Res_uncurried.typeExtractUncurriedFun pval_type in
154660
+ t
154661
+ else pval_type
154632
154662
in
154633
154663
check_string_int_attribute_iter.signature_item
154634
154664
check_string_int_attribute_iter item;
0 commit comments