Skip to content

Commit 514bc12

Browse files
committed
restore some punning behaviour
Preserve `isMobile={isMobile}` when it's like that in the source, instead of reformatting to `isMobile`. Do we want that?
1 parent 9126e0f commit 514bc12

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

compiler/syntax/src/res_printer.ml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4553,7 +4553,10 @@ and print_jsx_props ~state args cmt_tbl : Doc.t * Parsetree.expression option =
45534553
and print_jsx_prop ~state arg cmt_tbl =
45544554
match arg with
45554555
| ( ((Asttypes.Lbl {txt = lbl_txt} | Opt {txt = lbl_txt}) as lbl),
4556-
{pexp_desc = Pexp_ident {txt = Longident.Lident ident}} )
4556+
{
4557+
pexp_attributes = [];
4558+
pexp_desc = Pexp_ident {txt = Longident.Lident ident};
4559+
} )
45574560
when lbl_txt = ident (* jsx punning *) -> (
45584561
match lbl with
45594562
| Nolbl -> Doc.nil
@@ -4878,7 +4881,10 @@ and print_argument ~state (arg_lbl, arg) cmt_tbl =
48784881
match (arg_lbl, arg) with
48794882
(* ~a (punned)*)
48804883
| ( Lbl {txt = lbl; loc = l0},
4881-
{pexp_desc = Pexp_ident {txt = Longident.Lident name}} )
4884+
{
4885+
pexp_attributes = [];
4886+
pexp_desc = Pexp_ident {txt = Longident.Lident name};
4887+
} )
48824888
when lbl = name && not (ParsetreeViewer.is_braced_expr arg) ->
48834889
let loc = {l0 with loc_end = arg.pexp_loc.loc_end} in
48844890
let doc = Doc.concat [Doc.tilde; print_ident_like lbl] in
@@ -4890,6 +4896,7 @@ and print_argument ~state (arg_lbl, arg) cmt_tbl =
48904896
Pexp_constraint
48914897
( ({pexp_desc = Pexp_ident {txt = Longident.Lident name}} as arg_expr),
48924898
typ );
4899+
pexp_attributes = [];
48934900
} )
48944901
when lbl = name && not (ParsetreeViewer.is_braced_expr arg_expr) ->
48954902
let loc = {l0 with loc_end = arg.pexp_loc.loc_end} in
@@ -4904,7 +4911,11 @@ and print_argument ~state (arg_lbl, arg) cmt_tbl =
49044911
in
49054912
print_comments doc cmt_tbl loc
49064913
(* ~a? (optional lbl punned)*)
4907-
| Opt {txt = lbl; loc}, {pexp_desc = Pexp_ident {txt = Longident.Lident name}}
4914+
| ( Opt {txt = lbl; loc},
4915+
{
4916+
pexp_desc = Pexp_ident {txt = Longident.Lident name};
4917+
pexp_attributes = [];
4918+
} )
49084919
when lbl = name ->
49094920
let doc = Doc.concat [Doc.tilde; print_ident_like lbl; Doc.question] in
49104921
print_comments doc cmt_tbl loc

tests/syntax_tests/data/printer/expr/expected/jsx.res.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let x =
5151
let x = <div className="container" className2="container2" className3="container3" onClick />
5252

5353
let nav =
54-
<Nav isMobile fullScreen={!isMobile ? false : isOpen}>
54+
<Nav isMobile={isMobile} fullScreen={!isMobile ? false : isOpen}>
5555
<NavContent>
5656
<WidescreenMenu
5757
menuItems={props.items} trial={props.trial} user={props.user} viewer={props.viewer}
@@ -60,14 +60,14 @@ let nav =
6060
</Nav>
6161

6262
let nav2 =
63-
<Nav isMobile fullScreen={!isMobile ? false : isOpen}>
63+
<Nav isMobile={isMobile} fullScreen={!isMobile ? false : isOpen}>
6464
<NavContent>
6565
{switch isMobile {
6666
| true =>
6767
<MobileMenu
6868
handleOpenToggle={_ => setOpen(open_ => !open_)}
6969
menuItems={props.items}
70-
isOpen
70+
isOpen={isOpen}
7171
forceOpen={_ => setOpen(true)}
7272
forceClose={_ => setOpen(false)}
7373
user={props.user}
@@ -82,13 +82,13 @@ let nav2 =
8282
</Nav>
8383

8484
let nav3 =
85-
<Nav isMobile fullScreen={!isMobile ? false : isOpen}>
85+
<Nav isMobile={isMobile} fullScreen={!isMobile ? false : isOpen}>
8686
<NavContent>
8787
{isMobile
8888
? <MobileMenu
8989
handleOpenToggle={_ => setOpen(open_ => !open_)}
9090
menuItems={props.items}
91-
isOpen
91+
isOpen={isOpen}
9292
forceOpen={_ => setOpen(true)}
9393
forceClose={_ => setOpen(false)}
9494
user={props.user}
@@ -102,7 +102,7 @@ let nav3 =
102102
let avatarSection =
103103
<>
104104
<div style={{"zIndex": "1", "opacity": opacityUser}}>
105-
<Avatar user size={45} />
105+
<Avatar user={user} size={45} />
106106
</div>
107107
{user.email !== viewer.email
108108
? <div

0 commit comments

Comments
 (0)