@@ -242,9 +242,9 @@ let recordFromProps ~loc ~removeKey callArguments =
242242(* let make = ({id, name, children}: props<'id, 'name, 'children>) *)
243243let makePropsTypeParamsTvar namedTypeList =
244244 namedTypeList
245- |> List. filter_map (fun (_isOptional , label , _ , _interiorType ) ->
245+ |> List. filter_map (fun (_isOptional , label , _ , loc , _interiorType ) ->
246246 if label = " key" then None
247- else Some (Typ. var @@ safeTypeFromValue (Labelled label)))
247+ else Some (Typ. var ~loc @@ safeTypeFromValue (Labelled label)))
248248
249249let stripOption coreType =
250250 match coreType with
@@ -268,7 +268,7 @@ let stripJsNullable coreType =
268268let makePropsTypeParams ?(stripExplicitOption = false )
269269 ?(stripExplicitJsNullableOfRef = false ) namedTypeList =
270270 namedTypeList
271- |> List. filter_map (fun (isOptional , label , _ , interiorType ) ->
271+ |> List. filter_map (fun (isOptional , label , _ , loc , interiorType ) ->
272272 if label = " key" then None
273273 (* TODO: Worth thinking how about "ref_" or "_ref" usages *)
274274 else if label = " ref" then
@@ -277,7 +277,7 @@ let makePropsTypeParams ?(stripExplicitOption = false)
277277 For example, if JSX ppx is used for React Native, type would be different.
278278 *)
279279 match interiorType with
280- | {ptyp_desc = Ptyp_var "ref" } -> Some (refType Location. none )
280+ | {ptyp_desc = Ptyp_var "ref" } -> Some (refType loc )
281281 | _ ->
282282 (* Strip explicit Js.Nullable.t in case of forwardRef *)
283283 if stripExplicitJsNullableOfRef then stripJsNullable interiorType
@@ -287,9 +287,25 @@ let makePropsTypeParams ?(stripExplicitOption = false)
287287 else if isOptional && stripExplicitOption then stripOption interiorType
288288 else Some interiorType)
289289
290- let makeLabelDecls ~loc namedTypeList =
290+ let makeLabelDecls namedTypeList =
291+ let rec checkDuplicatedLabel l =
292+ let rec mem_label ((_ , (la : string ), _ , _ , _ ) as x ) = function
293+ | [] -> false
294+ | (_ , (lb : string ), _ , _ , _ ) :: l -> lb = la || mem_label x l
295+ in
296+ match l with
297+ | [] -> ()
298+ | hd :: tl ->
299+ if mem_label hd tl then
300+ let _, label, _, loc, _ = hd in
301+ React_jsx_common. raiseError ~loc " JSX: found the duplicated prop `%s`"
302+ label
303+ else checkDuplicatedLabel tl
304+ in
305+ let () = namedTypeList |> List. rev |> checkDuplicatedLabel in
306+
291307 namedTypeList
292- |> List. map (fun (isOptional , label , attrs , interiorType ) ->
308+ |> List. map (fun (isOptional , label , attrs , loc , interiorType ) ->
293309 if label = " key" then
294310 Type. field ~loc ~attrs: (optionalAttrs @ attrs) {txt = label; loc}
295311 interiorType
@@ -301,7 +317,7 @@ let makeLabelDecls ~loc namedTypeList =
301317 (Typ. var @@ safeTypeFromValue @@ Labelled label))
302318
303319let makeTypeDecls propsName loc namedTypeList =
304- let labelDeclList = makeLabelDecls ~loc namedTypeList in
320+ let labelDeclList = makeLabelDecls namedTypeList in
305321 (* 'id, 'className, ... *)
306322 let params =
307323 makePropsTypeParamsTvar namedTypeList
@@ -702,17 +718,22 @@ let argToType ~newtypes ~(typeConstraints : core_type option) types
702718 in
703719 match (type_, name, default) with
704720 | Some type_ , name , _ when isOptional name ->
705- (true , getLabel name, attrs, {type_ with ptyp_attributes = optionalAttrs})
721+ ( true ,
722+ getLabel name,
723+ attrs,
724+ loc,
725+ {type_ with ptyp_attributes = optionalAttrs} )
706726 :: types
707- | Some type_ , name , _ -> (false , getLabel name, attrs, type_) :: types
727+ | Some type_ , name , _ -> (false , getLabel name, attrs, loc, type_) :: types
708728 | None , name , _ when isOptional name ->
709729 ( true ,
710730 getLabel name,
711731 attrs,
732+ loc,
712733 Typ. var ~loc ~attrs: optionalAttrs (safeTypeFromValue name) )
713734 :: types
714735 | None , name , _ when isLabelled name ->
715- (false , getLabel name, attrs, Typ. var ~loc (safeTypeFromValue name))
736+ (false , getLabel name, attrs, loc, Typ. var ~loc (safeTypeFromValue name))
716737 :: types
717738 | _ -> types
718739
@@ -721,10 +742,12 @@ let argWithDefaultValue (name, default, _, _, _, _) =
721742 | Some default when isOptional name -> Some (getLabel name, default)
722743 | _ -> None
723744
724- let argToConcreteType types (name , attrs , _loc , type_ ) =
745+ let argToConcreteType types (name , attrs , loc , type_ ) =
725746 match name with
726- | name when isLabelled name -> (false , getLabel name, attrs, type_) :: types
727- | name when isOptional name -> (true , getLabel name, attrs, type_) :: types
747+ | name when isLabelled name ->
748+ (false , getLabel name, attrs, loc, type_) :: types
749+ | name when isOptional name ->
750+ (true , getLabel name, attrs, loc, type_) :: types
728751 | _ -> types
729752
730753let check_string_int_attribute_iter =
@@ -1306,7 +1329,8 @@ let transformSignatureItem ~config _mapper item =
13061329 makePropsRecordTypeSig ~core TypeOfAttr ~typ VarsOfCoreType " props"
13071330 psig_loc
13081331 ((* If there is Nolabel arg, regard the type as ref in forwardRef *)
1309- (if ! hasForwardRef then [(true , " ref" , [] , refType Location. none)]
1332+ (if ! hasForwardRef then
1333+ [(true , " ref" , [] , Location. none, refType Location. none)]
13101334 else [] )
13111335 @ namedTypeList)
13121336 in
0 commit comments