Skip to content

Commit e6ebbb9

Browse files
Copilottsnobip
authored andcommitted
Wrap variables in curly braces inside JSX children
1 parent 1cd4744 commit e6ebbb9

File tree

11 files changed

+20
-18
lines changed

11 files changed

+20
-18
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: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ let jsx_child_expr expr =
373373
| _ when ParsetreeViewer.expr_is_await expr -> Parenthesized
374374
| {
375375
Parsetree.pexp_desc =
376-
( Pexp_ident _ | Pexp_constant _ | Pexp_field _ | Pexp_construct _
377-
| Pexp_variant _ | Pexp_array _ | Pexp_pack _ | Pexp_record _
378-
| Pexp_extension _ | Pexp_letmodule _ | Pexp_letexception _
379-
| Pexp_open _ | Pexp_sequence _ | Pexp_let _ | Pexp_jsx_element _ );
376+
( Pexp_constant _ | Pexp_field _ | Pexp_construct _ | Pexp_variant _
377+
| Pexp_array _ | Pexp_pack _ | Pexp_record _ | Pexp_extension _
378+
| Pexp_letmodule _ | Pexp_letexception _ | Pexp_open _
379+
| Pexp_sequence _ | Pexp_let _ | Pexp_jsx_element _ );
380380
pexp_attributes = [];
381381
} ->
382382
Nothing

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/comments/expected/jsx.res.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module Cite = {
33
let make = (~author: option<string>, ~children) => {
44
// For semantics, check out
55
// https://css-tricks.com/quoting-in-html-quotations-citations-and-blockquotes/
6-
<div> foo </div>
6+
<div> {foo} </div>
77
}
88
}
99

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ apply({
282282
a
283283
})
284284

285-
let x = {<div> child </div>}
285+
let x = {<div> {child} </div>}
286286

287287
// not valid jsx
288288
let x = {@JSX child}

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)