@@ -288,17 +288,35 @@ let makePropsTypeParams ?(stripExplicitOption = false)
288
288
else Some interiorType)
289
289
290
290
let makeLabelDecls namedTypeList =
291
- namedTypeList
292
- |> List. map (fun (isOptional , label , attrs , loc , interiorType ) ->
293
- if label = " key" then
294
- Type. field ~loc ~attrs: (optionalAttrs @ attrs) {txt = label; loc}
295
- interiorType
296
- else if isOptional then
297
- Type. field ~loc ~attrs: (optionalAttrs @ attrs) {txt = label; loc}
298
- (Typ. var @@ safeTypeFromValue @@ Labelled label)
299
- else
300
- Type. field ~loc ~attrs {txt = label; loc}
301
- (Typ. var @@ safeTypeFromValue @@ Labelled label))
291
+ let rec mem_fst x = function
292
+ | [] -> false
293
+ | (a , _ ) :: l -> compare a (fst x) = 0 || mem_fst x l
294
+ in
295
+ let rec duplicated = function
296
+ | [] -> None
297
+ | hd :: tl -> if mem_fst hd tl then Some hd else duplicated tl
298
+ in
299
+ let duplicatedProp =
300
+ (* Find the duplicated prop from the back *)
301
+ namedTypeList |> List. rev
302
+ |> List. map (fun (_ , label , _ , loc , _ ) -> (label, loc))
303
+ |> duplicated
304
+ in
305
+ match duplicatedProp with
306
+ | Some (label , loc ) ->
307
+ React_jsx_common. raiseError ~loc " JSX: Duplicated prop %s" label
308
+ | None ->
309
+ namedTypeList
310
+ |> List. map (fun (isOptional , label , attrs , loc , interiorType ) ->
311
+ if label = " key" then
312
+ Type. field ~loc ~attrs: (optionalAttrs @ attrs) {txt = label; loc}
313
+ interiorType
314
+ else if isOptional then
315
+ Type. field ~loc ~attrs: (optionalAttrs @ attrs) {txt = label; loc}
316
+ (Typ. var @@ safeTypeFromValue @@ Labelled label)
317
+ else
318
+ Type. field ~loc ~attrs {txt = label; loc}
319
+ (Typ. var @@ safeTypeFromValue @@ Labelled label))
302
320
303
321
let makeTypeDecls propsName loc namedTypeList =
304
322
let labelDeclList = makeLabelDecls namedTypeList in
0 commit comments