Skip to content

Commit 312375d

Browse files
committed
wrap JSX children variables in curly braces
1 parent b4f3095 commit 312375d

File tree

9 files changed

+20
-16
lines changed

9 files changed

+20
-16
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#### :eyeglasses: Spec Compliance
2121

22+
- Wrap variables in curly braces inside JSX children. https://github.com/rescript-lang/rescript/pull/7863
23+
2224
#### :rocket: New Feature
2325

2426
- Add `Array.filterMapWithIndex` to Stdlib. https://github.com/rescript-lang/rescript/pull/7876

compiler/syntax/src/res_parens.ml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,14 @@ let jsx_child_expr expr =
371371
when starts_with_minus x ->
372372
Parenthesized
373373
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
374-
| _ when ParsetreeViewer.has_spread_attr expr.pexp_attributes -> Parenthesized
374+
| _ when ParsetreeViewer.has_spread_attr expr.pexp_attributes ->
375+
Parenthesized
375376
| {
376377
Parsetree.pexp_desc =
377-
( Pexp_constant _ | Pexp_field _ | Pexp_construct _
378-
| Pexp_variant _ | Pexp_array _ | Pexp_pack _ | Pexp_record _
379-
| Pexp_extension _ | Pexp_letmodule _ | Pexp_letexception _
380-
| Pexp_open _ | Pexp_sequence _ | Pexp_let _ | Pexp_jsx_element _ );
378+
( Pexp_constant _ | Pexp_field _ | Pexp_construct _ | Pexp_variant _
379+
| Pexp_array _ | Pexp_pack _ | Pexp_record _ | Pexp_extension _
380+
| Pexp_letmodule _ | Pexp_letexception _ | Pexp_open _
381+
| Pexp_sequence _ | Pexp_let _ | Pexp_jsx_element _ );
381382
pexp_attributes = [];
382383
} ->
383384
Nothing

compiler/syntax/src/res_parsetree_viewer.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ val has_await_attribute : Parsetree.attributes -> bool
1717
val has_inline_record_definition_attribute : Parsetree.attributes -> bool
1818
val has_res_pat_variant_spread_attribute : Parsetree.attributes -> bool
1919
val has_dict_pattern_attribute : Parsetree.attributes -> bool
20+
val has_spread_attr : Parsetree.attributes -> bool
2021

2122
type if_condition_kind =
2223
| If of Parsetree.expression

tests/build_tests/super_errors/expected/react_component_with_props.res.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
3 │ let make = React.forwardRef((
88
4 │  ~className=?,
99
. │ ...
10-
12 │  children
10+
12 │  {children}
1111
13 │  </div>
1212
14 │ )
1313
15 │ }

tests/build_tests/super_errors/fixtures/react_component_with_props.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module V4C7 = {
99
<input
1010
type_="text" ?className ref=?{Js.Nullable.toOption(ref)->Belt.Option.map(React.Ref.domRef)}
1111
/>
12-
children
12+
{children}
1313
</div>
1414
)
1515
}

tests/gentype_tests/typescript-react-example/src/Hooks.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module Inner = {
6060

6161
module NoProps = {
6262
@genType @react.component
63-
let make = () => <div> React.null </div>
63+
let make = () => <div> {React.null} </div>
6464
}
6565

6666
type cb = (~_to: vehicle) => unit
@@ -133,7 +133,7 @@ module WithChildren = {
133133
let aComponentWithChildren = (~vehicle, ~children) =>
134134
<div>
135135
{React.string("Another Hook " ++ vehicle.name)}
136-
<div> children </div>
136+
<div> {children} </div>
137137
</div>
138138
}
139139

tests/syntax_tests/data/conversion/reason/expected/jsxProps.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ let handleClick = (href, event) =>
66

77
@react.component
88
let make = (~href, ~className="", ~children) =>
9-
<a href className onClick={event => handleClick(href, event)}> children </a>
9+
<a href className onClick={event => handleClick(href, event)}> {children} </a>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ let x = 1
6161

6262
let x =
6363
<div \"aria-foo"=\"type">
64-
\"module"
65-
\"let"
64+
{\"module"}
65+
{\"let"}
6666
</div>
6767

6868
type dict = {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ let x =
209209

210210
let x =
211211
<div>
212-
ident
212+
{ident}
213213
"constant"
214214
{
215215
let a = 1
@@ -286,7 +286,7 @@ let x =
286286
{@attr ident}
287287
</div>
288288

289-
let x = <MyComponent sidebar={<div> test </div>} nav={<Navbar />} />
289+
let x = <MyComponent sidebar={<div> {test} </div>} nav={<Navbar />} />
290290

291291
<div>
292292
{possibleGradeValues
@@ -492,14 +492,14 @@ let fragmented_moo =
492492

493493
let arrow_with_fragment = el => <>
494494
{t(nbsp ++ "(")}
495-
el
495+
{el}
496496
{t(")")}
497497
</>
498498

499499
let arrow_with_container_tag = el =>
500500
<div>
501501
{t(nbsp ++ "(")}
502-
el
502+
{el}
503503
{t(")")}
504504
</div>
505505

0 commit comments

Comments
 (0)