Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

JSX V4 part 1 (to be continued). #547

Merged
merged 35 commits into from
Jun 25, 2022
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
552c05c
react ppx v4 and parsing spread props
mununki Jun 8, 2022
aaf02ae
change the empty record to "_" for jsx upper case
mununki Jun 9, 2022
2a1477f
change empty record to {key: None} for jsx upper case
mununki Jun 9, 2022
4e41a57
polishing the loc of react ppx
mununki Jun 9, 2022
945e911
implicit option type of @obj record update
mununki Jun 10, 2022
2ce3b67
add match vbs for optional arg with default value
mununki Jun 10, 2022
896688d
add @optional record declarations
mununki Jun 10, 2022
a1b48cf
fix missing pattern
mununki Jun 10, 2022
167a79d
clean up codes and comments
mununki Jun 11, 2022
ba4b9c2
support React.forwardRef
mununki Jun 11, 2022
bb11ee2
replace filterMap with std lib
mununki Jun 12, 2022
ac6fddc
Add JSX V4 spec.
cristianoc Jun 12, 2022
2a3ddac
typo
cristianoc Jun 12, 2022
2b742f1
JSX spec: move createElement to application.
cristianoc Jun 12, 2022
7f541ba
spec: comment on name
cristianoc Jun 12, 2022
6ec656c
spec: clean up file
cristianoc Jun 12, 2022
2abb690
external
cristianoc Jun 12, 2022
47a6cb0
Be consistent with interface
cristianoc Jun 12, 2022
a97c9ae
Update JSXV4.md
cristianoc Jun 12, 2022
4e80d69
restore React.createElement in application site
mununki Jun 13, 2022
e7af22f
spec: react fragment
mununki Jun 13, 2022
c7412fc
spec: tweak fragment.
cristianoc Jun 13, 2022
139e23a
make react component name capitalized
mununki Jun 13, 2022
c975041
test: add test files
mununki Jun 13, 2022
5a1dc66
fix ppx for forwardRef
mununki Jun 15, 2022
9a2ddb0
remove ref from props except forwardRef
mununki Jun 16, 2022
5aa2382
add test for forwardRef
mununki Jun 16, 2022
3c21396
format
mununki Jun 16, 2022
2e4025d
remove uneccessary adding @optional attr from extracting props type
mununki Jun 17, 2022
5216cce
indent by relocating every fn from jsxMapper
mununki Jun 17, 2022
34f9cf8
remove unused jsxVersion
mununki Jun 18, 2022
256eaac
add new line
mununki Jun 19, 2022
007b17b
update jsx ppx comment
mununki Jun 19, 2022
0bacbe3
rename v3 -> v4, restore v3, add cli args
mununki Jun 24, 2022
0337629
add tests for v3 and v4 respectively
mununki Jun 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
remove unused jsxVersion
* jsx version check is conducted in compiler config side
  • Loading branch information
mununki committed Jun 24, 2022
commit 34f9cf8ca2f08d938f22e1dfa76302ede7d3345f
25 changes: 8 additions & 17 deletions cli/reactjs_jsx_ppx_v3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1111,7 +1111,7 @@ let reactComponentSignatureTransform mapper signatures =
List.fold_right (transformComponentSignature mapper) signatures []
[@@raises Invalid_argument]

let transformJsxCall jsxVersion mapper callExpression callArguments attrs =
let transformJsxCall mapper callExpression callArguments attrs =
match callExpression.pexp_desc with
| Pexp_ident caller -> (
match caller with
Expand All @@ -1120,20 +1120,14 @@ let transformJsxCall jsxVersion mapper callExpression callArguments attrs =
(Invalid_argument
"JSX: `createElement` should be preceeded by a module name.")
(* Foo.createElement(~prop1=foo, ~prop2=bar, ~children=[], ()) *)
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} -> (
match !jsxVersion with
| None | Some 3 ->
transformUppercaseCall3 modulePath mapper loc attrs callExpression
callArguments
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 3"))
| {loc; txt = Ldot (modulePath, ("createElement" | "make"))} ->
transformUppercaseCall3 modulePath mapper loc attrs callExpression
callArguments
(* div(~prop1=foo, ~prop2=bar, ~children=[bla], ()) *)
(* turn that into
ReactDOMRe.createElement(~props=ReactDOMRe.props(~props1=foo, ~props2=bar, ()), [|bla|]) *)
| {loc; txt = Lident id} -> (
match !jsxVersion with
| None | Some 3 ->
transformLowercaseCall3 mapper loc attrs callExpression callArguments id
| Some _ -> raise (Invalid_argument "JSX: the JSX version must be 3"))
| {loc; txt = Lident id} ->
transformLowercaseCall3 mapper loc attrs callExpression callArguments id
| {txt = Ldot (_, anythingNotCreateElementOrMake)} ->
raise
(Invalid_argument
Expand Down Expand Up @@ -1165,7 +1159,7 @@ let structure nestedModules mapper structure =
@@ reactComponentTransform nestedModules mapper structures
[@@raises Invalid_argument]

let expr jsxVersion mapper expression =
let expr mapper expression =
match expression with
(* Does the function application have the @JSX attribute? *)
| {pexp_desc = Pexp_apply (callExpression, callArguments); pexp_attributes}
Expand All @@ -1179,8 +1173,7 @@ let expr jsxVersion mapper expression =
(* no JSX attribute *)
| [], _ -> default_mapper.expr mapper expression
| _, nonJSXAttributes ->
transformJsxCall jsxVersion mapper callExpression callArguments
nonJSXAttributes)
transformJsxCall mapper callExpression callArguments nonJSXAttributes)
(* is it a list with jsx attribute? Reason <>foo</> desugars to [@JSX][foo]*)
| {
pexp_desc =
Expand Down Expand Up @@ -1231,10 +1224,8 @@ let module_binding nestedModules mapper module_binding =

(* TODO: some line number might still be wrong *)
let jsxMapper nestedModules =
let jsxVersion = ref None in
let structure = structure nestedModules in
let module_binding = module_binding nestedModules in
let expr = expr jsxVersion in
{default_mapper with structure; expr; signature; module_binding}
[@@raises Invalid_argument, Failure]

Expand Down