Skip to content

Commit 310665d

Browse files
authored
Merge pull request #4420 from BuckleScript/bump
remove legacy jsx v2
2 parents 8d7a965 + f2ca746 commit 310665d

File tree

10 files changed

+124
-3620
lines changed

10 files changed

+124
-3620
lines changed

jscomp/main/js_main.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ let buckle_script_flags : (string * Arg.spec * string) list =
180180
)
181181
::
182182
("-bs-jsx",
183-
Arg.Int (fun i -> Js_config.jsx_version := i),
183+
Arg.Int (fun i ->
184+
(if i <> 3 then raise (Arg.Bad (" Not supported jsx version : " ^ string_of_int i)));
185+
Js_config.jsx_version := i),
184186
" Set jsx version"
185187
)
186188
::

jscomp/syntax/ppx_entry.ml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ let rewrite_signature (ast : Parsetree.signature) : Parsetree.signature =
2929
Ast_config.iter_on_bs_config_sigi ast;
3030
let ast =
3131
match !Js_config.jsx_version with
32-
| 2 -> Reactjs_jsx_ppx_v2.rewrite_signature ast
3332
| 3 -> Reactjs_jsx_ppx_v3.rewrite_signature ast
3433
| _ -> ast
3534
(* react-jsx ppx relies on built-in ones like `##` *)
@@ -48,8 +47,7 @@ let rewrite_implementation (ast : Parsetree.structure) : Parsetree.structure =
4847
Bs_ast_invariant.iter_warnings_on_stru ast ;
4948
Ast_config.iter_on_bs_config_stru ast ;
5049
let ast =
51-
match !Js_config.jsx_version with
52-
| 2 -> Reactjs_jsx_ppx_v2.rewrite_implementation ast
50+
match !Js_config.jsx_version with
5351
| 3 -> Reactjs_jsx_ppx_v3.rewrite_implementation ast
5452
| _ -> ast
5553
in

jscomp/syntax/reactjs_jsx_ppx.cppo.ml

Lines changed: 4 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -439,80 +439,8 @@ let jsxMapper () =
439439
args
440440
in
441441

442-
let transformUppercaseCall modulePath mapper loc attrs _ callArguments =
443-
let (children, argsWithLabels) = extractChildren ~loc ~removeLastPositionUnit: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+
516444

517445
let rec recursivelyTransformNamedArgsForMake mapper expr list =
518446
let expr = mapper.expr mapper expr in
@@ -932,30 +860,18 @@ let jsxMapper () =
932860
(* Foo.createElement(~prop1=foo, ~prop2=bar, ~children=[], ()) *)
933861
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} ->
934862
(match !jsxVersion with
935-
#ifdef REACT_JS_JSX_V2
936-
| None
937-
| Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
938-
#else
939-
| Some 2 -> transformUppercaseCall modulePath mapper loc attrs callExpression callArguments
940863
| None
941-
#endif
942864
| Some 3 -> transformUppercaseCall3 modulePath mapper loc attrs callExpression callArguments
943-
| 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"))
944866

945867
(* div(~prop1=foo, ~prop2=bar, ~children=[bla], ()) *)
946868
(* turn that into
947869
ReactDOMRe.createElement(~props=ReactDOMRe.props(~props1=foo, ~props2=bar, ()), [|bla|]) *)
948870
| {loc; txt = Lident id} ->
949871
(match !jsxVersion with
950-
#ifdef REACT_JS_JSX_V2
951-
| None
952-
| Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
953-
#else
954-
| Some 2 -> transformLowercaseCall mapper loc attrs callArguments id
955872
| None
956-
#endif
957873
| Some 3 -> transformLowercaseCall3 mapper loc attrs callArguments id
958-
| 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"))
959875

960876
| {txt = Ldot (_, anythingNotCreateElementOrMake)} ->
961877
raise (

0 commit comments

Comments
 (0)