Skip to content

JSX Preserve Mode #6197

Open
Open
@mununki

Description

@mununki

I would like to initiate a discussion on a potential feature: Preserve Mode for JSX expressions. The Preserve Mode is a functionality that, when enabled, maintains the original formatting and structure of JSX expressions in the JavaScript output generated by the compiler.

As the ReScript ecosystem evolves, it is worth exploring whether introducing Preserve Mode for JSX expressions to the compiler would be beneficial for the community. 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. Another significant advantage of Preserve Mode is the possibility of using ReScript with frameworks like Preact and SolidJS, expanding the reach and applicability of the language.

Please share your thoughts and experiences regarding the necessity and potential benefits of implementing Preserve Mode for JSX expressions in the ReScript compiler. Do you think it is a valuable addition, or are there any concerns or technical challenges that might arise from its implementation?

@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>
  );
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In progress

Relationships

None yet

Development

No branches or pull requests

Issue actions