This repository has been archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for v3 and v4 respectively
- Loading branch information
Showing
22 changed files
with
259 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@obj external makeProps: (~msg: 'msg, ~key: string=?, unit) => {"msg": 'msg} = "" // test React JSX file | ||
|
||
let make = | ||
(@warning("-16") ~msg) => { | ||
ReactDOMRe.createDOMElementVariadic("div", [{msg->React.string}]) | ||
} | ||
let make = { | ||
let \"CommentAtTop" = (\"Props": {"msg": 'msg}) => make(~msg=\"Props"["msg"]) | ||
\"CommentAtTop" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type props<'msg> = {@optional key: string, msg: 'msg} // test React JSX file | ||
|
||
let make = ({msg}: props<'msg>) => { | ||
ReactDOMRe.createDOMElementVariadic("div", [{msg->React.string}]) | ||
} | ||
let make = { | ||
let \"CommentAtTop" = (props: props<_>) => make(props) | ||
\"CommentAtTop" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Foo = { | ||
@obj | ||
external componentProps: (~a: int, ~b: string, ~key: string=?, unit) => {"a": int, "b": string} = | ||
"" | ||
@module("Foo") | ||
external component: React.componentLike<{"a": int, "b": string}, React.element> = "component" | ||
} | ||
|
||
let t = React.createElement(Foo.component, Foo.componentProps(~a=1, ~b={"1"}, ())) |
7 changes: 7 additions & 0 deletions
7
tests/ppx/react/expected/externalWithCustomName.res_v4_auto.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Foo = { | ||
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} | ||
@module("Foo") | ||
external component: React.componentLike<props<'a, 'b>, React.element> = "component" | ||
} | ||
|
||
let t = React.jsx(Foo.component, {a: 1, b: "1"}) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
module FancyInput = { | ||
@obj | ||
external makeProps: ( | ||
~className: 'className=?, | ||
~children: 'children, | ||
~key: string=?, | ||
~ref: 'ref=?, | ||
unit, | ||
) => {"className": option<'className>, "children": 'children} = "" | ||
let make = | ||
(@warning("-16") ~className=?, @warning("-16") ~children) => | ||
@warning("-16") | ||
ref => | ||
ReactDOMRe.createDOMElementVariadic( | ||
"div", | ||
[ | ||
ReactDOMRe.createDOMElementVariadic( | ||
"input", | ||
~props=ReactDOMRe.domProps( | ||
~type_="text", | ||
~className?, | ||
~ref=?{Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)}, | ||
(), | ||
), | ||
[], | ||
), | ||
children, | ||
], | ||
) | ||
let make = React.forwardRef({ | ||
let \"ForwardRef$FancyInput" = ( | ||
\"Props": {"className": option<'className>, "children": 'children}, | ||
ref, | ||
) => make(~children=\"Props"["children"], ~className=?\"Props"["className"], ref) | ||
\"ForwardRef$FancyInput" | ||
}) | ||
} | ||
@obj external makeProps: (~key: string=?, unit) => {.} = "" | ||
|
||
let make = () => { | ||
let input = React.useRef(Js.Nullable.null) | ||
|
||
ReactDOMRe.createDOMElementVariadic( | ||
"div", | ||
[ | ||
React.createElement( | ||
FancyInput.make, | ||
FancyInput.makeProps(~ref=input, ~children={React.string("Click to focus")}, ()), | ||
), | ||
], | ||
) | ||
} | ||
let make = { | ||
let \"ForwardRef" = (\"Props": {.}) => make() | ||
\"ForwardRef" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
module FancyInput = { | ||
type props<'className, 'children> = { | ||
@optional key: string, | ||
@optional className: 'className, | ||
children: 'children, | ||
@optional ref: ReactDOM.Ref.currentDomRef, | ||
} | ||
let make = ({className, children, ref}: props<'className, 'children>) => { | ||
let ref = Js.Nullable.fromOption(ref) | ||
let _ = ref | ||
|
||
ReactDOMRe.createDOMElementVariadic( | ||
"div", | ||
[ | ||
ReactDOMRe.createDOMElementVariadic( | ||
"input", | ||
~props=ReactDOMRe.domProps( | ||
~type_="text", | ||
~className?, | ||
~ref=?{Js.Nullable.toOption(ref)->Belt.Option.map(ReactDOM.Ref.domRef)}, | ||
(), | ||
), | ||
[], | ||
), | ||
children, | ||
], | ||
) | ||
} | ||
let make = React.forwardRef({ | ||
let \"ForwardRef$FancyInput" = (props: props<_>, ref) => | ||
make({...props, ref: @optional Js.Nullable.toOption(ref)}) | ||
\"ForwardRef$FancyInput" | ||
}) | ||
} | ||
type props = {@optional key: string} | ||
|
||
let make = (_: props) => { | ||
let input = React.useRef(Js.Nullable.null) | ||
|
||
ReactDOMRe.createDOMElementVariadic( | ||
"div", | ||
[React.jsx(FancyInput.make, {ref: input, children: {React.string("Click to focus")}})], | ||
) | ||
} | ||
let make = { | ||
let \"ForwardRef" = props => make(props) | ||
\"ForwardRef" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module Bar = { | ||
@obj external makeProps: (~a: 'a, ~b: 'b, ~key: string=?, unit) => {"a": 'a, "b": 'b} = "" | ||
let make = | ||
(@warning("-16") ~a, @warning("-16") ~b, _) => { | ||
Js.log("This function should be named `InnerModule.react$Bar`") | ||
ReactDOMRe.createDOMElementVariadic("div", []) | ||
} | ||
let make = { | ||
let \"InnerModule$Bar" = (\"Props": {"a": 'a, "b": 'b}) => | ||
make(~b=\"Props"["b"], ~a=\"Props"["a"], ()) | ||
\"InnerModule$Bar" | ||
} | ||
@obj external componentProps: (~a: 'a, ~b: 'b, ~key: string=?, unit) => {"a": 'a, "b": 'b} = "" | ||
|
||
let component = | ||
(@warning("-16") ~a, @warning("-16") ~b, _) => { | ||
Js.log("This function should be named `InnerModule.react$Bar$component`") | ||
ReactDOMRe.createDOMElementVariadic("div", []) | ||
} | ||
let component = { | ||
let \"InnerModule$Bar$component" = (\"Props": {"a": 'a, "b": 'b}) => | ||
component(~b=\"Props"["b"], ~a=\"Props"["a"], ()) | ||
\"InnerModule$Bar$component" | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Bar = { | ||
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} | ||
let make = ({a, b}: props<'a, 'b>) => { | ||
Js.log("This function should be named `InnerModule.react$Bar`") | ||
ReactDOMRe.createDOMElementVariadic("div", []) | ||
} | ||
let make = { | ||
let \"InnerModule$Bar" = (props: props<_>) => make(props) | ||
\"InnerModule$Bar" | ||
} | ||
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} | ||
|
||
let component = ({a, b}: props<'a, 'b>) => { | ||
Js.log("This function should be named `InnerModule.react$Bar$component`") | ||
ReactDOMRe.createDOMElementVariadic("div", []) | ||
} | ||
let component = { | ||
let \"InnerModule$Bar$component" = (props: props<_>) => make(props) | ||
\"InnerModule$Bar$component" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
@obj | ||
external makeProps: ( | ||
~a: '\"type-a", | ||
~b: array<option<[#Foo('\"type-a")]>>, | ||
~c: 'a, | ||
~key: string=?, | ||
unit, | ||
) => {"a": '\"type-a", "b": array<option<[#Foo('\"type-a")]>>, "c": 'a} = "" | ||
let make = (type a, ~a: a, ~b: array<option<[#Foo(a)]>>, ~c: 'a, _) => | ||
ReactDOMRe.createDOMElementVariadic("div", []) | ||
let make = { | ||
let \"Newtype" = (\"Props": {"a": '\"type-a", "b": array<option<[#Foo('\"type-a")]>>, "c": 'a}) => | ||
make(~c=\"Props"["c"], ~b=\"Props"["b"], ~a=\"Props"["a"]) | ||
\"Newtype" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
type props<'a, 'b, 'c> = {@optional key: string, a: 'a, b: 'b, c: 'c} | ||
let make = (_: props<'a, 'b, 'c>, type a, ~a: a, ~b: array<option<[#Foo(a)]>>, ~c: 'a, _) => | ||
ReactDOMRe.createDOMElementVariadic("div", []) | ||
let make = { | ||
let \"Newtype" = (props: props<_>) => make(props) | ||
\"Newtype" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@obj external makeProps: (~a: 'a, ~b: 'b, ~key: string=?, unit) => {"a": 'a, "b": 'b} = "" | ||
let make = | ||
(@warning("-16") ~a, @warning("-16") ~b, _) => { | ||
Js.log("This function should be named 'TopLevel.react'") | ||
ReactDOMRe.createDOMElementVariadic("div", []) | ||
} | ||
let make = { | ||
let \"TopLevel" = (\"Props": {"a": 'a, "b": 'b}) => make(~b=\"Props"["b"], ~a=\"Props"["a"], ()) | ||
\"TopLevel" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} | ||
let make = ({a, b}: props<'a, 'b>) => { | ||
Js.log("This function should be named 'TopLevel.react'") | ||
ReactDOMRe.createDOMElementVariadic("div", []) | ||
} | ||
let make = { | ||
let \"TopLevel" = (props: props<_>) => make(props) | ||
\"TopLevel" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@obj external makeProps: (~a: 'a, ~b: 'b, ~key: string=?, unit) => {"a": 'a, "b": 'b} = "" | ||
let make: | ||
type a. (~a: a, ~b: a, a) => React.element = | ||
(~a, ~b, _) => ReactDOMRe.createDOMElementVariadic("div", []) | ||
let make = { | ||
let \"TypeConstraint" = (\"Props": {"a": 'a, "b": 'b}) => make(~b=\"Props"["b"], ~a=\"Props"["a"]) | ||
\"TypeConstraint" | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
type props<'a, 'b> = {@optional key: string, a: 'a, b: 'b} | ||
let make: 'a. (~a: 'a, ~b: 'a, 'a) => React.element = (_: props<'a, 'b>, type a): ( | ||
(~a: a, ~b: a, a) => React.element | ||
) => (~a, ~b, _) => ReactDOMRe.createDOMElementVariadic("div", []) | ||
let make = { | ||
let \"TypeConstraint" = (props: props<_>) => make(props) | ||
\"TypeConstraint" | ||
} |