This repository was archived by the owner on Jun 15, 2023. It is now read-only.
This repository was archived by the owner on Jun 15, 2023. It is now read-only.
Jsx4 automatic mode: suspicious Caml_option.some
#667
Closed
Description
Context
Dependencies:
"@rescript/react": "^0.11.0-alpha.1",
"rescript": "^10.1.0-alpha.2",
bsconfig.json
{
"name": "speedycal",
"version": "0.0.1",
"sources": {
"dir": "src"
},
"package-specs": {
"module": "es6",
"in-source": true
},
"suffix": ".js",
"jsx": { "version": 4, "mode": "automatic" },
"bs-dependencies": ["@rescript/react"]
}
What am I seeing?
// Doctor.res
module User = {
type t = {firstName: string, lastName: string}
let format = user => "Dr." ++ user.lastName
@react.component
let make = (~doctor) => {
<h1> {React.string(format(doctor))} </h1>
}
}
Compiles to:
function Doctor$User(props) {
return JsxRuntime.jsx("h1", {
children: Caml_option.some("Dr." + props.doctor.lastName)
});
}
The Caml_option.some
seems suspicious in the output. The type of ~doctor
is t
, it isn't optional.
If you compare this with what's running in the playground right now: link to working code
// Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
var React = require("react");
function format(user) {
return "Dr." + user.lastName;
}
function Playground$User(Props) {
var doctor = Props.doctor;
return React.createElement("h1", undefined, "Dr." + doctor.lastName);
}
var User = {
format: format,
make: Playground$User
};
exports.User = User;
/* react Not a pure module */
We don't have any Caml_option.some
here.
Any pointers on why I might be seeing Caml_option.some
in the output? cc @mattdamon108 @cristianoc
Debug info
test file:
type t = {firstName: string, lastName: string}
let format = user => "Dr." ++ user.lastName
@react.component
let make = (~doctor) => {
<h1> {React.string(format(doctor))} </h1>
}
With dune exec -- rescript -jsx-mode automatic -jsx-version 4 -print res test.res
:
type t = {firstName: string, lastName: string}
let format = user => "Dr." ++ user.lastName
type props<'doctor> = {
doctor: 'doctor,
}
@react.component
let make = ({doctor, _}: props<'doctor>) => {
ReactDOM.jsx("h1", {children: {React.string(format(doctor))}})
}
let make = {
let \"Test" = (props: props<_>) => make(props)
\"Test"
}
With dune exec -- rescript -jsx-version 3 -print res test.res
:
type t = {firstName: string, lastName: string}
let format = user => "Dr." ++ user.lastName
@obj external makeProps: (~doctor: 'doctor, ~key: string=?, unit) => {"doctor": 'doctor} = ""
@react.component
let make =
(@warning("-16") ~doctor) => {
ReactDOMRe.createDOMElementVariadic("h1", [{React.string(format(doctor))}])
}
let make = {
let \"Test" = (\"Props": {"doctor": 'doctor}) => make(~doctor=\"Props"["doctor"])
\"Test"
}
Metadata
Metadata
Assignees
Labels
No labels