@@ -439,80 +439,8 @@ let jsxMapper () =
439
439
args
440
440
in
441
441
442
- let transformUppercaseCall modulePath mapper loc attrs _ callArguments =
443
- let (children, argsWithLabels) = extractChildren ~loc ~remove LastPositionUnit:true callArguments in
444
- let (argsKeyRef, argsForMake) = List. partition argIsKeyRef argsWithLabels in
445
- let childrenExpr = transformChildrenIfList ~loc ~mapper children in
446
- let recursivelyTransformedArgsForMake = argsForMake |> List. map (fun (label , expression ) -> (label, mapper.expr mapper expression)) in
447
- let args = recursivelyTransformedArgsForMake @ [ (nolabel, childrenExpr) ] in
448
- let wrapWithReasonReactElement e = (* ReasonReact.element(~key, ~ref, ...) *)
449
- Exp. apply
450
- ~loc
451
- (Exp. ident ~loc {loc; txt = Ldot (Lident " ReasonReact" , " element" )})
452
- (argsKeyRef @ [(nolabel, e)]) in
453
- Exp. apply
454
- ~loc
455
- ~attrs
456
- (* Foo.make *)
457
- (Exp. ident ~loc {loc; txt = Ldot (modulePath, " make" )})
458
- args
459
- |> wrapWithReasonReactElement in
460
-
461
- let transformLowercaseCall mapper loc attrs callArguments id =
462
- let (children, nonChildrenProps) = extractChildren ~loc callArguments in
463
- let componentNameExpr = constantString ~loc id in
464
- let childrenExpr = transformChildrenIfList ~loc ~mapper children in
465
- let createElementCall = match children with
466
- (* [@JSX] div(~children=[a]), coming from <div> a </div> *)
467
- | {
468
- pexp_desc =
469
- Pexp_construct ({txt = Lident " ::" }, Some {pexp_desc = Pexp_tuple _ })
470
- | Pexp_construct ({txt = Lident " []" }, None )
471
- } -> " createElement"
472
- (* [@JSX] div(~children=[|a|]), coming from <div> ...[|a|] </div> *)
473
- | { pexp_desc = (Pexp_array _ ) } ->
474
- raise (Invalid_argument " A spread + an array literal as a DOM element's \
475
- children would cancel each other out, and thus don't make sense written \
476
- together. You can simply remove the spread and the array literal." )
477
- (* [@JSX] div(~children= <div />), coming from <div> ...<div/> </div> *)
478
- | {
479
- pexp_attributes
480
- } when pexp_attributes |> List. exists (fun (attribute , _ ) -> attribute.txt = " JSX" ) ->
481
- raise (Invalid_argument " A spread + a JSX literal as a DOM element's \
482
- children don't make sense written together. You can simply remove the spread." )
483
- | _ -> " createElementVariadic"
484
- in
485
- let args = match nonChildrenProps with
486
- | [_justTheUnitArgumentAtEnd] ->
487
- [
488
- (* "div" *)
489
- (nolabel, componentNameExpr);
490
- (* [|moreCreateElementCallsHere|] *)
491
- (nolabel, childrenExpr)
492
- ]
493
- | nonEmptyProps ->
494
- let propsCall =
495
- Exp. apply
496
- ~loc
497
- (Exp. ident ~loc {loc; txt = Ldot (Lident " ReactDOMRe" , " props" )})
498
- (nonEmptyProps |> List. map (fun (label , expression ) -> (label, mapper.expr mapper expression)))
499
- in
500
- [
501
- (* "div" *)
502
- (nolabel, componentNameExpr);
503
- (* ReactDOMRe.props(~className=blabla, ~foo=bar, ()) *)
504
- (labelled " props" , propsCall);
505
- (* [|moreCreateElementCallsHere|] *)
506
- (nolabel, childrenExpr)
507
- ] in
508
- Exp. apply
509
- ~loc
510
- (* throw away the [@JSX] attribute and keep the others, if any *)
511
- ~attrs
512
- (* ReactDOMRe.createElement *)
513
- (Exp. ident ~loc {loc; txt = Ldot (Lident " ReactDOMRe" , createElementCall)})
514
- args
515
- in
442
+
443
+
516
444
517
445
let rec recursivelyTransformNamedArgsForMake mapper expr list =
518
446
let expr = mapper.expr mapper expr in
@@ -932,20 +860,18 @@ let jsxMapper () =
932
860
(* Foo.createElement(~prop1=foo, ~prop2=bar, ~children=[], ()) *)
933
861
| {loc; txt = Ldot (modulePath , ("createElement" | "make" ))} ->
934
862
(match ! jsxVersion with
935
- | Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
936
863
| None
937
864
| Some 3 -> transformUppercaseCall3 modulePath mapper loc attrs callExpression callArguments
938
- | Some _ -> raise (Invalid_argument " JSX: the JSX version must be 2 or 3" ))
865
+ | Some _ -> raise (Invalid_argument " JSX: the JSX version must be 3" ))
939
866
940
867
(* div(~prop1=foo, ~prop2=bar, ~children=[bla], ()) *)
941
868
(* turn that into
942
869
ReactDOMRe.createElement(~props=ReactDOMRe.props(~props1=foo, ~props2=bar, ()), [|bla|]) *)
943
870
| {loc; txt = Lident id } ->
944
871
(match ! jsxVersion with
945
- | Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
946
872
| None
947
873
| Some 3 -> transformLowercaseCall3 mapper loc attrs callArguments id
948
- | Some _ -> raise (Invalid_argument " JSX: the JSX version must be 2 or 3" ))
874
+ | Some _ -> raise (Invalid_argument " JSX: the JSX version must be 3" ))
949
875
950
876
| {txt = Ldot (_ , anythingNotCreateElementOrMake )} ->
951
877
raise (
0 commit comments