@@ -49712,7 +49712,7 @@ let funExpr expr =
49712
49712
collectNewTypes (stringLoc :: acc) returnExpr
49713
49713
| returnExpr -> (List.rev acc, returnExpr)
49714
49714
in
49715
- let rec collect n attrsBefore acc expr =
49715
+ let rec collect attrsBefore acc expr =
49716
49716
match expr with
49717
49717
| {
49718
49718
pexp_desc =
@@ -49723,48 +49723,28 @@ let funExpr expr =
49723
49723
{pexp_desc = Pexp_apply _} );
49724
49724
} ->
49725
49725
(attrsBefore, List.rev acc, rewriteUnderscoreApply expr)
49726
- | {
49727
- pexp_desc = Pexp_fun (lbl, defaultExpr, pattern, returnExpr);
49728
- pexp_attributes = [];
49729
- } ->
49730
- let parameter = Parameter {attrs = []; lbl; defaultExpr; pat = pattern} in
49731
- collect (n + 1) attrsBefore (parameter :: acc) returnExpr
49732
49726
| {pexp_desc = Pexp_newtype (stringLoc, rest); pexp_attributes = attrs} ->
49733
49727
let stringLocs, returnExpr = collectNewTypes [stringLoc] rest in
49734
49728
let param = NewTypes {attrs; locs = stringLocs} in
49735
- collect (n + 1) attrsBefore (param :: acc) returnExpr
49736
- | {pexp_desc = Pexp_fun _; pexp_attributes}
49737
- when pexp_attributes
49738
- |> List.exists (fun ({Location.txt}, _) ->
49739
- txt = "bs" || txt = "res.async")
49740
- && n > 0 ->
49741
- (* stop here, the uncurried or async attribute always indicates the beginning of an arrow function
49742
- * e.g. `(. a) => (. b)` instead of `(. a, . b)` *)
49743
- (attrsBefore, List.rev acc, expr)
49729
+ collect attrsBefore (param :: acc) returnExpr
49744
49730
| {
49745
- pexp_desc =
49746
- Pexp_fun
49747
- (((Labelled _ | Optional _) as lbl), defaultExpr, pattern, returnExpr);
49748
- pexp_attributes = attrs;
49731
+ pexp_desc = Pexp_fun (lbl, defaultExpr, pattern, returnExpr);
49732
+ pexp_attributes = [];
49749
49733
} ->
49750
- (* Normally attributes are attached to the labelled argument, e.g. (@foo ~x) => ...
49751
- In the case of `@res.async`, pass the attribute to the outside *)
49752
- let attrs_async, attrs_other =
49753
- attrs |> List.partition (fun ({Location.txt}, _) -> txt = "res.async")
49754
- in
49755
- let parameter =
49756
- Parameter {attrs = attrs_other; lbl; defaultExpr; pat = pattern}
49757
- in
49758
- collect (n + 1) (attrs_async @ attrsBefore) (parameter :: acc) returnExpr
49734
+ let parameter = Parameter {attrs = []; lbl; defaultExpr; pat = pattern} in
49735
+ collect attrsBefore (parameter :: acc) returnExpr
49736
+ (* If a fun has an attribute, then it stops here and makes currying.
49737
+ i.e attributes outside of (...), uncurried `(.)` and `async` make currying *)
49738
+ | {pexp_desc = Pexp_fun _} -> (attrsBefore, List.rev acc, expr)
49759
49739
| expr -> (attrsBefore, List.rev acc, expr)
49760
49740
in
49761
49741
match expr with
49762
49742
| {
49763
- pexp_desc = Pexp_fun (Nolabel , _defaultExpr, _pattern, _returnExpr);
49743
+ pexp_desc = Pexp_fun (_ , _defaultExpr, _pattern, _returnExpr);
49764
49744
pexp_attributes = attrs;
49765
49745
} as expr ->
49766
- collect 0 attrs [] {expr with pexp_attributes = []}
49767
- | expr -> collect 0 [] [] expr
49746
+ collect attrs [] {expr with pexp_attributes = []}
49747
+ | expr -> collect [] [] expr
49768
49748
49769
49749
let processBracesAttr expr =
49770
49750
match expr.pexp_attributes with
@@ -57955,13 +57935,23 @@ and printExprFunParameters ~customLayout ~inCallback ~async ~uncurried
57955
57935
attrs = [];
57956
57936
lbl = Asttypes.Nolabel;
57957
57937
defaultExpr = None;
57958
- pat = {Parsetree.ppat_desc = Ppat_var stringLoc};
57938
+ pat =
57939
+ {
57940
+ Parsetree.ppat_desc = Ppat_var stringLoc;
57941
+ Parsetree.ppat_attributes = attrs;
57942
+ };
57959
57943
};
57960
57944
]
57961
57945
when not uncurried ->
57962
57946
let txtDoc =
57963
57947
let var = printIdentLike stringLoc.txt in
57964
- let var = if hasConstraint then addParens var else var in
57948
+ let var =
57949
+ match attrs with
57950
+ | [] -> if hasConstraint then addParens var else var
57951
+ | attrs ->
57952
+ let attrs = printAttributes ~customLayout attrs cmtTbl in
57953
+ addParens (Doc.concat [attrs; var])
57954
+ in
57965
57955
if async then addAsync var else var
57966
57956
in
57967
57957
printComments txtDoc cmtTbl stringLoc.loc
@@ -58052,22 +58042,25 @@ and printExpFunParameter ~customLayout parameter cmtTbl =
58052
58042
match (lbl, pattern) with
58053
58043
| Asttypes.Nolabel, pattern -> printPattern ~customLayout pattern cmtTbl
58054
58044
| ( (Asttypes.Labelled lbl | Optional lbl),
58055
- {
58056
- ppat_desc = Ppat_var stringLoc;
58057
- ppat_attributes = [] | [({Location.txt = "ns.namedArgLoc"}, _)];
58058
- } )
58045
+ {ppat_desc = Ppat_var stringLoc; ppat_attributes} )
58059
58046
when lbl = stringLoc.txt ->
58060
58047
(* ~d *)
58061
- Doc.concat [Doc.text "~"; printIdentLike lbl]
58048
+ Doc.concat
58049
+ [
58050
+ printAttributes ~customLayout ppat_attributes cmtTbl;
58051
+ Doc.text "~";
58052
+ printIdentLike lbl;
58053
+ ]
58062
58054
| ( (Asttypes.Labelled lbl | Optional lbl),
58063
58055
{
58064
58056
ppat_desc = Ppat_constraint ({ppat_desc = Ppat_var {txt}}, typ);
58065
- ppat_attributes = [] | [({Location.txt = "ns.namedArgLoc"}, _)] ;
58057
+ ppat_attributes;
58066
58058
} )
58067
58059
when lbl = txt ->
58068
58060
(* ~d: e *)
58069
58061
Doc.concat
58070
58062
[
58063
+ printAttributes ~customLayout ppat_attributes cmtTbl;
58071
58064
Doc.text "~";
58072
58065
printIdentLike lbl;
58073
58066
Doc.text ": ";
@@ -274988,14 +274981,15 @@ let makePropsTypeParams ?(stripExplicitOption = false)
274988
274981
274989
274982
let makeLabelDecls ~loc namedTypeList =
274990
274983
namedTypeList
274991
- |> List.map (fun (isOptional, label, _ , interiorType) ->
274984
+ |> List.map (fun (isOptional, label, attrs , interiorType) ->
274992
274985
if label = "key" then
274993
- Type.field ~loc ~attrs:optionalAttrs {txt = label; loc} interiorType
274986
+ Type.field ~loc ~attrs:(optionalAttrs @ attrs) {txt = label; loc}
274987
+ interiorType
274994
274988
else if isOptional then
274995
- Type.field ~loc ~attrs:optionalAttrs {txt = label; loc}
274989
+ Type.field ~loc ~attrs:( optionalAttrs @ attrs) {txt = label; loc}
274996
274990
(Typ.var @@ safeTypeFromValue @@ Labelled label)
274997
274991
else
274998
- Type.field ~loc {txt = label; loc}
274992
+ Type.field ~loc ~attrs {txt = label; loc}
274999
274993
(Typ.var @@ safeTypeFromValue @@ Labelled label))
275000
274994
275001
274995
let makeTypeDecls propsName loc namedTypeList =
@@ -275380,7 +275374,9 @@ let newtypeToVar newtype type_ =
275380
275374
mapper.typ mapper type_
275381
275375
275382
275376
let argToType ~newtypes ~(typeConstraints : core_type option) types
275383
- (name, default, _noLabelName, _alias, loc, type_) =
275377
+ ((name, default, {ppat_attributes = attrs}, _alias, loc, type_) :
275378
+ arg_label * expression option * pattern * label * 'loc * core_type option)
275379
+ =
275384
275380
let rec getType name coreType =
275385
275381
match coreType with
275386
275382
| {ptyp_desc = Ptyp_arrow (arg, c1, c2)} ->
@@ -275398,28 +275394,29 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types
275398
275394
in
275399
275395
match (type_, name, default) with
275400
275396
| Some type_, name, _ when isOptional name ->
275401
- (true, getLabel name, [] , {type_ with ptyp_attributes = optionalAttrs})
275397
+ (true, getLabel name, attrs , {type_ with ptyp_attributes = optionalAttrs})
275402
275398
:: types
275403
- | Some type_, name, _ -> (false, getLabel name, [] , type_) :: types
275399
+ | Some type_, name, _ -> (false, getLabel name, attrs , type_) :: types
275404
275400
| None, name, _ when isOptional name ->
275405
275401
( true,
275406
275402
getLabel name,
275407
- [] ,
275403
+ attrs ,
275408
275404
Typ.var ~loc ~attrs:optionalAttrs (safeTypeFromValue name) )
275409
275405
:: types
275410
275406
| None, name, _ when isLabelled name ->
275411
- (false, getLabel name, [], Typ.var ~loc (safeTypeFromValue name)) :: types
275407
+ (false, getLabel name, attrs, Typ.var ~loc (safeTypeFromValue name))
275408
+ :: types
275412
275409
| _ -> types
275413
275410
275414
275411
let argWithDefaultValue (name, default, _, _, _, _) =
275415
275412
match default with
275416
275413
| Some default when isOptional name -> Some (getLabel name, default)
275417
275414
| _ -> None
275418
275415
275419
- let argToConcreteType types (name, _loc, type_) =
275416
+ let argToConcreteType types (name, attrs, _loc, type_) =
275420
275417
match name with
275421
- | name when isLabelled name -> (false, getLabel name, [] , type_) :: types
275422
- | name when isOptional name -> (true, getLabel name, [] , type_) :: types
275418
+ | name when isLabelled name -> (false, getLabel name, attrs , type_) :: types
275419
+ | name when isOptional name -> (true, getLabel name, attrs , type_) :: types
275423
275420
| _ -> types
275424
275421
275425
275422
let check_string_int_attribute_iter =
@@ -275456,15 +275453,19 @@ let transformStructureItem ~config mapper item =
275456
275453
|> Option.map React_jsx_common.typVarsOfCoreType
275457
275454
|> Option.value ~default:[]
275458
275455
in
275459
- let rec getPropTypes types ({ptyp_loc; ptyp_desc} as fullType) =
275456
+ let rec getPropTypes types
275457
+ ({ptyp_loc; ptyp_desc; ptyp_attributes} as fullType) =
275460
275458
match ptyp_desc with
275461
275459
| Ptyp_arrow (name, type_, ({ptyp_desc = Ptyp_arrow _} as rest))
275462
275460
when isLabelled name || isOptional name ->
275463
- getPropTypes ((name, ptyp_loc, type_) :: types) rest
275461
+ getPropTypes
275462
+ ((name, ptyp_attributes, ptyp_loc, type_) :: types)
275463
+ rest
275464
275464
| Ptyp_arrow (Nolabel, _type, rest) -> getPropTypes types rest
275465
275465
| Ptyp_arrow (name, type_, returnValue)
275466
275466
when isLabelled name || isOptional name ->
275467
- (returnValue, (name, returnValue.ptyp_loc, type_) :: types)
275467
+ ( returnValue,
275468
+ (name, ptyp_attributes, returnValue.ptyp_loc, type_) :: types )
275468
275469
| _ -> (fullType, types)
275469
275470
in
275470
275471
let innerType, propTypes = getPropTypes [] pval_type in
@@ -275936,19 +275937,22 @@ let transformSignatureItem ~config _mapper item =
275936
275937
in
275937
275938
let rec getPropTypes types ({ptyp_loc; ptyp_desc} as fullType) =
275938
275939
match ptyp_desc with
275939
- | Ptyp_arrow (name, type_, ({ptyp_desc = Ptyp_arrow _} as rest))
275940
+ | Ptyp_arrow
275941
+ ( name,
275942
+ ({ptyp_attributes = attrs} as type_),
275943
+ ({ptyp_desc = Ptyp_arrow _} as rest) )
275940
275944
when isOptional name || isLabelled name ->
275941
- getPropTypes ((name, ptyp_loc, type_) :: types) rest
275945
+ getPropTypes ((name, attrs, ptyp_loc, type_) :: types) rest
275942
275946
| Ptyp_arrow
275943
275947
(Nolabel, {ptyp_desc = Ptyp_constr ({txt = Lident "unit"}, _)}, rest)
275944
275948
->
275945
275949
getPropTypes types rest
275946
275950
| Ptyp_arrow (Nolabel, _type, rest) ->
275947
275951
hasForwardRef := true;
275948
275952
getPropTypes types rest
275949
- | Ptyp_arrow (name, type_, returnValue)
275953
+ | Ptyp_arrow (name, ({ptyp_attributes = attrs} as type_) , returnValue)
275950
275954
when isOptional name || isLabelled name ->
275951
- (returnValue, (name, returnValue.ptyp_loc, type_) :: types)
275955
+ (returnValue, (name, attrs, returnValue.ptyp_loc, type_) :: types)
275952
275956
| _ -> (fullType, types)
275953
275957
in
275954
275958
let innerType, propTypes = getPropTypes [] pval_type in
0 commit comments