@@ -27,7 +27,8 @@ let getLabel str =
27
27
| Optional str | Labelled str -> str
28
28
| Nolabel -> " "
29
29
30
- let optionalAttr = [({txt = " ns.optional" ; loc = Location. none}, PStr [] )]
30
+ let optionalAttr = ({txt = " ns.optional" ; loc = Location. none}, PStr [] )
31
+ let optionalAttrs = [optionalAttr]
31
32
32
33
let constantString ~loc str =
33
34
Ast_helper.Exp. constant ~loc (Pconst_string (str, None ))
@@ -211,7 +212,7 @@ let recordFromProps ~loc ~removeKey callArguments =
211
212
let id = getLabel arg_label in
212
213
if isOptional arg_label then
213
214
( {txt = Lident id; loc = pexp_loc},
214
- {pexpr with pexp_attributes = optionalAttr } )
215
+ {pexpr with pexp_attributes = optionalAttrs } )
215
216
else ({txt = Lident id; loc = pexp_loc}, pexpr)
216
217
in
217
218
let fields = props |> List. map processProp in
@@ -288,9 +289,9 @@ let makeLabelDecls ~loc namedTypeList =
288
289
namedTypeList
289
290
|> List. map (fun (isOptional , label , _ , interiorType ) ->
290
291
if label = " key" then
291
- Type. field ~loc ~attrs: optionalAttr {txt = label; loc} interiorType
292
+ Type. field ~loc ~attrs: optionalAttrs {txt = label; loc} interiorType
292
293
else if isOptional then
293
- Type. field ~loc ~attrs: optionalAttr {txt = label; loc}
294
+ Type. field ~loc ~attrs: optionalAttrs {txt = label; loc}
294
295
(Typ. var @@ safeTypeFromValue @@ Labelled label)
295
296
else
296
297
Type. field ~loc {txt = label; loc}
@@ -462,7 +463,7 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
462
463
| Exact children ->
463
464
[
464
465
( labelled " children" ,
465
- Exp. apply ~attrs: optionalAttr
466
+ Exp. apply ~attrs: optionalAttrs
466
467
(Exp. ident
467
468
{
468
469
txt = Ldot (Lident " ReactDOM" , " someElement" );
@@ -543,19 +544,14 @@ let transformLowercaseCall3 ~config mapper jsxExprLoc callExprLoc attrs
543
544
(nolabel, childrenExpr);
544
545
]
545
546
| nonEmptyProps ->
546
- let propsCall =
547
- Exp. apply
548
- (Exp. ident
549
- {loc = Location. none; txt = Ldot (Lident " ReactDOM" , " domProps" )})
550
- (nonEmptyProps
551
- |> List. map (fun (label , expression ) ->
552
- (label, mapper.expr mapper expression)))
547
+ let propsRecord =
548
+ recordFromProps ~loc: Location. none ~remove Key:false nonEmptyProps
553
549
in
554
550
[
555
551
(* "div" *)
556
552
(nolabel, componentNameExpr);
557
553
(* ReactDOM.domProps(~className=blabla, ~foo=bar, ()) *)
558
- (labelled " props" , propsCall );
554
+ (labelled " props" , propsRecord );
559
555
(* [|moreCreateElementCallsHere|] *)
560
556
(nolabel, childrenExpr);
561
557
]
@@ -688,14 +684,14 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types
688
684
in
689
685
match (type_, name, default) with
690
686
| Some type_ , name , _ when isOptional name ->
691
- (true , getLabel name, [] , {type_ with ptyp_attributes = optionalAttr })
687
+ (true , getLabel name, [] , {type_ with ptyp_attributes = optionalAttrs })
692
688
:: types
693
689
| Some type_ , name , _ -> (false , getLabel name, [] , type_) :: types
694
690
| None , name , _ when isOptional name ->
695
691
( true ,
696
692
getLabel name,
697
693
[] ,
698
- Typ. var ~loc ~attrs: optionalAttr (safeTypeFromValue name) )
694
+ Typ. var ~loc ~attrs: optionalAttrs (safeTypeFromValue name) )
699
695
:: types
700
696
| None , name , _ when isLabelled name ->
701
697
(false , getLabel name, [] , Typ. var ~loc (safeTypeFromValue name)) :: types
@@ -1052,7 +1048,7 @@ let transformStructureItem ~config mapper item =
1052
1048
{
1053
1049
patternWithoutConstraint with
1054
1050
ppat_attributes =
1055
- (if isOptional arg_label then optionalAttr else [] )
1051
+ (if isOptional arg_label then optionalAttrs else [] )
1056
1052
@ pattern.ppat_attributes;
1057
1053
} )
1058
1054
:: patternsWithLabel)
@@ -1068,7 +1064,7 @@ let transformStructureItem ~config mapper item =
1068
1064
{
1069
1065
pattern with
1070
1066
ppat_attributes =
1071
- optionalAttr @ pattern.ppat_attributes;
1067
+ optionalAttrs @ pattern.ppat_attributes;
1072
1068
} )
1073
1069
:: patternsWithNolabel)
1074
1070
expr
0 commit comments