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

Jsx ppx v4 part2 #614

Merged
merged 94 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
4a24011
add pattern constraint in destructuring args
mununki Jun 27, 2022
b1706cc
fix pattern in destructuring args
mununki Jun 27, 2022
e2b5883
new jsx transform for lower case
mununki Jun 27, 2022
7e73183
clean up applying optional attribute
mununki Jun 27, 2022
1d820d8
fix tests
mununki Jun 27, 2022
d8bec65
update ppx v4 spec with new jsx transform
mununki Jun 28, 2022
3d1aee3
add JSX V4 upgrade doc
mununki Jun 29, 2022
0fa928f
Update cli/JSXV4UPGRADE.md
mununki Jun 29, 2022
ffa3127
apply Js.React.array fn to children
mununki Jun 29, 2022
76fff14
fix test
mununki Jun 29, 2022
73d7de9
Update JSXV4UPGRADE.md
cristianoc Jun 30, 2022
8b042ee
new JSX mode
mununki Jun 30, 2022
2e96188
missing ns.optional for forwardRef
mununki Jun 30, 2022
57b7a74
fix tests
mununki Jun 30, 2022
d35d8cb
use React for new jsx transform, modify cli arg
mununki Jul 3, 2022
a2f690f
update V4 upgrade doc
mununki Jul 3, 2022
355f256
fix loc for ref in forwardRef
mununki Jul 4, 2022
ecf6565
add jsxFragment
mununki Jul 5, 2022
d76e807
labelled arg for jsx_mode
mununki Jul 5, 2022
b4ae677
add file-level jsx config, @@jsxConfig
mununki Jul 6, 2022
3367a9c
change jsx_version type to int
mununki Jul 7, 2022
1cc4efc
clean up of updating jsx config
mununki Jul 7, 2022
4f021c2
update V4 spec doc
mununki Jul 7, 2022
6561566
Update JSXV4.md
cristianoc Jul 7, 2022
1f3fb46
Update JSXV4.md
cristianoc Jul 7, 2022
ef3613a
Half way through making config more flexible.
cristianoc Jul 7, 2022
d20c974
Make config mutable.
cristianoc Jul 7, 2022
af563df
Make update imperative.
cristianoc Jul 7, 2022
e61a03c
Add str item and sig item.
cristianoc Jul 7, 2022
eefd1b3
Hook up config update to V4.
cristianoc Jul 7, 2022
1eebb57
Rename V4-specific visitor with V4.
cristianoc Jul 7, 2022
78a30dd
Move V4 inside.
cristianoc Jul 7, 2022
cecb147
Move V3 inside.
cristianoc Jul 7, 2022
44dd625
rename
cristianoc Jul 7, 2022
017c9de
Bring toplevel out.
cristianoc Jul 7, 2022
4d41ef0
Move out more.
cristianoc Jul 7, 2022
cec6e7a
Create config early.
cristianoc Jul 7, 2022
880bf04
Move config creation outside the module.
cristianoc Jul 7, 2022
c86b756
simplify toplevel
cristianoc Jul 7, 2022
333bbe9
Same for implementation.
cristianoc Jul 7, 2022
208c464
Unify V3 and V4 at top level.
cristianoc Jul 7, 2022
362ea66
Include nested modules in config.
cristianoc Jul 7, 2022
4b892aa
Clean up.
cristianoc Jul 7, 2022
72cc0ad
Unify getMapper.
cristianoc Jul 7, 2022
52ccfe4
Allow V3 to do the switch.
cristianoc Jul 7, 2022
3613de9
add test for jsxConfig
mununki Jul 7, 2022
fa8318a
Weave the mappers together.
cristianoc Jul 7, 2022
a3216c8
Rename
cristianoc Jul 7, 2022
4bc6f34
Another rename.
cristianoc Jul 7, 2022
9ddd721
cleanup
cristianoc Jul 7, 2022
0d1bcbd
Rename toplevel transforms.
cristianoc Jul 7, 2022
9c500e2
Refactor V4 process structure to be more granular.
cristianoc Jul 7, 2022
ed58791
Inline toplevel transforms.
cristianoc Jul 7, 2022
62aa219
More explicit.
cristianoc Jul 7, 2022
c7a10e0
In V4, gate structure item transform to V4.
cristianoc Jul 7, 2022
e69efff
Refactor toplevel V3.
cristianoc Jul 7, 2022
d5280f2
Rename V3.
cristianoc Jul 7, 2022
ea52f01
Make V3 structure and signature more explicit.
cristianoc Jul 7, 2022
a1e245a
Gate V3 structure and signature to when config version is 3.
cristianoc Jul 7, 2022
483ad96
Run both V3 and V4 structure and signature now that they are gated.
cristianoc Jul 7, 2022
ec1cdaf
Expose the structure (signature) item transformers and call them dire…
cristianoc Jul 7, 2022
eb6e681
Reorganize interface a bit.
cristianoc Jul 7, 2022
b556a3e
Don't recursively process all the structure items at once.
cristianoc Jul 7, 2022
64f49b5
Handle config update directly.
cristianoc Jul 7, 2022
b739cb8
Move config processing outside V4.
cristianoc Jul 7, 2022
b6ee674
Restore config when getting out of a submodule.
cristianoc Jul 7, 2022
0951062
cleanup tranformStructureItem4
cristianoc Jul 7, 2022
4b42894
fix props type params for external definition
mununki Jul 9, 2022
97df3e9
clean up make props type params
mununki Jul 9, 2022
0babb8c
test with jsx config update
mununki Jul 9, 2022
47beff4
udpate docs
mununki Jul 10, 2022
b755fab
fix typo
mununki Jul 11, 2022
6e90507
more concrete type for arg
mununki Jul 11, 2022
247ad0c
fix test
mununki Jul 11, 2022
589bdcc
fix newtype
mununki Jul 11, 2022
af1d52d
fix typeConstraints
mununki Jul 12, 2022
fb08992
keep pvb_attributes
mununki Jul 13, 2022
dbad398
remove unused variables, values
mununki Jul 14, 2022
4cc70a0
uppercase loc to definition
mununki Jul 14, 2022
b128cbe
clean up
mununki Jul 16, 2022
2bbf89d
clean up transforming forwardRef
mununki Jul 17, 2022
f4cb119
update V4 spec doc
mununki Jul 17, 2022
8c62db0
change order of fields in props type record
mununki Jul 17, 2022
bbb6398
strip explicit option from arg in implementation
mununki Jul 19, 2022
8bc3e5d
make type param label safe
mununki Jul 19, 2022
d3b5505
check each module has one react comp at most
mununki Jul 20, 2022
f64e5c5
fix raise error in transform sig
mununki Jul 20, 2022
d837748
add hasReactComponent into jsx config
mununki Jul 20, 2022
b78dde4
helper fn to raise error for multiple react comp
mununki Jul 20, 2022
5378e20
hasReactComponent: support interface files
cristianoc Jul 20, 2022
e65f991
restore config.hasReactComponent
mununki Jul 20, 2022
ba34580
helper fn to raise error with loc
mununki Jul 20, 2022
ffdb1d5
Tweak message for one component per module.
cristianoc Jul 21, 2022
fcab9e2
Update changelog before initial merge.
cristianoc Jul 21, 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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
## Master

