Skip to content

Commit 870906d

Browse files
authored
Revert "Further improve JSX preserve output (#7445)" (#7475)
This reverts commit 8f9e0f1. # Conflicts: # tests/tests/src/jsx_preserve_test.mjs
1 parent dc88212 commit 870906d

File tree

2 files changed

+38
-45
lines changed

2 files changed

+38
-45
lines changed

compiler/core/js_dump.ml

+8-15
Original file line numberDiff line numberDiff line change
@@ -1123,23 +1123,13 @@ and print_jsx cxt ?(spread_props : J.expression option)
11231123
fields
11241124
in
11251125
let print_props cxt props =
1126-
let print_prop_value (x : J.expression) ctx =
1127-
let needs_braces =
1128-
match x.expression_desc with
1129-
| Str _ | Optional_block ({expression_desc = Str _}, _) -> false
1130-
| _ -> true
1131-
in
1132-
if needs_braces then P.string f "{";
1133-
let next_cxt = expression ~level:0 ctx f x in
1134-
if needs_braces then P.string f "}";
1135-
next_cxt
1136-
in
1137-
11381126
(* If a key is present, should be printed before the spread props,
11391127
This is to ensure tools like ESBuild use the automatic JSX runtime *)
11401128
let print_key key cxt =
1141-
P.string f "key=";
1142-
print_prop_value key cxt
1129+
P.string f "key={";
1130+
let cxt_k = expression ~level:0 cxt f key in
1131+
P.string f "} ";
1132+
cxt_k
11431133
in
11441134

11451135
let print_spread_props spread cxt =
@@ -1153,7 +1143,10 @@ and print_jsx cxt ?(spread_props : J.expression option)
11531143
let prop_name = Ext_ident.unwrap_uppercase_exotic n in
11541144
P.string f prop_name;
11551145
P.string f "=";
1156-
print_prop_value x ctx
1146+
P.string f "{";
1147+
let next_cxt = expression ~level:0 ctx f x in
1148+
P.string f "}";
1149+
next_cxt
11571150
in
11581151
let printable_props =
11591152
(match key with

tests/tests/src/jsx_preserve_test.mjs

+30-30
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,21 @@ let _single_element_fragment = <>
2929

3030
let _multiple_element_fragment = <>
3131
<input
32-
type="text"
32+
type={"text"}
3333
/>
3434
<input
35-
type="number"
35+
type={"number"}
3636
/>
3737
</>;
3838

3939
let _unary_element_with_props = <input
40-
className="foo"
41-
type="text"
40+
className={"foo"}
41+
type={"text"}
4242
/>;
4343

4444
let _container_element_with_props_and_children = <div
45-
className="foo"
46-
title="foo"
45+
className={"foo"}
46+
title={"foo"}
4747
>
4848
{"Hello, world!"}
4949
</div>;
@@ -57,19 +57,19 @@ let newrecord = {...baseProps};
5757

5858
let _unary_element_with_spread_props = <input
5959
{...newrecord}
60-
type="text"
60+
type={"text"}
6161
/>;
6262

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

6565
let _container_with_spread_props = <div
6666
{...newrecord$1}
67-
title="barry"
68-
className="barry"
67+
title={"barry"}
68+
className={"barry"}
6969
>
7070
{"Hello, world!"}
7171
<input
72-
type="text"
72+
type={"text"}
7373
/>
7474
</div>;
7575

@@ -83,8 +83,8 @@ let baseChildren = [
8383
];
8484

8585
let _container_with_spread_children = <div
86-
className="barry"
87-
title="barry"
86+
className={"barry"}
87+
title={"barry"}
8888
>
8989
{baseChildren}
9090
</div>;
@@ -93,31 +93,31 @@ let newrecord$2 = {...baseProps};
9393

9494
let _container_with_spread_props_and_children = <div
9595
{...newrecord$2}
96-
title="barry"
97-
className="barry"
96+
title={"barry"}
97+
className={"barry"}
9898
>
9999
{baseChildren}
100100
</div>;
101101

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

104104
let _unary_element_with_spread_props_keyed = <input
105-
key="barry-key"
105+
key={"barry-key"}
106106
{...newrecord$3}
107-
type="text"
107+
type={"text"}
108108
/>;
109109

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

112112
let _container_with_spread_props_keyed = <div
113-
key="barry-key"
113+
key={"barry-key"}
114114
{...newrecord$4}
115-
title="barry"
116-
className="barry"
115+
title={"barry"}
116+
className={"barry"}
117117
>
118118
{"Hello, world!"}
119119
<input
120-
type="text"
120+
type={"text"}
121121
/>
122122
</div>;
123123

@@ -156,29 +156,29 @@ let MyWeirdComponent = {
156156
};
157157

158158
let _escaped_jsx_prop = <Jsx_preserve_test$MyWeirdComponent
159-
MyWeirdProp="bar"
159+
MyWeirdProp={"bar"}
160160
/>;
161161

162162
let _large_component = <div
163-
className="bar"
163+
className={"bar"}
164164
tabIndex={1}
165-
title="foo"
165+
title={"foo"}
166166
onClick={param => {}}
167167
onMouseDown={param => {}}
168168
>
169169
<p
170-
className="bar"
170+
className={"bar"}
171171
tabIndex={1}
172-
title="foo"
172+
title={"foo"}
173173
onClick={param => {}}
174174
onMouseDown={param => {}}
175175
>
176176
{"Hello, world!"}
177177
</p>
178178
<strong
179-
className="bar"
179+
className={"bar"}
180180
tabIndex={1}
181-
title="foo"
181+
title={"foo"}
182182
onClick={param => {}}
183183
onMouseDown={param => {}}
184184
>
@@ -199,13 +199,13 @@ let ComponentWithOptionalProps = {
199199

200200
let _optional_props = <Jsx_preserve_test$ComponentWithOptionalProps
201201
i={1}
202-
s="test"
202+
s={"test"}
203203
element={<div />}
204204
/>;
205205

206206
let _props_with_hyphen = <label
207-
aria-label="close sidebar"
208-
data-testid="test"
207+
aria-label={"close sidebar"}
208+
data-testid={"test"}
209209
/>;
210210

211211
export {

0 commit comments

Comments
 (0)