Skip to content

Preserve JSX #7387

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

Merged
merged 31 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
ffc7666
Add additional node to Pexp_apply
nojaf Apr 10, 2025
92e38cb
Try and pass jsx_element from typed_tree to js_call
nojaf Apr 10, 2025
dd56e61
Follow Lprim
nojaf Apr 11, 2025
a0c170f
Transform initial simple element
nojaf Apr 23, 2025
a98e3b8
Initial fragment support
nojaf Apr 24, 2025
1801da1
WIP extract, good stuff
nojaf Apr 24, 2025
ab32462
Print props, catch with key functions
nojaf Apr 25, 2025
6b075c0
Don't pass untyped ast, simple flag is sufficient.
nojaf Apr 25, 2025
d0bfedc
Support fragments
nojaf Apr 25, 2025
3d2930e
Unwrap children
nojaf May 3, 2025
547dfca
Poor man feature flag
nojaf May 3, 2025
09950f1
Remove duplicated in
nojaf May 3, 2025
0ab6987
Older camls
nojaf May 3, 2025
8e4811b
Revert "Poor man feature flag"
nojaf May 3, 2025
aa94f6f
Add new -bs-jsx-preserve flag
nojaf May 3, 2025
e30cab3
WIP, deal with prop spreading
nojaf May 4, 2025
773124f
Deal with prop spreading
nojaf May 4, 2025
46d3d50
Clean up Lprim and move the information to the call primitive.
cristianoc May 4, 2025
1a20f38
Add test for spreading children
nojaf May 4, 2025
8929f37
Refactor duplicate code
nojaf May 4, 2025
cecf67d
Support keyed and prop spreading
nojaf May 4, 2025
3fcf1df
Rename test file
nojaf May 4, 2025
8b7eb45
Keep key prop before spreading props. Also ensure test can run.
nojaf May 4, 2025
90b28f0
Add only spread props case
nojaf May 4, 2025
faa5618
Give record a name
nojaf May 5, 2025
400b550
Use config flag in Js_dump instead
nojaf May 5, 2025
3e1867e
Remove helper code
nojaf May 5, 2025
32bffd8
Extra call info
nojaf May 5, 2025
f104529
Detect direct Array as well
nojaf May 5, 2025
848b3ab
Don't run with mocha
nojaf May 5, 2025
aceb0e2
Feedback code review
nojaf May 5, 2025
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
Prev Previous commit
Next Next commit
Support keyed and prop spreading
  • Loading branch information
nojaf committed May 4, 2025
commit cecf67d8094582916f2561ba4bad79e3d7808281
21 changes: 21 additions & 0 deletions compiler/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,27 @@ and expression_desc cxt ~(level : int) f x : cxt =
visit [] props
in
print_jsx cxt ~level ~spread_props f fnName tag fields
(* In the case of prop spreading and keyed *)
| [tag; ({expression_desc = J.Seq _} as props); key] ->
let fields, spread_props =
let rec visit acc e =
match e.J.expression_desc with
| J.Seq
( {
J.expression_desc =
J.Bin
( Js_op.Eq,
{J.expression_desc = J.Static_index (_, name, _)},
value );
},
rest ) ->
visit ((name, value) :: acc) rest
| _ -> (List.rev acc, e)
in
visit [] props
in
let fields = ("key", key) :: fields in
print_jsx cxt ~level ~spread_props f fnName tag fields
| _ ->
expression_desc cxt ~level f
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this code branch ever executed?

Copy link
Member Author

Choose a reason for hiding this comment

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

If it is, it means we missed something. Could we add some sort of assert in this case?

(Call
Expand Down
17 changes: 12 additions & 5 deletions tests/tests/src/nojaf.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ let _unary_element_with_spread_props = <input {...newrecord} type={"text"}/>;

let newrecord$1 = {...baseProps};

let _container_with_spread_props = <div {...newrecord$1} title={"barry"} className={"barry"}>{"Hello, world!"}
<input type={"text"}/>
</div>;
let _container_with_spread_props = <div {...newrecord$1} title={"barry"} className={"barry"}>{"Hello, world!"}<input type={"text"}/></div>;

let baseChildren = [
<span>{"Hello, world!"}</span>,
Expand All @@ -51,8 +49,15 @@ let _container_with_spread_children = <div className={"barry"} title={"barry"}>{

let newrecord$2 = {...baseProps};

let _container_with_spread_props_and_children = <div {...newrecord$2} title={"barry"} className={"barry"}>{baseChildren}
</div>;
let _container_with_spread_props_and_children = <div {...newrecord$2} title={"barry"} className={"barry"}>{baseChildren}</div>;

let newrecord$3 = {...baseProps};

let _unary_element_with_spread_props_keyed = <input {...newrecord$3} key={"barry-key"} type={"text"}/>;

let newrecord$4 = {...baseProps};

let _container_with_spread_props_keyed = <div {...newrecord$4} key={"barry-key"} title={"barry"} className={"barry"}>{"Hello, world!"}<input type={"text"}/></div>;

export {
React,
Expand All @@ -70,5 +75,7 @@ export {
baseChildren,
_container_with_spread_children,
_container_with_spread_props_and_children,
_unary_element_with_spread_props_keyed,
_container_with_spread_props_keyed,
}
/* _single_element_child Not a pure module */
8 changes: 8 additions & 0 deletions tests/tests/src/nojaf.res
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,11 @@ let _container_with_spread_children = <div title="barry" className="barry"> ...b

let _container_with_spread_props_and_children =
<div {...baseProps} title="barry" className="barry"> ...baseChildren </div>

let _unary_element_with_spread_props_keyed = <input {...baseProps} type_="text" key="barry-key" />

let _container_with_spread_props_keyed =
<div {...baseProps} title="barry" className="barry" key="barry-key">
{React.string("Hello, world!")}
<input type_="text" />
</div>