I would like to bring your attention to an open GitHub issue discussing the implementation of Preserve Mode in ReScript. For those unfamiliar, Preserve Mode is a feature that maintains the original formatting and structure of JSX expressions in the JavaScript output generated by the ReScript compiler.
This feature could potentially enhance the readability and maintainability of the compiled output containing JSX, making it easier for developers to work with and understand the generated code. Furthermore, Preserve Mode could allow for better compatibility with frameworks like Preact and SolidJS, expanding the reach and applicability of ReScript.
Example:
@react.component
let make = () => {
let (user, setUser) = React.Uncurried.useState(_ => "mununki")
<div>
<p> {`${user} uses ReScript`->React.string} </p>
<input value=user onChange={e => setUser(._ => (e->JsxEventC.Form.target)["value"])} />
</div>
}
preserved JSX
function Preserve(props) {
var match = React.useState(function (param) {
return "mununki";
});
var setUser = match[1];
var user = match[0];
return (
<div>
<p> user + " uses ReScript" </p>
<input
value={user}
onChange={function (e) {
setUser(function (param) {
return e.target.value;
});
}}
/>
</div>
);
}
We would love to hear your thoughts on Preserve Mode and how it could be beneficial to the ReScript community. Additionally, if you have any use cases or scenarios where Preserve Mode would be particularly useful, please share them with us.
We’re also interested in understanding which specific frameworks you think could benefit from this feature and how their individual requirements may differ with respect to Preserve Mode. Your feedback will be invaluable in determining whether this feature should be considered for future development and how it can be tailored to suit the needs of various frameworks.
Thank you for your input!