> **Tags:**
>
> - :boom: [Breaking Change]
> - :eyeglasses: [Spec Compliance]
> - :rocket: [New Feature]
> - :bug: [Bug Fix]
> - :memo: [Documentation]
> - :house: [Internal]
> - :nail_care: [Polish]

#### :rocket: New Feature

- Add surface syntax for `async`/`await` https://github.com/rescript-lang/syntax/pull/600

- Initial support for JSX V4, still work in progress.
- :boom: when V4 is activated, at most one component is allowed for each module.

## ReScript 10.0

- Fix printing for inline nullary functor types [#477](https://github.com/rescript-lang/syntax/pull/477)
Expand Down
62 changes: 57 additions & 5 deletions cli/JSXV4.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,8 @@ let make = React.forwardRef((~x, ~y, ref) => body)

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}})
@react.component (~x, ~y) => ref => body
(props, ref) => fn(props, ref)
})
```

Expand Down Expand Up @@ -70,6 +67,34 @@ React.createElement(Comp.make, {x, y:7, @optional z})
React.createElement(Comp.make, {x, key: "7"})
```

**New "jsx" transform**

The V4 ppx supports [the new "jsx" transform](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) of React.js.

The "jsx" transform affects component application but not the definition.

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

```rescript
<div name="div" />
// is converted to
Js.React.jsxDom("div", { name: "div" })
```

The props type of dom elements, e.g. `div`, is inferred to `Js.React.domProps`.

```rescript
type domProps = {
key?: string,
id?: string,
...
}
```

**Interface And External**

```rescript
Expand Down Expand Up @@ -98,3 +123,30 @@ function has the name of the enclosing module/file.

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

**File-level config**

The top-level attribute `@@jsxConfig` is used to update the jsx config for the rest of the file (or until the next config update). Only the values mentioned are updated, the others are left unchanged.

```rescript
@@jsxConfig({ version: 4, mode: "automatic" })

module Wrapper = {
module R1 = {
@react.component // V4 & new jsx transform
let make = () => body
}

@@jsxConfig({ version: 4, mode: "classic" })

module R2 = {
@react.component // V4 with `React.createElement`
let make = () => body
}
}

@@jsxConfig({ version: 3 })

@react.component // V3
let make = () => body
```
37 changes: 37 additions & 0 deletions cli/JSXV4UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
**JSX V4 upgrade path**

1. No need to upgrade rescript-react or change bsconfig.json

JSX V3 by default.

2. New opt-in configuration added in bsconfig.json

a. JSX V3

```json
"jsx": {
"version": 3,
}
```

b. JSX V4 with classic mode (generate calls to `React.createElement` just as with V3)

```json
"jsx": {
"version": 4,
"mode": "classic"
}
```

c. JSX V4 with experimental JSX mode (generate calls `jsx` functions)

```json
"jsx": {
"version": 4,
"mode": "automatic"
}
```

JSX V4 with `"automatic"` runtme needs React v17.\* or higher as a peer dependency. It will require a new version of`rescript-react`.

> The existing configuration `reason.react-jsx` will be ignored if the new configuration is present.
Loading