@@ -288,23 +288,28 @@ let makePropsTypeParams ?(stripExplicitOption = false)
288
288
else Some interiorType)
289
289
290
290
let makeLabelDecls namedTypeList =
291
- let rec mem_fst x = function
291
+ let rec mem_label (( _ , la , _ , _ , _ ) as x ) = function
292
292
| [] -> false
293
- | (a , _ ) :: l -> compare a (fst x) = 0 || mem_fst x l
293
+ | (_ , lb , _ , _ , _ ) :: l -> compare lb la = 0 || mem_label x l
294
294
in
295
295
let rec duplicated = function
296
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
297
+ | hd :: tl -> if mem_label hd tl then Some hd else duplicated tl
304
298
in
299
+ (* Check if there are duplicated props in the namedTypeList without making list relocation. *)
300
+ let duplicatedProp = namedTypeList |> duplicated in
305
301
match duplicatedProp with
306
- | Some (label , loc ) ->
307
- React_jsx_common. raiseError ~loc " JSX: found the duplicated prop `%s`" label
302
+ | Some _ -> (
303
+ (* If there are duplicated props, then find the one from the last. *)
304
+ let duplicatedPropAtLast = namedTypeList |> List. rev |> duplicated in
305
+ match duplicatedPropAtLast with
306
+ | Some (_ , label , _ , loc , _ ) ->
307
+ React_jsx_common. raiseError ~loc " JSX: found the duplicated prop `%s`"
308
+ label
309
+ | None ->
310
+ (* Never reach here *)
311
+ React_jsx_common. raiseError ~loc: Location. none
312
+ " JSX: found the duplicated prop" )
308
313
| None ->
309
314
namedTypeList
310
315
|> List. map (fun (isOptional , label , attrs , loc , interiorType ) ->
0 commit comments