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
Show file tree
Hide file tree
Changes from all commits
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
100 changes: 100 additions & 0 deletions cli/JSXV4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
**Abbreviation**

The placement of `@react.component` is an abbreviation as described below.

**Normal Case**

```rescript
@react.component
let make = (~x, ~y, ~z) => body

// is an abbreviation for

let make = @react.component (~x, ~y, ~z) => body
```

**Forward Ref**

```rescript
@react.component
let make = React.forwardRef((~x, ~y, ref) => body)

// is an abbreviation for

let make = React.forwardRef({
let fn =
@react.component (~x, ~y, ~ref=?) => {
let ref = ref->Js.Nullable.fromOption
body
}
(props, ref) => fn({...props, ref: {ref->Js.Nullable.toOption}})
})
```

**Conversion**

Conversion applies to an arrow function definition where all the arguments are labelled.
It produces a type definition and a new function.

**Definition**

```rescript
@react.component (~x, ~y=3+x, ?z) => body

// is converted to

type props<'x, 'y, 'z> = {x: 'x, @optional y: 'y, @optional z: 'z, @optional key: string}

({x, y, z}: props<_>) => {
let y = switch props.y {
| None => 3 + x
| Some(y) => y
}
body
}
```

**Application**

```rescript
<Comp x>
// is converted to
React.createElement(Comp.make, {x})

<Comp x y=7 ?z>
// is converted to
React.createElement(Comp.make, {x, y:7, @optional z})

<Comp x key="7">
// is converted to
React.createElement(Comp.make, {x, key: "7"})
```

**Interface And External**

```rescript
@react.component (~x: int, ~y: int=?, ~z: int=?) => React.element

// is converted to

type props<'x, 'y, 'z> = {x: 'x, @optional y: 'y, @optional z: 'z}

props<int, int, int> => React.element
```

Since an external is a function declaration, it follows the same rule.

**Component Name**

Use the V3 convention for names, and make sure the generated
function has the name of the enclosing module/file.

**Fragment**

```rescript
<> comp1 comp2 comp3 </>

// is converted to

ReactDOMRe.createElement(ReasonReact.fragment, [comp1, comp2, comp3])
```
Loading