Repository navigation
Preserve JSX - #7387
Preserve JSX#7387
Conversation
|
Got an initial result here, was able to transform: module ReactDOM = {
@module("react/jsx-runtime")
external jsx: (string, JsxDOM.domProps) => Jsx.element = "jsx"
}
let _ = <div className="meh"></div>into // Generated by ReScript, PLEASE EDIT WITH CARE
'use strict';
let JsxRuntime = require("react/jsx-runtime");
let ReactDOM = {};
<div className={"meh"}></div>;
exports.ReactDOM = ReactDOM;There are still a lot of cases to cover, but it is a start. |
|
Made some more progress, was able to transform my entire project. |
rescript
@rescript/darwin-arm64
@rescript/darwin-x64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/win32-x64
commit: |
This reverts commit 547dfca.
|
@cknitt you can test this by: npm i "https://pkg.pr.new/rescript-lang/rescript@f10452935ae8bc0325116323ee9b55f61c1827be"
"suffix": ".res.jsx",
"jsx": {
"version": 4
},
"bsc-flags": [
"-bs-jsx-preserve"
](suffix not strictly required) |
|
@cristianoc, this is now functioning effectively. Could you please review this approach? If it seems reasonable, we can refine it. |
cristianoc
left a comment
There was a problem hiding this comment.
Looks pretty good.
Main question is if there's a way to avoid extending every Lprim with a boolean, and the scope of changes can be restricted somehow.
| let fields = ("key", key) :: fields in | ||
| print_jsx cxt ~level f fnName tag fields | ||
| | _ -> | ||
| expression_desc cxt ~level f |
There was a problem hiding this comment.
Is this code branch ever executed?
There was a problem hiding this comment.
If it is, it means we missed something. Could we add some sort of assert in this case?
|
@cristianoc could you check e30cab3 and 773124f as well. Had to write some new to deal with prop spreading. |
cristianoc
left a comment
There was a problem hiding this comment.
minor style comments, plus the test does not seem to use preserve mode at the moment?
| { | ||
| arity = Full; | ||
| call_info = Call_ml; | ||
| (* no clue if this is correct *) call_transformed_jsx = false; |
There was a problem hiding this comment.
maybe use one of the existing default constants for this -- seems likely to be correct as these are generated applications, not coming from jsx ppx
| { | ||
| arity = Full; | ||
| call_info = Call_ml; | ||
| (* no clue if this is correct *) call_transformed_jsx = |
| (E.call | ||
| ~info: | ||
| { | ||
| arity = Full; |
There was a problem hiding this comment.
how about {...one_of_those_constants, transformed_jsx}
| { | ||
| arity = Full; | ||
| call_info = Call_na; | ||
| call_transformed_jsx = transformed_jsx; |
| ~info: | ||
| { | ||
| arity = Full; | ||
| call_info = Call_na; |
| ~info: | ||
| { | ||
| arity = Full; | ||
| call_info = Call_na; |
| call_transformed_jsx = transformed_jsx; | ||
| } | ||
| (E.dot self name) args) | ||
| else |
| ~info: | ||
| { | ||
| arity = Full; | ||
| call_info = Call_na; |
| ~info: | ||
| { | ||
| arity = Full; | ||
| call_info = Call_na; |
cristianoc
left a comment
There was a problem hiding this comment.
Looks good to go!
Merge away after any final small cleanup.
* Add additional node to Pexp_apply * Try and pass jsx_element from typed_tree to js_call * Follow Lprim * Transform initial simple element * Initial fragment support * WIP extract, good stuff * Print props, catch with key functions * Don't pass untyped ast, simple flag is sufficient. * Support fragments * Unwrap children * Poor man feature flag * Remove duplicated in * Older camls * Revert "Poor man feature flag" This reverts commit 547dfca. * Add new -bs-jsx-preserve flag * WIP, deal with prop spreading * Deal with prop spreading * Clean up Lprim and move the information to the call primitive. * Add test for spreading children * Refactor duplicate code * Support keyed and prop spreading * Rename test file * Keep key prop before spreading props. Also ensure test can run. * Add only spread props case * Give record a name * Use config flag in Js_dump instead * Remove helper code * Extra call info * Detect direct Array as well * Don't run with mocha * Feedback code review --------- Co-authored-by: Cristiano Calcagno <cristianoc@users.noreply.github.com> Signed-off-by: Pedro Castro <aspeddro@gmail.com>
@cristianoc, this doesn't work yet, but it highlights the idea. Could you point out where the information is not passed? It's a bit overwhelming for me to grasp.