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

Commit 0d219e7

Browse files
committed
Remove @optional from JSX and use ns.optional.
1 parent a494db1 commit 0d219e7

15 files changed

+25
-25
lines changed

cli/reactjs_jsx_ppx_v4.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let getLabel str =
3333

3434
let optionIdent = Lident "option"
3535

36-
let optionalAttr = [({txt = "optional"; loc = Location.none}, PStr [])]
36+
let optionalAttr = [({txt = "ns.optional"; loc = Location.none}, PStr [])]
3737

3838
let constantString ~loc str =
3939
Ast_helper.Exp.constant ~loc (Pconst_string (str, None))

tests/ppx/react/expected/commentAtTop.res_v4_auto.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type props<'msg> = {@optional key: string, msg: 'msg} // test React JSX file
1+
type props<'msg> = {key?: string, msg: 'msg} // test React JSX file
22

33
let make = ({msg}: props<'msg>) => {
44
ReactDOMRe.createDOMElementVariadic("div", [{msg->React.string}])

tests/ppx/react/expected/commentAtTop.res_v4_cls.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type props<'msg> = {@optional key: string, msg: 'msg} // test React JSX file
1+
type props<'msg> = {key?: string, msg: 'msg} // test React JSX file
22

33
let make = ({msg}: props<'msg>) => {
44
ReactDOMRe.createDOMElementVariadic("div", [{msg->React.string}])

tests/ppx/react/expected/externalWithCustomName.res_v4_auto.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Foo = {
2-
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
2+
type props<'a, 'b> = {key?: string, a: 'a, b: 'b}
33
@module("Foo")
44
external component: React.componentLike<props<'a, 'b>, React.element> = "component"
55
}

tests/ppx/react/expected/externalWithCustomName.res_v4_cls.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Foo = {
2-
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
2+
type props<'a, 'b> = {key?: string, a: 'a, b: 'b}
33
@module("Foo")
44
external component: React.componentLike<props<'a, 'b>, React.element> = "component"
55
}

tests/ppx/react/expected/forwardRef.res_v4_auto.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module FancyInput = {
22
type props<'className, 'children> = {
3-
@optional key: string,
4-
@optional className: 'className,
3+
key?: string,
4+
className?: 'className,
55
children: 'children,
6-
@optional ref: ReactDOM.Ref.currentDomRef,
6+
ref?: ReactDOM.Ref.currentDomRef,
77
}
88
let make = ({className, children, ref}: props<'className, 'children>) => {
99
let ref = Js.Nullable.fromOption(ref)
@@ -28,11 +28,11 @@ module FancyInput = {
2828
}
2929
let make = React.forwardRef({
3030
let \"ForwardRef$FancyInput" = (props: props<_>, ref) =>
31-
make({...props, ref: @optional Js.Nullable.toOption(ref)})
31+
make({...props, ref: ?Js.Nullable.toOption(ref)})
3232
\"ForwardRef$FancyInput"
3333
})
3434
}
35-
type props = {@optional key: string}
35+
type props = {key?: string}
3636

3737
let make = (_: props) => {
3838
let input = React.useRef(Js.Nullable.null)

tests/ppx/react/expected/forwardRef.res_v4_cls.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
module FancyInput = {
22
type props<'className, 'children> = {
3-
@optional key: string,
4-
@optional className: 'className,
3+
key?: string,
4+
className?: 'className,
55
children: 'children,
6-
@optional ref: ReactDOM.Ref.currentDomRef,
6+
ref?: ReactDOM.Ref.currentDomRef,
77
}
88
let make = ({className, children, ref}: props<'className, 'children>) => {
99
let ref = Js.Nullable.fromOption(ref)
@@ -28,11 +28,11 @@ module FancyInput = {
2828
}
2929
let make = React.forwardRef({
3030
let \"ForwardRef$FancyInput" = (props: props<_>, ref) =>
31-
make({...props, ref: @optional Js.Nullable.toOption(ref)})
31+
make({...props, ref: ?Js.Nullable.toOption(ref)})
3232
\"ForwardRef$FancyInput"
3333
})
3434
}
35-
type props = {@optional key: string}
35+
type props = {key?: string}
3636

3737
let make = (_: props) => {
3838
let input = React.useRef(Js.Nullable.null)

tests/ppx/react/expected/innerModule.res_v4_auto.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Bar = {
2-
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
2+
type props<'a, 'b> = {key?: string, a: 'a, b: 'b}
33
let make = ({a, b}: props<'a, 'b>) => {
44
Js.log("This function should be named `InnerModule.react$Bar`")
55
ReactDOMRe.createDOMElementVariadic("div", [])
@@ -8,7 +8,7 @@ module Bar = {
88
let \"InnerModule$Bar" = (props: props<_>) => make(props)
99
\"InnerModule$Bar"
1010
}
11-
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
11+
type props<'a, 'b> = {key?: string, a: 'a, b: 'b}
1212

1313
let component = ({a, b}: props<'a, 'b>) => {
1414
Js.log("This function should be named `InnerModule.react$Bar$component`")

tests/ppx/react/expected/innerModule.res_v4_cls.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Bar = {
2-
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
2+
type props<'a, 'b> = {key?: string, a: 'a, b: 'b}
33
let make = ({a, b}: props<'a, 'b>) => {
44
Js.log("This function should be named `InnerModule.react$Bar`")
55
ReactDOMRe.createDOMElementVariadic("div", [])
@@ -8,7 +8,7 @@ module Bar = {
88
let \"InnerModule$Bar" = (props: props<_>) => make(props)
99
\"InnerModule$Bar"
1010
}
11-
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
11+
type props<'a, 'b> = {key?: string, a: 'a, b: 'b}
1212

1313
let component = ({a, b}: props<'a, 'b>) => {
1414
Js.log("This function should be named `InnerModule.react$Bar$component`")

tests/ppx/react/expected/newtype.res_v4_auto.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type props<'a, 'b, 'c> = {@optional key: string, a: 'a, b: 'b, c: 'c}
1+
type props<'a, 'b, 'c> = {key?: string, a: 'a, b: 'b, c: 'c}
22
let make = (_: props<'a, 'b, 'c>, type a, ~a: a, ~b: array<option<[#Foo(a)]>>, ~c: 'a, _) =>
33
ReactDOMRe.createDOMElementVariadic("div", [])
44
let make = {

tests/ppx/react/expected/newtype.res_v4_cls.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type props<'a, 'b, 'c> = {@optional key: string, a: 'a, b: 'b, c: 'c}
1+
type props<'a, 'b, 'c> = {key?: string, a: 'a, b: 'b, c: 'c}
22
let make = (_: props<'a, 'b, 'c>, type a, ~a: a, ~b: array<option<[#Foo(a)]>>, ~c: 'a, _) =>
33
ReactDOMRe.createDOMElementVariadic("div", [])
44
let make = {

tests/ppx/react/expected/topLevel.res_v4_auto.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
1+
type props<'a, 'b> = {key?: string, a: 'a, b: 'b}
22
let make = ({a, b}: props<'a, 'b>) => {
33
Js.log("This function should be named 'TopLevel.react'")
44
ReactDOMRe.createDOMElementVariadic("div", [])

tests/ppx/react/expected/topLevel.res_v4_cls.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
1+
type props<'a, 'b> = {key?: string, a: 'a, b: 'b}
22
let make = ({a, b}: props<'a, 'b>) => {
33
Js.log("This function should be named 'TopLevel.react'")
44
ReactDOMRe.createDOMElementVariadic("div", [])

tests/ppx/react/expected/typeConstraint.res_v4_auto.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
1+
type props<'a, 'b> = {key?: string, a: 'a, b: 'b}
22
let make: 'a. (~a: 'a, ~b: 'a, 'a) => React.element = (_: props<'a, 'b>, type a): (
33
(~a: a, ~b: a, a) => React.element
44
) => (~a, ~b, _) => ReactDOMRe.createDOMElementVariadic("div", [])

tests/ppx/react/expected/typeConstraint.res_v4_cls.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b}
1+
type props<'a, 'b> = {key?: string, a: 'a, b: 'b}
22
let make: 'a. (~a: 'a, ~b: 'a, 'a) => React.element = (_: props<'a, 'b>, type a): (
33
(~a: a, ~b: a, a) => React.element
44
) => (~a, ~b, _) => ReactDOMRe.createDOMElementVariadic("div", [])

0 commit comments

Comments
 (0)