Skip to content

Jsx adaptions #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions bsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"reason": { "react-jsx": 3 },
"sources": [
{"dir": "src", "subdirs": true},
{ "dir": "test", "type": "dev" }
{ "dir": "test", "subdirs": true, "type": "dev" }
],
"package-specs": [{ "module": "commonjs", "in-source": true }],
"package-specs": [{ "module": "es6", "in-source": true }],
"suffix": ".bs.js",
"bs-dev-dependencies": ["reason-test-framework"],
"bsc-flags": ["-bs-no-version-header"]
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"homepage": "https://rescript-lang.org/docs/latest/react/",
"devDependencies": {
"bs-platform": "8.4.2",
"esm": "^3.2.25",
"jest": "^26.0.1",
"react": "^16.8.1",
"react-dom": "^16.8.1",
Expand Down
8 changes: 4 additions & 4 deletions src/React.res
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ external cloneElement: (element, 'props) => element = "cloneElement"
external createElementVariadic: (component<'props>, 'props, array<element>) => element =
"createElement"

@module("react") @deprecated("Please use JSX syntax directly.")
@module("react/jsx-runtime")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we still want the @deprecated here. We want people to use JSX syntax or createElement. If we need to create a directly usable api we can do that outside of this work.

external jsxKeyed: (component<'props>, 'props, string) => element = "jsx"

@module("react") @deprecated("Please use JSX syntax directly.")
@module("react/jsx-runtime")
external jsx: (component<'props>, 'props) => element = "jsx"

@module("react") @deprecated("Please use JSX syntax directly.")
@module("react/jsx-runtime")
external jsxs: (component<'props>, 'props) => element = "jsxs"

@module("react") @deprecated("Please use JSX syntax directly.")
@module("react/jsx-runtime")
external jsxsKeyed: (component<'props>, 'props, string) => element = "jsxs"

type ref<'value> = {mutable current: 'value}
Expand Down
30 changes: 30 additions & 0 deletions test/v4-ppx/BasicComponent.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@@warning("-27")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this coming from? I don't think the ppx adds -27 so I'm surprised to see it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caused by this line

let \"Foo$App" = (\"Props": {.}) => make()

"Props" is not being used here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the -27 attribute manually though


module Test = {
@bs.obj external makeProps: (~children: 'children, unit) => {"children": 'children} = ""
let make =
(@warning("-16") ~children) => {
children
}
let make = {
let \"Foo$Test" = (\"Props": {"children": 'children}) => make(~children=\"Props"["children"])
\"Foo$Test"
}
}

module App = {
@bs.obj external makeProps: unit => {.} = ""

let make = () => {
(@warning("-3") React.jsx)(
Test.make,
{
Test.makeProps(~children={React.string("help")}, ())
},
)
}
let make = {
let \"Foo$App" = (\"Props": {.}) => make()
\"Foo$App"
}
}
48 changes: 48 additions & 0 deletions test/v4-ppx/KeyedComp.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
@@warning("-27")

module Test = {
@bs.obj external makeProps: (~children: 'children, unit) => {"children": 'children} = ""
let make =
(@warning("-16") ~children) => {
children
}
let make = {
let \"Foo$Test" = (\"Props": {"children": 'children}) => make(~children=\"Props"["children"])
\"Foo$Test"
}
}

module App = {
@bs.obj external makeProps: unit => {.} = ""

let make = () => {
@warning("-3")
React.jsxs(
React.Fragment.make,
React.Fragment.makeProps(
~children=React.array([
(@warning("-3") React.jsx)(
Test.make,
Test.makeProps(~children={React.string("help")}, ()),
),
(@warning("-3") React.jsxKeyed)(
Test.make,
Test.makeProps(~children={React.string("help")}, ()),
"test",
),
]),
(),
),
)
}
let make = {
let \"Foo$App" = (\"Props": {.}) => make()
\"Foo$App"
}
}

let element = <App/>


ReactDOMServer.renderToString(element)->Js.log